The Linux rm command is used to delete a file or directory.
Syntax
rm [options] name...
Parameters:
-i Ask for confirmation one by one before deleting.
-f Even if the original file attribute is set to read-only, it will be deleted directly without confirming one by one.
-r Delete the files in the directory and below one by one.
Example
1. 删除文件可以直接使用rm命令,若删除目录则必须配合选项"-r"
$ rm test.txt
2. $ rm testdr
rm: 无法删除目录"testdr": 是一个目录
$ rm -r homework
3. 删除当前目录下的所有文件及目录,命令行为:
$ rm -r *
文件一旦通过rm命令删除,则无法恢复,所以必须格外小心地使用该命令。
The Linux cp command is mainly used to copy files or directories.
Syntax
cp [options] source dest
or
cp [options] source... directory
parameter description:
-a: This option is usually used when copying a directory, it preserves links, file attributes, and copies all contents under the directory. Its effect is equal to the combination of dpR parameters.
-d: keep links when copying. The links mentioned here are equivalent to shortcuts in Windows systems.
-f: Overwrite existing object files without prompting.
-i: Contrary to the -f option, give a prompt before overwriting the target file, asking the user to confirm whether to overwrite, answering "y" The target file will be overwritten.
-p: In addition to copying the contents of the file, also copy the modification time and access rights to the new file.
-r: If the given source file is a directory file, all subdirectories and files in the directory will be copied.
-l: Do not copy files, just generate link files.
Example
1. #复制 test.txt,命名为 test2.txt
$ cp test.txt test2.txt
2. #使用指令"cp"将当前目录"test/"下的所有文件复制到新目录"newtest"下
$ cp –r test/ newtest
注意:用户使用该指令复制目录时,必须使用参数"-r"或者"-R"。