Linux Command Cheat Sheet




  1. cd (Change Directory):
      • Description: Changes the current working directory.
      • Use Cases:
        1. cd Documents: Move to the "Documents" directory.
        2. cd ..: Move up one level in the directory structure.
        3. cd /: Change to the root directory.
        4. cd ~/Downloads: Quickly navigate to the user's Downloads folder.
        5. cd -: Toggle between the current and previous directories.
        6. cd -L: Follow symbolic links.

    1. ls (List):

      • Description: Lists the contents of the current directory.
      • Use Cases:
        1. ls -a: List all files, including hidden ones.
        2. ls -l: Display detailed information about files.
        3. ls *.txt: List all files with a .txt extension.
        4. ls -R: Recursively list subdirectories and their contents.
        5. ls -lh: List files with human-readable file sizes.
        6. ls -t: Sort files by modification time.

    2. pwd (Print Working Directory):

      • Description: Prints the current working directory.
      • Use Cases:
        1. pwd: Display the full path of the current directory.
        2. echo $(pwd): Use in scripts to get and print the current directory.
        3. cd "$(pwd)": Change to the current directory.
        4. pwd -P: Print the physical path (resolved symlink path).
        5. pwd -L: Print the logical path (unresolved symlink path).
        6. pwd -W: Print the Windows path style.

    3. mkdir (Make Directory):

      • Description: Creates a new directory.
      • Use Cases:
        1. mkdir new_folder: Create a directory named "new_folder."
        2. mkdir -p path/to/new/directory: Create nested directories.
        3. mkdir {dir1,dir2,dir3}: Create multiple directories at once.
        4. mkdir -m 755 new_directory: Create a directory with specific permissions.
        5. mkdir -v new_directory: Display a message for each created directory.
        6. mkdir --help: Show help information for the command.

    4. rmdir (Remove Directory):

      • Description: Removes an empty directory.
      • Use Cases:
        1. rmdir empty_folder: Remove an empty directory named "empty_folder."
        2. rmdir -p path/to/empty/directory: Remove nested empty directories.
        3. rmdir --ignore-fail-on-non-empty non_empty_folder: Remove a non-empty directory.

    5. rm (Remove):

      • Description: Removes files or directories.
      • Use Cases:
        1. rm file.txt: Delete a file named "file.txt."
        2. rm -r folder: Remove a directory and its contents.
        3. rm *.log: Delete all files with a .log extension.
        4. rm -f file.txt: Forcefully remove a file without confirmation.
        5. rm -i *.txt: Interactively remove files with confirmation.
        6. rm -v file1 file2: Display a message for each removed file.

    6. cp (Copy):

      • Description: Copies files or directories.
      • Use Cases:
        1. cp file.txt /path/to/destination: Copy a file to a specified directory.
        2. cp -r source_folder destination_folder: Copy a directory and its contents.
        3. cp *.jpg backup_folder: Copy all JPEG files to a backup directory.
        4. cp -u *.txt /backup: Copy files only if the source is newer than the destination.
        5. cp -i file.txt /path/to/destination: Interactively copy files with confirmation.
        6. cp --preserve=mode,timestamps source.txt destination.txt: Copy while preserving specified attributes.

    7. mv (Move):

      • Description: Moves or renames files or directories.
      • Use Cases:
        1. mv old_file.txt new_file.txt: Rename a file.
        2. mv file.txt /new/location/: Move a file to a different directory.
        3. mv folder1 folder2: Rename a directory.
        4. mv -u *.txt /backup: Move files only if the source is newer than the destination.
        5. mv -i file.txt /path/to/destination: Interactively move files with confirmation.
        6. mv --backup=numbered file.txt /path/to/backup: Move and create numbered backups.

    8. touch:

      • Description: Creates an empty file.
      • Use Cases:
        1. touch new_file.txt: Create an empty file named "new_file.txt."
        2. touch file1.txt file2.txt: Create multiple empty files.
        3. touch $(date +"%Y%m%d").log: Create a log file with a timestamp.
        4. touch -t 202201011200 file.txt: Create a file with a specific timestamp.
        5. touch -c existing_file.txt: Update the access and modification times of an existing file.
        6. touch --reference=template_file.txt new_file.txt: Set the timestamps of a new file to match an existing file.

    9. cat:

      • Description: Concatenates and displays the content of files.
      • Use Cases:
        1. cat file.txt: Display the content of "file.txt."
        2. cat file1.txt file2.txt > combined.txt: Concatenate two files into one.
        3. cat *.log > all_logs.txt: Combine multiple log files into one.
        4. cat -n file.txt: Display line numbers with the content.
        5. zcat compressed_file.gz: Display the content of a compressed file.
        6. cat file.txt | grep "pattern": Display lines matching a specific pattern.

    10. grep:

      • Description: Searches for a pattern in files.
      • Use Cases:
        1. grep "keyword" file.txt: Display lines containing the specified keyword.
        2. grep -r "pattern" /path/to/search: Recursively search for a pattern in files.
        3. ps aux | grep "process_name": Find a specific process in the process list.
        4. grep -i "case-insensitive" file.txt: Perform a case-insensitive search.
        5. grep -w "word" file.txt: Match whole words only.
        6. grep -v "exclude_pattern" file.txt: Invert match to exclude lines containing a pattern.
  1. find (Continued):
  • Description: Searches for files and directories in a directory hierarchy.
  • Use Cases:
    1. find /path/to/search -name "*.txt": Find all text files in a directory.
    2. find / -size +100M: Find files larger than 100 megabytes.
    3. find . -type f -exec chmod 644 {} \;: Change permissions of all files in the current directory.
    4. find /path -mtime -7: Find files modified in the last 7 days.
    5. find / -name "*.log" -exec rm {} \;: Delete all log files on the system.
    6. find /path -type d -empty -delete: Delete all empty directories in a specific path.
  1. chmod:

    • Description: Changes file permissions.
    • Use Cases:
      1. chmod +x script.sh: Add execute permission to a script.
      2. chmod 644 file.txt: Set read and write permissions for the owner, read-only for others.
      3. chmod -R 755 /path/to/directory: Recursively set permissions for a directory and its contents.
      4. chmod g+s directory: Set the setgid bit, making files created in the directory inherit its group.
      5. chmod a-x file.txt: Remove execute permission for all users.
      6. chmod u=rw,g=r,o=r file.txt: Set specific permissions using symbolic notation.

  2. chown:

    • Description: Changes file owner and group.
    • Use Cases:
      1. chown user:group file.txt: Change the owner and group of a file.
      2. chown -R user:group /path/to/directory: Recursively change ownership of a directory and its contents.
      3. chown :group file.txt: Change only the group of a file.
      4. chown user: /path/to/directory: Change the owner of a directory, leaving the group unchanged.
      5. chown -c user:group file.txt: Display a message for each changed ownership.
      6. chown --reference=template_file.txt new_file.txt: Set ownership based on an existing file.

  3. ps (Process Status):

    • Description: Displays information about processes.
    • Use Cases:
      1. ps aux: Display a detailed list of all processes.
      2. ps -e | grep "process_name": Find a specific process by name.
      3. ps -ef | grep "username": List processes associated with a specific user.
      4. ps -e | grep -v "grep" | grep "process_name": Exclude the grep process from the result.
      5. ps -e --sort=-cpu: Display processes sorted by CPU usage (descending).
      6. ps -p PID -o pid,ppid,cmd,%cpu,%mem: Show specific information for a process with a given PID.

  4. kill:

    • Description: Sends a signal to terminate processes.
    • Use Cases:
      1. kill PID: Terminate a process by its process ID.
      2. kill -9 PID: Forcefully terminate a process.
      3. pkill -f "process_name": Kill processes by name.
      4. killall process_name: Kill all processes with a specific name.
      5. kill -STOP PID: Suspend a process.
      6. kill -CONT PID: Resume a suspended process.

  5. echo:

    • Description: Prints text to the terminal.
    • Use Cases:
      1. echo "Hello, World!": Display the text "Hello, World!".
      2. echo $PATH: Print the value of the PATH environment variable.
      3. echo -e "Line1\nLine2": Print multiple lines with the -e option.
      4. echo $((2+2)): Perform arithmetic and print the result.
      5. echo "Error: Something went wrong" >&2: Print an error message to standard error.
      6. echo "Today is $(date)": Embed command output within an echo statement.

  6. man (Manual):

    • Description: Displays the manual page for a command.
    • Use Cases:
      1. man ls: View the manual page for the "ls" command.
      2. man -k keyword: Search for manual pages containing a specific keyword.
      3. man 5 passwd: Display information about the passwd file format.
      4. man -t find | ps2pdf - > find.pdf: Convert a manual page to PDF.
      5. man -Hfirefox command: Open the manual page in a web browser.
      6. man -l file.5: View a specific section of a manual page.
  1. head:
  • Description: Displays the first few lines of a file.
  • Use Cases:
    1. head file.txt: Display the first 10 lines of "file.txt."
    2. head -n 20 file.txt: Display the first 20 lines.
    3. ls | head -3: Display the first 3 items in the current directory.
    4. head -c 100 file.txt: Display the first 100 bytes of a file.
    5. head -q file1.txt file2.txt: Quiet mode, don't display headers when multiple files are specified.
    6. journalctl | head -n 50: Display the first 50 lines of system journal entries.
  1. tail:
  • Description: Displays the last few lines of a file.
  • Use Cases:
    1. tail file.txt: Display the last 10 lines of "file.txt."
    2. tail -n 20 file.txt: Display the last 20 lines.
    3. tail -f /var/log/syslog: Follow the content of a log file in real-time.
    4. tail -c +101 file.txt: Display all characters from the 101st character onwards.
    5. journalctl | tail -n 50: Display the last 50 lines of system journal entries.
    6. ls -lt | tail -n +6: Display a directory listing, excluding the first 5 lines.
  1. nano:
  • Description: A simple command-line text editor.
  • Use Cases:
    1. nano file.txt: Open or create a file for editing.
    2. nano +10 file.txt: Open a file and position the cursor at line 10.
    3. nano -B file.txt: Create a backup of the file before saving changes.
    4. nano -c file.txt: Show line numbers and column numbers.
    5. nano -x: Start nano in no-wrapping mode.
    6. nano --help: Display help information for nano.
  1. vim:
  • Description: A powerful text editor with modes and extensive features.
  • Use Cases:
    1. vim file.txt: Open or create a file for editing.
    2. vim +10 file.txt: Open a file and position the cursor at line 10.
    3. vim -O file1.txt file2.txt: Open multiple files in split windows.
    4. vim -u NONE -N: Start Vim with no plugins and no compatible mode.
    5. vim -c "set number" file.txt: Execute a command on startup (set line numbering).
    6. vimdiff file1.txt file2.txt: Compare two files using Vim's side-by-side mode.
  1. du (Disk Usage):
  • Description: Displays the disk space used by files and directories.
  • Use Cases:
    1. du -h /path: Show disk usage in human-readable format.
    2. du -sh *: Display the total disk usage of each item in the current directory.
    3. du -c -h /path/*: Display the total disk usage of all items in a directory.
    4. du -d 2 /path: Display disk usage up to a specified depth.
    5. find / -type f -exec du -h {} + | sort -rh | head -n 10: Find and display the largest files on the system.
    6. du -h --max-depth=1 /path: Display disk usage of each immediate subdirectory.
  1. df (Disk Free):
  • Description: Displays information about available disk space.
  • Use Cases:
    1. df -h: Show disk space usage in a human-readable format.
    2. df -T: Display filesystem types along with disk space information.
    3. df -i: Show inode usage on filesystems.
    4. df -h /path: Display disk space information for a specific directory or filesystem.
    5. df --total: Display total disk space usage across all filesystems.
    6. df -P /path: Use the POSIX output format for consistent column widths.
  1. tar:
  • Description: Creates or extracts tar archives.
  • Use Cases:
    1. tar -cvf archive.tar file1 file2: Create a tar archive of specified files.
    2. tar -xvf archive.tar: Extract files from a tar archive.
    3. tar -czvf archive.tar.gz directory/: Create a compressed tar archive.
    4. tar -tvf archive.tar: List the contents of a tar archive.
    5. tar -rvf archive.tar new_file: Add a new file to an existing tar archive.
    6. tar --exclude=*.log -cvf archive.tar *: Create an archive excluding all .log files.
  1. gzip:
  • Description: Compresses or decompresses files using gzip compression.
  • Use Cases:
    1. gzip file.txt: Compress a file and add the ".gz" extension.
    2. gzip -d file.txt.gz: Decompress a gzip-compressed file.
    3. gzip -c file.txt > file.txt.gz: Compress a file and retain the original.
    4. gunzip -k file.txt.gz: Decompress a file and keep the original compressed file.
    5. gzip -r directory: Compress all files in a directory recursively.
    6. zcat file.txt.gz: Display the content of a compressed file without decompressing.
  1. gunzip:
  • Description: Decompresses files compressed with gzip.
  • Use Cases:
    1. gunzip file.txt.gz: Decompress a gzip-compressed file.
    2. gunzip -k file.txt.gz: Decompress a file and keep the original compressed file.
    3. gunzip -c file.txt.gz > file.txt: Decompress a file and retain the original.
    4. gunzip -r directory: Decompress all files in a directory recursively.
    5. gunzip -l file.txt.gz: Display information about the compressed file.
    6. gunzip --help: Display help information for gunzip.
  1. zip:
  • Description: Compresses files into a zip archive.
  • Use Cases:
    1. zip archive.zip file1 file2: Create a zip archive of specified files.
    2. unzip archive.zip: Extract files from a zip archive.
    3. zip -r archive.zip directory/: Create a zip archive of an entire directory.
    4. zip -u archive.zip new_file.txt: Update a zip archive with a new file.
    5. zip -d archive.zip file.txt: Delete
    6. zip -e secure.zip file.txt: Create a password-protected zip archive.

  1. unzip:
  • Description: Extracts files from a zip archive.
  • Use Cases:
    1. unzip archive.zip: Extract files from a zip archive.
    2. unzip -l archive.zip: List the contents of a zip archive.
    3. unzip -d /path/to/extract archive.zip: Extract files to a specified directory.
    4. unzip -u archive.zip: Update an existing zip archive with new files.
    5. unzip -p archive.zip file.txt > output.txt: Extract and redirect the content of a specific file.
    6. unzip -e password_protected.zip: Extract from a password-protected zip archive.
  1. curl:
  • Description: Transfers data to or from a server.
  • Use Cases:
    1. curl http://example.com: Retrieve content from a URL and display it.
    2. curl -O http://example.com/file.txt: Download a file from a URL.
    3. curl -X POST -d "data" http://api.com: Send a POST request with data.
    4. curl -I http://example.com: Show only the HTTP headers.
    5. curl -u username:password http://secure-site.com: Authenticate with a username and password.
    6. curl -L http://shorturl.com: Follow redirects to the final destination.
  1. wget:
  • Description: Downloads files from the web using HTTP, HTTPS, or FTP.
  • Use Cases:
    1. wget http://example.com/file.txt: Download a file from a URL.
    2. wget -c http://example.com/largefile.zip: Resume a partially downloaded file.
    3. wget -r -np http://example.com/folder/: Recursively download files from a website.
    4. wget --limit-rate=500k http://example.com/file.iso: Limit download speed to 500 KB/s.
    5. wget --ftp-user=user --ftp-password=pass ftp://example.com/file.txt: Download from an FTP server with authentication.
    6. wget --spider -r http://example.com: Check if web pages are accessible without downloading.
  1. ssh:
  • Description: Connects to a remote server securely.
  • Use Cases:
    1. ssh username@hostname: Connect to a remote server with a specified username.
    2. ssh -p 2222 username@hostname: Connect to a server on a non-default SSH port.
    3. ssh-keygen -t rsa: Generate an SSH key pair for authentication.
    4. ssh-copy-id username@hostname: Copy SSH keys to a remote server for passwordless login.
    5. ssh -L 8080:localhost:80 username@hostname: Create an SSH tunnel for local port forwarding.
    6. scp file.txt username@hostname:/path/to/destination: Securely copy a file to a remote server.
  1. scp:
  • Description: Securely copies files between local and remote hosts.
  • Use Cases:
    1. scp file.txt username@hostname:/path/to/destination: Copy a file to a remote server.
    2. scp -r directory username@hostname:/remote/directory/: Copy a directory and its contents.
    3. scp username@remote:/path/to/file.txt .: Copy a file from a remote server to the local directory.
    4. scp -P 2222 file.txt username@hostname:/path/to/destination: Specify a non-default SSH port.
    5. scp -i keyfile.pem file.txt username@hostname:/path/to/destination: Use a specific private key for authentication.
    6. rsync -avz --progress /local/path/ username@remote:/remote/path/: Synchronize files between local and remote hosts with rsync.
  1. rsync:
  • Description: Synchronizes files and directories between local and remote systems.
  • Use Cases:
    1. rsync -avz /local/path/ username@remote:/remote/path/: Copy files from local to remote using compression.
    2. rsync -avz --delete /local/path/ username@remote:/remote/path/: Synchronize and delete extraneous files on the destination.
    3. rsync -avz --exclude='*.log' /local/path/ username@remote:/remote/path/: Exclude specific file types during synchronization.
    4. rsync -avz --dry-run /local/path/ username@remote:/remote/path/: Perform a dry run without making changes.
    5. rsync -avz --bwlimit=1000 /local/path/ username@remote:/remote/path/: Limit the bandwidth during synchronization.
    6. rsync -avz -e 'ssh -p 2222' /local/path/ username@hostname:/remote/path/: Specify a non-default SSH port.
  1. history:
  • Description: Displays the command history.
  • Use Cases:
    1. history: Display the command history.
    2. !ls: Execute the last command that started with "ls."
    3. history | grep "keyword": Search the command history for a specific keyword.
    4. !!: Repeat the last command.
    5. !n: Repeat the nth command from the history.
    6. history -c: Clear the entire command history.
  1. clear:
  • Description: Clears the terminal screen.
  • Use Cases:
    1. clear: Clear the terminal screen.
    2. clear && command: Clear the screen before executing a command.
    3. Ctrl + L: Shortcut to clear the terminal screen.
    4. clear -x: Clear the screen and scrollback buffer.
    5. watch -n 1 'command | clear': Continuously run a command and clear the screen every second.
    6. tput reset: Use the terminfo capability to clear the screen.
  1. date:
  • Description: Displays or sets the system date and time.
  • Use Cases:
    1. date: Display the current date and time.
    2. date +"%Y-%m-%d %H:%M:%S": Format and display the date and time.
    3. date -s "2022-01-01 12:00:00": Set the system date and time.
    4. date --date="2 days ago": Display the date from two days ago.
    5. date -u: Display the date in Coordinated Universal Time (UTC).
    6. date +%s: Display the current timestamp (seconds since 1970-01-01 00:00:00 UTC).
  1. cal:
  • Description: Displays a calendar.
  • Use Cases:
    1. cal: Display the current month's calendar.
    2. cal -3: Display the previous, current, and next month's calendars.
    3. cal 2022: Display the calendar for the entire year 2022.
    4. cal -j: Display Julian dates in the calendar.
    5. cal -y: Display a calendar with a week starting from Sunday.
    6. cal -A 1 -B 1: Display one month ahead and one month behind the current month.
  1. uptime:
  • Description: Displays how long the system has been running.
  • Use Cases:
    1. uptime: Display the current time, how long the system has been running, and the number of users.
    2. uptime -p: Display the uptime in a more human-readable format.
    3. w: Similar to uptime but also shows who is logged in and what they are doing.
    4. top: Display real-time system statistics, including uptime.
    5. ps -eo etime,cmd | grep -i "process_name": Check the uptime of a specific process.
    6. watch -n 1 uptime: Continuously monitor system uptime.
  1. whoami:
  • Description: Displays the username of the current user.
  • Use Cases:
    1. whoami: Display the current username.
    2. echo "I am $(whoami)": Use in scripts to incorporate the username.
    3. sudo -u $(whoami) command: Execute a command with elevated privileges as the current user.
    4. id -un: Display the username using the id command.
    5. finger $(whoami): Display additional information about the user.
    6. who: Display information about currently logged-in users.
  1. uname:
  • Description: Displays system information.
  • Use Cases:
    1. uname: Display the system name (kernel name).
    2. uname -a: Display all system information.
    3. uname -s: Display the kernel name.
    4. uname -r: Display the kernel release.
    5. uname -m: Display the machine hardware name.
    6. uname -n: Display the network node hostname.
  1. df (Data Format):
  • Description: Converts and formats data.
  • Use Cases:
    1. echo "123" | df: Display the size and usage of standard input.
    2. df -hT: Display a summarized and human-readable format of filesystem information.
    3. df -B MB: Display block sizes in megabytes.
    4. df --output=source,size,used,avail: Specify the columns to be displayed.
    5. df -H /path: Display disk usage with human-readable units.
    6. df --sync: Synchronize output to avoid displaying outdated information.
  1. ps (PostScript):
  • Description: Generates PostScript files.
  • Use Cases:
    1. ps2pdf file.ps: Convert a PostScript file to PDF.
    2. ps2pdf -dPDFSETTINGS=/prepress file.ps: Optimize PDF output for prepress printing.
    3. ps2pdf -sOutputFile=output.pdf input.ps: Specify the output file name.
    4. ps2pdf -dNOPAUSE -dBATCH -sDEVICE=jpeg -r300 -sOutputFile=output.jpg input.ps: Convert to JPEG format.
    5. ps2pdf -dEmbedAllFonts=true -dSubsetFonts=true input.ps: Embed and subset fonts in the PDF.
    6. ps2pdf -dFirstPage=2 -dLastPage=5 input.ps output.pdf: Convert specific pages to PDF.
  1. echo:
  • Description: Prints text to the terminal.
  • Use Cases:
    1. echo "Hello, World!": Display the text "Hello, World!".
    2. echo $PATH: Print the value of the PATH environment variable.
    3. echo -e "Line1\nLine2": Print multiple lines with the -e option.
    4. echo $((2+2)): Perform arithmetic and print the result.
    5. echo "Error: Something went wrong" >&2: Print an error message to standard error.
    6. echo "Today is $(date)": Embed command output within an echo statement.
  1. printf:
  • Description: Formats and prints data.
  • Use Cases:
    1. printf "Name: %s\nAge: %d\n" "John" 25: Display formatted text.
    2. printf "%-10s %-8s %-4s\n" "Name" "Age" "ID": Format text with specified widths.
    3. printf "%0.2f\n" 3.14159: Format and display a floating-point number.
    4. printf "Hex: %x\n" 255: Display a hexadecimal representation.
    5. printf "Binary: %b\n" 101: Display a binary representation.
    6. printf "Octal: %o\n" 8: Display an octal representation.
  1. grep (Global Regular Expression Print):
  • Description: Searches for a pattern in files.
  • Use Cases:
    1. grep "keyword" file.txt: Display lines containing the specified keyword.
    2. grep -r "pattern" /path/to/search: Recursively search for a pattern in files.
    3. ps aux | grep "process_name": Find a specific process in the process list.
    4. grep -i "case-insensitive" file.txt: Perform a case-insensitive search.
    5. grep -w "word" file.txt: Match whole words only.
    6. grep -v "exclude_pattern" file.txt: Invert match to exclude lines containing a pattern.
  1. awk:
  • Description: A versatile text processing tool.
  • Use Cases:
    1. ls -l | awk '{print $1, $9}': Display file permissions and names.
    2. ps aux | awk '$3 > 50 {print $1, $3}': Print user and CPU usage for processes using more than 50% CPU.
    3. awk '{sum += $1} END {print sum}' numbers.txt: Calculate and print the sum of numbers in a file.
    4. df -h | awk '$5 > 80 {print $6, $5}': Display filesystems with usage above 80%.
    5. awk '/pattern/ {print $0}' file.txt: Print lines containing a specific pattern.
    6. awk -F: '{print $1, $3}' /etc/passwd: Set a custom field separator and print user names and IDs.
  1. sed (Stream Editor):
  • Description: Edits text streams.
  • Use Cases:
    1. sed 's/old/new/' file.txt: Replace the first occurrence of "old" with "new" in each line.
    2. sed '2,5s/old/new/' file.txt: Replace "old" with "new" in lines 2 to 5.
    3. sed 's/old/new/g' file.txt: Replace all occurrences of "old" with "new" in each line.
    4. sed -n '1,5p' file.txt: Print only lines 1 to 5.
    5. sed '/pattern/d' file.txt: Delete lines containing a specific pattern.
    6. sed 's/^/prefix_/' file.txt: Add a prefix to the beginning of each line.
  1. cut:
  • Description: Removes sections from each line of a file.
  • Use Cases:
    1. cut -d',' -f2 file.csv: Extract the second field from a CSV file.
    2. cut -c1-5 file.txt: Extract the first five characters from each line.
    3. ps aux | cut -c1-20,30-: Extract specific columns from the output of ps.
    4. cut -f1,3 -d':' /etc/passwd: Extract user names and user IDs from the passwd file.
    5. cut -f2- file.txt: Extract fields starting from the second field.
    6. echo "apple,orange,banana" | cut -d',' --output-delimiter=' | ' -f2,3: Change the output delimiter.
  1. sort:
  • Description: Sorts lines of text files.
  • Use Cases:
    1. sort file.txt: Sort lines alphabetically.
    2. sort -r file.txt: Sort lines in reverse order.
    3. sort -n numbers.txt: Sort numerical values.
    4. ls -l | sort -k5,5nr: Sort files by size in descending order.
    5. sort -t':' -k3,3n /etc/passwd: Sort the passwd file by user ID.
    6. sort -u file.txt: Sort and remove duplicate lines.
  1. uniq:
  • Description: Removes duplicate lines from a sorted file.
  • Use Cases:
    1. sort file.txt | uniq: Remove consecutive duplicate lines.
    2. sort file.txt | uniq -c: Count and remove consecutive duplicate lines.
    3. sort file.txt | uniq -u: Display only lines that are not repeated.
    4. uniq -i file.txt: Case-insensitive comparison.
    5. uniq -d file.txt: Display only duplicate lines.
    6. uniq -w 3 file.txt: Compare only the first 3 characters.
  1. tr (Translate):
  • Description: Translates or deletes characters.
  • Use Cases:
    1. echo "Hello" | tr 'a-z' 'A-Z': Convert lowercase to uppercase.
    2. echo "Hello 123" | tr -d '0-9': Remove digits.
    3. echo "Hello 123" | tr -c 'a-z' 'X': Replace non-lowercase characters with 'X'.
    4. echo " Hello " | tr -s ' ': Squeeze consecutive spaces into one.
    5. echo "abc" | tr -d -c 'a-z': Delete characters not in the specified range.
    6. echo "HELLO" | tr 'A-Z' 'a-z': Convert uppercase to lowercase.
  1. wc (Word Count):
  • Description: Counts lines, words, and characters in a file.
  • Use Cases:
    1. wc file.txt: Display the line, word, and byte count for a file.
    2. wc -l file.txt: Display only the line count.
    3. wc -w file.txt: Display only the word count.
    4. echo "Hello" | wc -c: Count the number of characters in a string.
    5. cat *.txt | wc -l: Count the total number of lines in multiple files.
    6. find /path -type f -exec cat {} \; | wc -l: Count the total number of lines in all files in a directory.
  1. curl:
  • Description: Transfers data to or from a server.
  • Use Cases:
    1. curl http://example.com: Retrieve content from a URL and display it.
    2. curl -O http://example.com/file.txt: Download a file from a URL.
    3. curl -X POST -d "data" http://api.com: Send a POST request with data.
    4. curl -I http://example.com: Show only the HTTP headers.
    5. curl -u username:password http://secure-site.com: Authenticate with a username and password.
    6. curl -L http://shorturl.com: Follow redirects to the final destination.
  1. wget:
  • Description: Downloads files from the web using HTTP, HTTPS, or FTP.
  • Use Cases:
    1. wget http://example.com/file.txt: Download a file from a URL.
    2. wget -c http://example.com/largefile.zip: Resume a partially downloaded file.
    3. wget -r -np http://example.com/folder/: Recursively download files from a website.
    4. wget --limit-rate=500k http://example.com/file.iso: Limit download speed to 500 KB/s.
    5. wget --ftp-user=user --ftp-password=pass ftp://example.com/file.txt: Download from an FTP server with authentication.
    6. wget --spider -r http://example.com: Check if web pages are accessible without downloading.
  1. ssh:
  2. Description: Connects to a remote server securely.
  • Use Cases:
    1. ssh username@hostname: Connect to a remote server with a specified username.
    2. ssh -p 2222 username@hostname: Connect to a server on a non-default SSH port.
    3. ssh-keygen -t rsa: Generate an SSH key pair for authentication.
    4. ssh-copy-id username@hostname: Copy SSH keys to a remote server for passwordless login.
    5. ssh -L 8080:localhost:80 username@hostname: Create an SSH tunnel for local port forwarding.
    6. scp file.txt username@hostname:/path/to/destination: Securely copy a file to a remote server.

  1. docker:
  • Description: Manages containers for developing, shipping, and running applications.
  • Use Cases:
    1. docker build -t image_name .: Build a Docker image from the current directory.
    2. docker run -p 8080:80 image_name: Run a Docker container, mapping port 8080 to port 80.
    3. docker ps: List running containers.
    4. docker exec -it container_name /bin/bash: Access a running container's shell.
    5. docker-compose up: Start services defined in a Docker Compose file.
    6. docker system prune: Remove all stopped containers, unused networks, and dangling images.
  1. kubectl:
  • Description: Interacts with Kubernetes clusters to deploy and manage applications.
  • Use Cases:
    1. kubectl apply -f deployment.yaml: Deploy a Kubernetes resource defined in a YAML file.
    2. kubectl get pods: List running pods in a Kubernetes cluster.
    3. kubectl logs pod_name: View logs from a specific pod.
    4. kubectl describe deployment deployment_name: Display detailed information about a deployment.
    5. kubectl scale deployment deployment_name --replicas=3: Scale the number of replicas for a deployment.
    6. kubectl delete pod pod_name: Delete a pod in a Kubernetes cluster.
  1. ansible:
  • Description: Automates configuration management, application deployment, and task execution.
  • Use Cases:
    1. ansible-playbook deploy_app.yml: Run an Ansible playbook for deploying an application.
    2. ansible all -m ping: Check connectivity to all hosts in the inventory.
    3. ansible-playbook -i inventory_file deploy_app.yml: Use a custom inventory file for playbook execution.
    4. ansible-vault encrypt secrets.yml: Encrypt sensitive data in an Ansible Vault.
    5. ansible-galaxy init role_name: Initialize a new Ansible role.
    6. ansible-doc command_module: View documentation for an Ansible module.
  1. terraform:
  • Description: Manages infrastructure as code and enables provisioning of resources.
  • Use Cases:
    1. terraform init: Initialize a Terraform working directory.
    2. terraform apply: Apply changes to infrastructure as defined in Terraform configuration.
    3. terraform plan: Generate and show an execution plan for changes.
    4. terraform destroy: Destroy Terraform-managed infrastructure.
    5. terraform state show: Show Terraform state or plan file.
    6. terraform fmt: Format Terraform configuration files.
  1. git:
  • Description: Version control system for tracking changes in source code during software development.
  • Use Cases:
    1. git clone repository_url: Clone a Git repository.
    2. git add file_name: Add changes in a file to the staging area.
    3. git commit -m "Commit message": Commit changes to the local repository.
    4. git push origin branch_name: Push changes to a remote repository.
    5. git pull origin branch_name: Pull changes from a remote repository.
    6. git branch -a: List all branches in the repository.
  1. jenkins:
  • Description: An automation server used for building, testing, and deploying software.
  • Use Cases:
    1. Jenkins Pipeline: Define a continuous integration/continuous deployment (CI/CD) pipeline.
    2. Jenkins Job DSL: Create and manage Jenkins jobs programmatically.
    3. Jenkins CLI: Interact with Jenkins from the command line.
    4. Jenkins Plugin Management: Install and manage plugins for extending Jenkins functionality.
    5. Jenkins Slave Configuration: Set up and configure build agents (slaves) in Jenkins.
    6. Jenkins System Configuration: Adjust global settings and configurations in Jenkins.
  1. curl (for API testing):
  • Description: Command-line tool for making HTTP requests.
  • Use Cases:
    1. curl -X GET http://api_endpoint: Send a GET request to an API.
    2. curl -X POST -H "Content-Type: application/json" -d '{"key":"value"}' http://api_endpoint: Send a POST request with JSON data.
    3. curl -H "Authorization: Bearer token" http://api_endpoint: Include an authorization token in the request header.
    4. curl -I http://api_endpoint: Fetch only the HTTP headers from the response.
    5. curl -u username:password http://api_endpoint: Perform basic authentication.
    6. curl --data-urlencode "param1=value1" --data-urlencode "param2=value2" http://api_endpoint: Send data as URL-encoded form parameters.
  1. vault (HashiCorp Vault):
  • Description: Manages secrets and protects sensitive data for applications.
  • Use Cases:
    1. vault write secret/myapp/apikey value=supersecret: Store a secret in Vault.
    2. vault read secret/myapp/apikey: Retrieve a secret from Vault.
    3. vault kv get secret/myapp: List all key-value pairs in a secret path.
    4. vault policy write mypolicy policy.hcl: Create or update a policy in Vault.
    5. vault token create -policy=mypolicy: Create a new token with a specified policy.
    6. vault audit enable file file_path.log: Enable file-based auditing in Vault.
  1. logrotate:
  • Description: Rotates, compresses, and mails system logs.
  • Use Cases:
    1. logrotate -f /etc/logrotate.conf: Force log rotation using a specific configuration file.
    2. logrotate -d /etc/logrotate.conf: Debug mode to check the log rotation process without making changes.
    3. logrotate --state /var/lib/logrotate/status: Specify an alternate state file for log rotation.
    4. logrotate -s /path/to/state/file: Set the state file for log rotation.
    5. logrotate -v /etc/logrotate.conf: Verbose mode to display detailed information during log rotation.
    6. logrotate --force /etc/logrotate.d/custom: Force log rotation for a specific log file.
  1. htop:
  • Description: Interactive process viewer for monitoring system resources.
  • Use Cases:
    1. htop: Launch the htop process viewer.
    2. htop -u username: Display processes for a specific user.
    3. htop -p PID: Show information for a specific process ID.
    4. htop -s: Sort processes based on a selected column.
    5. htop -t: Tree view, display processes in a hierarchical structure.