Linux is one of the most widely used operating systems for development, servers, and many other technical operations. Knowing basic Linux commands is crucial, whether you’re a beginner or an experienced user. In this post, I’ll introduce you to some of the most commonly used Linux commands along with brief explanations.
1. ls – List Directory Contents
The ls command is used to list files and directories in the current directory.
ls
You can also use flags like -l for a detailed listing or -a to include hidden files:ls -la
2. cd – Change Directorycd is used to navigate through directories. For example, to move into a directory named “Documents”:cd DocumentsTo go back to the previous directory, use:cd ..
3. pwd – Print Working Directory
This command shows the full path of the current directory you’re in:pwd
4. mkdir – Make Directory
Use mkdir to create a new directory:mkdir new_folder
5. rm – Remove Files and Directoriesrm deletes files, and when used with the -r option, it removes directories and their contents:rm filename.txt rm -r directory_name
6. cp – Copy Files and Directories
The cp command copies files from one location to another. To copy a file:cp source_file destination_directory
For copying directories, use the -r option:cp -r source_directory destination_directory
7. mv – Move or Rename Filesmv is used to move files or rename them:mv old_filename new_filename
Or to move a file to another directory:mv filename.txt /path/to/destination/
8. cat – Concatenate and Display Filescat is used to display the contents of a file:cat filename.txt
9. touch – Create a New File
The touch command creates a new empty file:touch newfile.txt
10. chmod – Change File Permissionschmod is used to modify file or directory permissions. For example, to give a file read, write, and execute permissions:chmod 755 filename.sh
11. chown – Change File Owner
This command changes the ownership of files or directories:sudo chown new_owner filename.txt
12. sudo – Execute Commands as Superuser
Many administrative tasks require superuser privileges. Prepend sudo to run commands with elevated privileges:sudo apt update
13. apt – Package Manager for Debian-Based Systems
For installing or updating software on Debian-based systems (e.g., Ubuntu), you use apt:sudo apt install package_name sudo apt update
14. ps – List Processes
The ps command displays information about running processes:ps aux
15. kill – Terminate Processes
To terminate a process, use kill with the process ID (PID):kill 1234
To forcefully terminate a process, use:kill -9 1234
16. grep – Search Within Filesgrep searches for patterns within files:grep "search_term" filename.txt
You can also use it to search within multiple files or outputs:grep -r "search_term" directory/
17. df – Disk Space Usage
To see available disk space, use the df command:df -h
The -h flag shows the sizes in a human-readable format.
18. du – Disk Usage of Files and Directoriesdu shows the disk usage of files and directories:du -h directory_name
19. tar – Archive Files
The tar command is used for creating and extracting archives. To create a .tar.gz file:tar -czvf archive_name.tar.gz directory_name
To extract a .tar.gz file:tar -xzvf archive_name.tar.gz
20. nano or vim – Text Editors
For editing files directly from the terminal, nano and vim are two common editors. Use nano for simple editing:nano filename.txt
Or vim for more advanced editing (if you’re familiar with its commands):vim filename.txt
21. ssh – Secure Shellssh is used to securely connect to remote machines:ssh user@remote_host
22. wget – Download Files from the Web
To download files from the internet, use wget:wget https://example.com/file.zip
23. history – Show Command History
The history command shows a list of previously run commands:history
24. man – Manual Pages
If you’re unsure how to use a command, you can use man to bring up its manual page:man ls
25. exit – Close the Terminal or Logout
Finally, the exit command is used to close the terminal or log out of an SSH session:exit
Conclusion
These are just a few of the essential Linux commands that will help you navigate and manage your system more efficiently. Whether you’re setting up a server, working on a local machine, or automating tasks, mastering these commands will enhance your productivity. Feel free to experiment with them to deepen your understanding of how Linux operates.check out the List View: click the icon a few spots to the right of the plus icon and you’ll get a tidy, easy-to-view list of the blocks and patterns in your post.