Important Command Line Commands

Here’s a list of important command line commands with examples:

  1. cd (Change Directory):
    • Command: cd [directory_path]
    • Example: cd Documents will move you to the “Documents” folder.
  2. ls (List):
    • Command: ls [options] [directory_path]
    • Example: ls -l will list the files and folders in the current directory in a detailed format with permissions of files. Read more about checking and changing file permissions.
  3. pwd (Print Working Directory):
    • Command: pwd
    • Example: pwd will display the current directory path.
  4. mkdir (Make Directory):
    • Command: mkdir [directory_name]
    • Example: mkdir NewFolder will create a new directory called “NewFolder”.
  5. rmdir (Remove Directory):
    • Command: rmdir [directory_name]
    • Example: rmdir EmptyFolder will delete the empty directory “EmptyFolder”.
  6. cp (Copy):
    • Command: cp [options] [source_file] [destination_file]
    • Example: cp file.txt destination will copy “file.txt” to the “destination” directory.
  7. mv (Move):
  8. rm (Remove):
    • Command: rm [options] [file_name]
    • Example: rm file.txt will delete the file “file.txt”.
  9. touch (Create Empty File):
    • Command: touch [file_name]
    • Example: touch newfile.txt will create a new empty file called “newfile.txt”.
  10. cat (Concatenate):
    • Command: cat [file_name]
    • Example: cat file.txt will display the contents of “file.txt”.
  11. more (Page through a File):
    • Command: more [file_name]
    • Example: more file.txt will display the contents of “file.txt” one page at a time.
  12. less (Opposite of more):
    • Command: less [file_name]
    • Example: less file.txt will display the contents of “file.txt” and allow backward navigation.
  13. head (Output First Part):
    • Command: head [options] [file_name]
    • Example: head file.txt will display the first few lines of “file.txt”.
  14. tail (Output Last Part):
    • Command: tail [options] [file_name]
    • Example: tail file.txt will display the last few lines of “file.txt”.
  15. find (Search):
    • Command: find [path] [expression]
    • Example: find /path/to/search -name "*.txt" will search for all files with the “.txt” extension in the specified directory.
  16. grep (Global Regular Expression Print):
    • Command: grep [options] "pattern" [file_name]
    • Example: grep "search term" file.txt will search for “search term” in “file.txt”.
  17. ln (Link):
    • Command: ln [options] [target_file] [link_name]
    • Example: ln -s /path/to/file linkname will create a symbolic link named “linkname” to the specified file.
  18. chmod (Change Mode):
    • Command: chmod [permissions] [file_name]
    • Example: chmod 755 script.sh will give read, write, and execute permissions to the owner, and read and execute permissions to others for “script.sh”. Read more about checking and changing file permissions
  19. chown (Change Owner):
    • Command: chown [user]:[group] [file_name]
    • Example: chown user:group file.txt will change the owner and group of “file.txt” to the specified user and group.
  20. tar (Tape Archive):
    • Command: tar [options] [archive_file] [file1] [file2] ...
    • Example: tar -cvf archive.tar file1.txt file2.txt will create a new tar archive file containing “file1.txt” and “file2.txt”. Read more about compressing and decompressing folder
  21. zip (Compress):
    • Command: zip [options] [archive_file] [file1] [file2] ...
    • Example: zip archive.zip file1.txt file2.txt will create a new zip archive containing “file1.txt” and “file2.txt”.
  22. unzip (Uncompress):
    • Command: unzip [options] [archive_file]
    • Example: unzip archive.zip will extract the files from the “archive.zip” file.
  23. ssh (Secure Shell):
    • Command: ssh [username]@[hostname]
    • Example: ssh username@hostname will establish an SSH connection to the specified host using the provided username.
  24. scp (Secure Copy):
    • Command: scp [options] [source_file] [username]@[hostname]:[destination_path]
    • Example: scp file.txt username@hostname:/remote/path will securely copy “file.txt” to the specified remote server and path.
  25. ping (Packet Internet Groper):
    • Command: ping [IP_address_or_domain]
    • Example: ping google.com will send ICMP packets to “google.com” to test network connectivity.
  26. ifconfig (Interface Configuration):
    • Command: ifconfig [interface_name]
    • Example: ifconfig eth0 will display the configuration details of the “eth0” network interface.
  27. wget (Web Get):
    • Command: wget [URL]
    • Example: wget https://example.com/file.txt will download “file.txt” from the specified URL.

Examples provided are for illustration purposes and may vary based on your specific system and file paths.

To get a detailed explanation of each command, you can utilize the manual pages available in most Unix-like systems. The manual pages provide comprehensive documentation and explanations for various commands. You can access the manual pages by using the man command followed by the command name you want to learn about.

For example, to get a detailed explanation of the ls command, you can run:

man ls

This will display the manual page for the ls command, including a description, available options, and usage examples. You can navigate through the manual page using the arrow keys or the Page Up and Page Down keys. To exit the manual page, you can press the q key.

Similarly, you can use the man command with other commands to access their respective manual pages and learn more about their functionality and usage.

Keep in mind that the manual pages may vary slightly between different operating systems or distributions, but they generally provide a wealth of information on how to use the commands effectively.

When writing commands in a command-line interface, you can use specific keyboard shortcuts to move to the start or end of a command. The shortcuts may vary depending on the terminal or shell you are using, but here are some commonly used shortcuts:

  1. Move to the Start of the Line:
  • Shortcut: Ctrl + A
  1. Move to the End of the Line:
  • Shortcut: Ctrl + E

These shortcuts allow you to quickly navigate to the beginning or end of a command line, making it easier to edit or add content.

Additionally, you can also use the left and right arrow keys to move character by character within a command line. Pressing the left arrow key will move the cursor to the left, while pressing the right arrow key will move it to the right.

These shortcuts and arrow keys can help you navigate and edit commands efficiently within a command-line interface.

Here are some important tricks and tips for working effectively in a command-line interface:

  1. Use Tab Completion: Typing the first few characters of a file or directory name and then pressing the Tab key will automatically complete the rest of the name if there is a unique match. If there are multiple matches, pressing Tab twice will display a list of possible options.
  2. Command History: You can use the up and down arrow keys to navigate through previously executed commands. This allows you to easily repeat or modify commands without retyping them.
  3. Use Command Options and Flags: Most commands have various options and flags that can modify their behavior. You can typically find a list of available options and their descriptions in the command’s manual page (accessible via man [command]).
  4. Redirection: You can redirect the output of a command to a file using the > symbol. For example, ls > file.txt will redirect the output of the ls command to the file “file.txt”. You can also append output to an existing file using >>.
  5. Pipes: The pipe symbol | allows you to take the output of one command and use it as input for another command. For example, ls | grep "keyword" will list only the files that match the specified keyword.
  6. Use Ctrl + C to Terminate: If a command is taking too long to execute or you want to stop it, you can press Ctrl + C to send an interrupt signal and terminate the command.
  7. Use Ctrl + D to Exit: Pressing Ctrl + D at an empty command prompt or on a new line will signal the end of input or the end of a file, respectively, and exit the current shell.
  8. Command Substitution: You can use the output of one command as an argument for another command by enclosing it in $() or backticks. For example, echo $(ls) will display the output of the ls command.
  9. Use Ctrl + R for Reverse Search: Pressing Ctrl + R allows you to search through your command history based on keywords. It is a useful shortcut for finding and reusing previously executed commands. Read more about reverse search in command line
  10. Use Ctrl + L to Clear the Screen: Pressing Ctrl + L will clear the terminal screen, providing a clean workspace.
  11. Use Ctrl + Z to Suspend a Process: Pressing Ctrl + Z will suspend the currently running foreground process. You can later resume it in the background using the bg command.

These tricks and tips can help improve your productivity and efficiency when working in a command-line interface. Experiment with them and explore further to discover additional features and shortcuts specific to your shell and system.

Don't Miss Out! Subscribe to Read Our Latest Blogs.

If you found this blog helpful, share it on social media.

Subscription form (#5)

Leave a Comment

Pin It on Pinterest

Scroll to Top