Day 1- Advance Linux Series Part 1

Jeeva-AWSLabsJourney
3 min readApr 10, 2024

--

Monitor disk usage of directories and sub directories.

du: Stands for "disk usage," it calculates and displays the disk space used by files and directories.

-h: Displays sizes in a human-readable format.

--max-depth=1: Limits the depth of directory recursion to 1 level, showing only immediate child directories.

sort -hr: Sorts the output in reverse numerical order (-r) and displays human-readable sizes (-h).

  • du -h — max-depth=1 /path/to/directory | sort -hr

This command is useful when you want to quickly identify which directories are consuming the most disk space within a specified directory and its immediate subdirectories. It displays the disk usage in a human-readable format and sorts the output in descending order, making it easy to pinpoint the largest directories.

Search for a string in all files within a directory.

grep: Searches for patterns in files.

-r: Recursively searches subdirectories.

"search_string": The string to search for.

/path/to/directory: The directory in which to start the search.

  • grep -r “search_string” /path/to/directory
  • This command is helpful when you need to find occurrences of a specific string within files located in a particular directory and its subdirectories. It recursively searches through files, displaying the lines containing the specified string along with the filenames where they’re found.

Count the number of files in a directory (excluding directories)

find: Searches for files and directories within a directory hierarchy.

-maxdepth 1: Restricts the search to the specified directory without descending into subdirectories.

-type f: Specifies that only regular files should be included in the search.

wc -l: Counts the number of lines in the output, which corresponds to the number of files.

  • find /path/to/directory -maxdepth 1 -type f | wc -l
  • This command is handy for quickly determining the total number of files (excluding directories) within a specified directory. It’s useful for tasks like assessing the number of files in a folder without including subdirectories or generating file counts for scripting purposes.

Monitor system resource usage in real-time.

top: Displays system summary information and a list of processes currently being managed by the kernel.

Useful interactive commands in top: q to quit, h for help, k to kill a process, 1 to toggle between single and multi-core CPU view

  • top
  • Running top provides a dynamic overview of system resource usage, including CPU, memory, and processes. It's helpful for monitoring system performance, identifying resource-intensive processes, and diagnosing performance issues in real-time.

List all open network connections

netstat: Displays network connections, routing tables, interface statistics, masquerade connections, and multicast memberships.

-tulnp: Shows TCP (-t) and UDP (-u) connections, listening (-l) sockets, and the process (-p) using each socket

  • netstat -tulnp

This command lists all active network connections along with the programs or processes associated with them. It’s useful for diagnosing network-related issues, identifying listening ports, and monitoring network activity on a system.

Create a ZIP archive of a directory.

zip: A compression and file packaging utility.

-r: Recursively includes directories and their contents.

archive_name.zip: The name of the ZIP archive to create.

/path/to/directory: The directory to be compressed.

  • zip -r archive_name.zip /path/to/directory

This command compresses the specified directory and its contents into a ZIP archive. It’s helpful for creating backups, transferring directories, or archiving files for storage while preserving directory structures and permissions.

Failure is simply the opportunity to begin again, this time more intelligently.” — Henry Ford.

Don’t let fear hold you back! Embrace the journey and learn from every experience.

--

--

Jeeva-AWSLabsJourney
Jeeva-AWSLabsJourney

Written by Jeeva-AWSLabsJourney

Exploring AWS, cloud, Linux & DevOps. Your guide to navigating the digital realm. Join me on the journey of discovery

No responses yet