Essential Linux Commands for Efficient File and System Management
File and Directory Commands:
1. ls (List): Used to list files and directories in the current directory.
Example: ls will display a list of files and directories in your current location.
2. cd (Change Directory): Used to navigate between directories.
Example: cd /home/user/documents will change your current directory to "documents."
3. pwd (Print Working Directory): Displays the current working directory.
Example: pwd will show the full path of your current directory.
4. mkdir (Make Directory): Creates a new directory.
Example: mkdir new_folder will create a directory named "new_folder."
5. rmdir (Remove Directory): Deletes an empty directory.
Example: rmdir old_folder will remove the empty directory "old_folder."
File Manipulation Commands:
6. touch: Creates a new empty file.
Example: touch new_file.txt will create an empty file named "new_file.txt."
7. rm (Remove): Deletes files and directories.
Example: rm old_file.txt will delete the file "old_file.txt."
8. cp (Copy): Copies files and directories.
Example: cp source_file.txt destination/ will copy "source_file.txt" to the "destination" directory.
9. mv (Move): Moves or renames files and directories.
Example: mv file.txt new_location/ will move "file.txt" to the "new_location" directory.
File Content Viewing Commands:
10. cat (Concatenate): Displays the content of a file.
Example: cat file.txt will display the content of "file.txt."
11. more and less: View file contents one page at a time. Useful for long files.
领英推荐
Example: less long_file.txt will allow you to view "long_file.txt" one page at a time.
Text Search and File Search Commands:
12. grep (Global Regular Expression Print): Searches for text patterns in files.
Example: grep "keyword" file.txt will search for the word "keyword" in "file.txt."
13. find: Searches for files and directories.
Example: find /home/user -name "*.txt" will search for all files with a ".txt" extension in the "/home/user" directory.
File Permission and Ownership Commands:
14. chmod (Change Mode): Changes file permissions.
Example: chmod 644 file.txt will set read and write permissions for the owner and read-only permissions for others on "file.txt."
15. chown (Change Owner): Changes file ownership.
Example: chown user:group file.txt will change the owner and group of "file.txt" to "user" and "group."
Process Management Commands:
16. ps (Process Status): Lists running processes.
Example: ps aux will display a list of all running processes.
17. kill: Terminates processes.
Example: kill -9 process_id will forcefully terminate a process with the specified ID.
File Compression and Archiving Commands:
18. tar: Used to archive and compress files and directories.
Example: tar -cvzf archive.tar.gz folder/ will create a compressed archive of the "folder."
Disk Space Usage Commands:
19. df (Disk Free): Displays disk space usage.
Example: df -h will show disk space usage in a human-readable format.
20. du (Disk Usage): Shows the sizes of directories and files.
Example: du -sh directory/ will display the total size of the "directory" in a human-readable format.