Linux study notes: basic instructions mkdir, rmdir, and rm

#The learning content comes from Mofan python: linux tutorial

mkdir creates a folder
mkdir (make directory) means creating a folder, and it is very simple to use.

$ mkdir folder2

If you want to create another folder in folder2 in this directory, it is also Ok.

$ mkdir folder2/f2
In this way, the folder f2 is newly created in folder2.

 

rmdir removes the folder
rmdir (remove directory) is literally, remove the folder. But there is a precondition. These folders to be removed must be empty. Otherwise it will fail. So if you want the one you just created folder2 cannot be removed because there is an f2 folder in it.

To remove an empty folder, for example, I am creating a new folder3, and then remove

$ rmdir folder3


rm removes files
in the folder where there is a file, or removes a single file, we can use rm to do it. Note: After executing rm, the return operation cannot be performed, please make sure not to execute operations like Do something like rm /, which will wipe your computer.

1 remove a single file

$ rm file1
2 -i or -I prompt to remove files (to avoid accidental deletion)

-i will prompt for each file to be removed -I will prompt for
more than 3 files
$ rm -i f1 f2 f3 f4
rm: remove regular empty file 'f1'?
rm: remove regular empty file 'f2'? y
rm: remove regular empty file 'f3'?
rm: remove regular empty file 'f4'? y
$ rm -I f1 f2 f3 f4
rm: remove 4 arguments? y
3 -r or -R (recursively) to delete the file folder

Different from rmdir, rm -r can delete a folder if there are files in the folder. For example, my folder1 has two files, file1 and file2.

$ rm -r folder1

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325028366&siteId=291194637