Linux has many commonly used commands, the following are some common commands that must be mastered in daily use:
1. ls: used to list the files and subdirectories in the directory. Common options are:
-
-l
: Displays file details in long format.-a
: Show all files, including.
hidden files starting with .-h
: Displays the file size in human readable format.-R
: Recursively display subdirectory contents.
2. cd: used to change the current working directory. Example:
-
cd /path/to/directory
: Switch to the directory of the specified path.cd ..
: Switch to the upper level directory.cd ~
: Switch to the current user's home directory.
3. pwd: Display the path of the current working directory.
4. mkdir: Create a new directory. Example:
-
mkdir directory_name
: Createdirectory_name
a directory named .
5. rm: used to delete files and directories. Common options are:
-
-r
: Recursively delete a directory and its contents.-f
: Forcefully delete a file or directory without confirmation.
6. cp: used to copy files and directories. Example:
-
cp file1 file2
: will befile1
copied tofile2
.cp -r directory1 directory2
: Copy the directory and its contents todirectory2
.
7. mv: used to move files and directories, or rename files and directories. Example:
-
mv file1 file2
: will befile1
moved or renamed tofile2
.mv file1 directory
: willfile1
move todirectory
directory.
8. touch: Create a new file or update the access time and modification time of an existing file. Example:
-
touch file_name
: Createfile_name
an empty file named .touch -a file_name
: only updatedfile_name
access time.touch -m file_name
: Onlyfile_name
the modified time of the update.
9. cat: used to view the contents of the file. Example:
-
cat file_name
: Displayedfile_name
content.
10. less: Display file content page by page, suitable for large files. Example:
-
less file_name
: Openfile_name
, use the up and down arrows to browse the contents.
11. grep: Search for the specified pattern in the file. Example:
-
grep pattern file_name
:file_name
Search inpattern
.
12. find: Search files according to the specified conditions. Example:
-
find /path/to/search -name "pattern"
pattern
: Search for files matching the pattern by name in the specified path .
13. chmod: Modify the permissions of files or directories. Example:
-
chmod permissions file_name
:file_name
Set the permissions for permissions to permissions.chmod +x script.sh
: Add execution permission to the script file.
14. chown: Modify the owner of a file or directory. Example:
chown user_name file_name
:file_name
Change the owner of touser_name
.chown user_name:group_name file_name
:file_name
Change the owner touser_name
and the group togroup_name
.
15. chgrp: Modify the group to which a file or directory belongs. Example:
chgrp group_name file_name
:file_name
Change the belonging group togroup_name
.
16. sudo: Execute commands as a super user (root). Example:
- sudo command: Execute as superuser
command
.
17. su: switch user identity. Example:
su username
: Switch tousername
user.
18. tar: Create and extract archive files (compressed files). Example:
tar -cvf archive.tar file1 file2
: Packfile1
andfile2
as archive.tar.tar -xvf archive.tar
: Unziparchive.tar
the file.
19. gzip: compress files. Example:
gzip file_name
: compressfile_name
, generatefile_name.gz
.
20. unzip: decompress files. Example:
unzip file_name.zip
: Unzipfile_name.zip
the file.
These commands cover common tasks such as file and directory manipulation, rights management, file searching, and compression. Of course, the Linux system provides more powerful commands and functions, which can be further studied and mastered according to needs.