File and directory operations - pwd, rm
1. pwd: display the current location information
Function description of pwd command
The pwd command displays the absolute path of the current working directory to switch back and forth between directories.
Syntax format of pwd command
pwd [OPTION]...
pwd [parameter options]
Option description of pwd command
There are only two pwd options, which are not commonly used, so I will not elaborate:
Practical operation of pwd command
Example 1: execute pwd command without any parameters
[root@oldboyedu ~]# pwd /root <-->Absolute path [root@oldboyedu ~]# cd /etc/init.d/ [root@oldboyedu /etc/init.d]# pwd /etc/init.d <-->Absolute path
2. rm: delete file or directory
Function description of rm command
rm command is used to delete one or more files or directories. It is dangerous. Please use it carefully.
Syntax format of rm command
rm [OPTION]... FILE...
rm [parameter options] [file or directory]
Option description of rm command
The rm option is relatively simple. Table 1 shows the parameters and descriptions of the rm command
Table 1: parameters and description of rm command
Parameter options | Explanation (with * as the focus) |
---|---|
-f | Force deletion, ignore nonexistent files, do not prompt for confirmation* |
-i | Need to confirm before deleting |
-I | Delete more than three files or require confirmation before recursive deletion |
-r | Recursively delete directories and their contents* |
Practical operation of rm command
Experimental environment
[root@oldboyedu ~]# mkdir -p /data/dir{1..3} [root@oldboyedu ~]# touch /data/file{1..3}.txt [root@oldboyedu ~]# tree /data/ /data/ ├── dir1 ├── dir2 ├── dir3 ├── file1.txt ├── file2.txt └── file3.txt 3 directories, 3 files [root@oldboyedu ~]# cd /data/ [root@oldboyedu /data]# ls dir1 dir2 dir3 file1.txt file2.txt file3.txt
Example 1: direct rm execution
[root@oldboyedu /data]# rm file3.txt rm: remove regular empty file 'file3.txt'? n <-->input y Confirm, enter n cancel [root@oldboyedu /data]# Alias rm < -- > the system aliases rm (masks the full path of the preceding \ or command) alias rm='rm -i'
Example 2: forced deletion
[root@oldboyedu /data]# RM - F file3.txt < > [root@oldboyedu /data]# ls dir1 dir2 dir3 file1.txt file2.txt
Example 3: recursive deletion
[root@oldboyedu /data]# mkdir -p dir1/a/b [root@oldboyedu /data]# tree dir1 dir1 └── a └── b 2 directories, 0 files [root@oldboyedu /data]# rm dir1 rm: cannot remove 'dir1': Is a directory [root@oldboyedu /data]# The RM - R dir1 < -- > - R parameter is used to delete the directory rm: descend into directory 'dir1'? y rm: descend into directory 'dir1/a'? y rm: remove directory 'dir1/a/b'? n [root@oldboyedu /data]# The combination of Rm-rf dir1 < -- > should be used with caution
As for today's writing, if you have any questions or mistakes, you are welcome to comment and point out the confusion