1. View the current directory (print working directory)
The basic format of this command is:
[root@localhost ~]# pwd
2. View all subdirectories or file lists in the specified directory (list)
The basic format of this command is:
[root@localhost ~]# ls [选项] 目录名称
options:
-
-a: Display all files, including hidden files (
.
files beginning with ) -
-l: use long format to list file and directory information
3. Change directory
The basic format of this command is as follows:
[root@localhost ~]# cd [相对路径或绝对路径]
- Absolute path: the directory starting with the drive letter
- Relative directory: the directory starting with the directory name
The cd command can be followed by some special symbols to express fixed meanings
special symbols | effect |
---|---|
~ | Represents the home directory of the currently logged in user |
~username | Indicates switching to the home directory of the specified user |
- | Represents the last directory |
. | represents the current directory |
. . | Represents the parent directory |
4. Create directories (make directories)
The basic format of this command is:
[root@localhost ~]# mkdir [选项] 目录名
[root@localhost ~]# mkdir -p /home/test/demo
options:
- -m: Used to manually configure the permissions of the created directory instead of using the default permissions
- -p: Create all directories recursively. Take the creation
/home/test/demo
as an example. By default, you need to create each directory layer by layer.-p
If you use the option, the system will automatically create/home、/home/test
and/home/test/demo
5. Delete an empty directory (remove empty directories)
The basic format of this command is:
[root@localhost ~]# rmdir [选项] 目录名
options:
- -p : Used to delete empty directories recursively.
The rmdir command can only delete empty directories
6. Create one or more empty files
[root@localhost ~]# touch [文件名或文件名列表](创建多个文件时文件名之间用空格隔开)
例如:
[root@localhost ~]# touch t1.txt #创建名为 t1.txt 的空文件
[root@localhost ~]# touch t1.txt t2.txt #创建t1.txt t2.txt两个空文件
7. Copy files or directories (copy)
The basic format of this command is as follows:
[root@localhost ~]# cp [选项] 源文件 目标文件
[root@localhost ~]# cp -r test1 test2 #把目录test1中的文件递归复制到目录test2中
options:
- -d: If the source file is a soft link (invalid for hard links), the copied target file is also a soft link
- -i: Ask, if the target file already exists, it will ask whether to overwrite
- -p: After copying, the target file retains the attributes of the source file (including owner, group, permissions and time)
- -r: recursive copy, used to copy directories
8. Delete a file or directory (remove)
The basic format of this command is:
[root@localhost ~]# rm [选项] 文件或目录
options:
- -f: force delete (force), use
-f
, the system will no longer ask, but directly delete the target file or directory - -i: On
-f
the contrary, before deleting a file or directory, the system will give a prompt message, using-i
can effectively prevent accidentally deleting useful files or directories - -r: Recursive deletion, mainly used to delete directories, can delete the specified directory and all its contents, including all subdirectories and files
9. Move directory, file or rename (move)
[root@localhost ~]# mv [选项] 源文件 目标文件
options:
- -f: force overwrite, if the target file already exists, it will force overwrite directly without asking;
- -i: Interactive move, if the target file already exists, ask the user whether to overwrite (default option);
- -n: If the target file already exists, the move will not be overwritten and the user will not be asked;
- -v: Display the moving process of files or directories;
- -u: If the target file already exists, but the source file is newer than the two, the target file will be upgraded;
If the source and destination files are in the same directory, that's renaming