The Ultimate Linux Command Line Cheat Sheet: 31 Must-Know Commands for Power Users _ With Examples

Linux is a powerful and versatile operating system, and the command line interface (CLI) is an essential tool for interacting with it. Here, we’ll go over 30 useful Linux commands that can serve as a handy cheat sheet for both new and experienced users.

  1. ls – Lists the files and directories in the current directory. Example: ls will list all the files and directories in the current directory.
  2. cd – Changes the current directory. Example: cd Documents will change the current directory to the Documents directory.
  3. mkdir – Creates a new directory. Example: mkdir new_directory will create a new directory called “new_directory”.
  4. rmdir – Removes an empty directory. Example: rmdir old_directory will remove the empty directory called “old_directory”.
  5. touch – Creates a new empty file. Example: touch new_file.txt will create a new empty file called “new_file.txt”.
  6. cp – Copies a file or directory. Example: cp file.txt backup/ will copy “file.txt” to the “backup” directory.
  7. mv – Moves or renames a file or directory. Example: mv file.txt Documents/ will move “file.txt” to the “Documents” directory.
  8. rm – Removes a file. Example: rm old_file.txt will remove the file called “old_file.txt”.
  9. cat – Displays the contents of a file. Example: cat file.txt will display the contents of “file.txt” on the screen.
  10. less – Displays the contents of a file in a paginated format. Example: less file.txt will display the contents of “file.txt” one page at a time.
  11. grep – Searches for a specific pattern in a file or multiple files. Example: grep "example" file.txt will search for the string “example” in “file.txt”.
  12. find – Searches for files and directories in a directory hierarchy. Example: find / -name "example" will search for files and directories named “example” starting at the root directory.
  13. wc – Displays the number of lines, words, and characters in a file. Example: wc file.txt will display the number of lines, words, and characters in “file.txt”.
  14. sort – Sorts the contents of a file. Example: sort file.txt will sort the contents of “file.txt” alphabetically.
  15. uniq – Removes duplicate lines from a sorted file. Example: sort file.txt | uniq will sort and remove duplicates from “file.txt”.
  16. cut – Removes sections from each line of a file. Example: cut -f 1 file.txt will remove the second field from each line of “file.txt”.
  17. paste – Merges lines of files. Example: paste file1.txt file2.txt will merge the contents of “file1.txt” and “file2.txt” into a single file.
  18. awk – Text processing tool for printing columns and rows from a file. Example: awk '{print $1}' file.txt will print the first column of “file.txt”.
  19. tar – Archiving tool for creating, extracting, and manipulating tar files. Example: tar -cvf archive.tar file1 file2 will create an archive called “archive.tar” with “file1” and “file2”.
  20. gzip – Compression tool for creating and extracting gzip files. Example: gzip file.txt will create a compressed file called “file.txt.gz”.
  21. gunzip – Decompression tool for extracting gzip files. Example: gunzip file.txt.gz will extract “file.txt.gz” and create a file called “file.txt”.
  22. chmod – Changes the permissions of a file or directory. Example: chmod 755 file.txt will give read, write, and execute permissions to the owner, and read and execute permissions to everyone else for “file.txt”.
  23. chown – Changes the owner and group of a file or directory. Example: chown user:group file.txt will change the owner and group of “file.txt” to “user” and “group” respectively.
  24. df – Displays the amount of free space on the file system.
  25. Example: df -h will show the available disk space in a human-readable format
  26. du – Displays the disk usage of a directory or file. Example: du -sh /home will show the disk usage of /home directory in human-readable format
  27. free – Displays the amount of free and used memory in the system. Example: free -h will show the memory usage in a human-readable format
  28. sed – Stream editor for filtering and transforming text. Example: sed 's/old_word/new_word/g' file.txt will replace all occurrences of “old_word” with “new_word” in “file.txt”.
  29. top – Displays real-time information about the system’s processes. Example: top will show the list of running processes and their resource usage in real-time
  30. ps – Displays information about the currently running processes. Example: ps aux will show a list of all running processes and their details
  31. kill – Sends a signal to a process to terminate it. Example: kill -9 1234 will force-terminate the process with ID 1234

These are just a few examples of the many powerful commands that Linux has to offer. By mastering these commands and understanding how to use them effectively, you can greatly increase your productivity and efficiency when working with the Linux operating system.

Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Inline Feedbacks
View all comments