简介:
ubuntu中删除命令一般使用rm,但是rm误删之后,想恢复比较麻烦,所以今天我们还介绍另外一种删除方法,trash,文件删除是放到回收站,这样误删之后还有挽回的机会。
1.rm命令
最简单最有效最权威的看命令的方法就是看--help,
1.1 --help
Usage: rm [OPTION]... FILE...
Remove (unlink) the FILE(s).
-f, --force ignore nonexistent files and arguments, never prompt
-i prompt before every removal
-I prompt once before removing more than three files, or
when removing recursively. Less intrusive than -i,
while still giving protection against most mistakes
--interactive[=WHEN] prompt according to WHEN: never, once (-I), or
always (-i). Without WHEN, prompt always
--one-file-system when removing a hierarchy recursively, skip any
directory that is on a file system different from
that of the corresponding command line argument
--no-preserve-root do not treat '/' specially
--preserve-root do not remove '/' (default)
-r, -R, --recursive remove directories and their contents recursively
-d, --dir remove empty directories
-v, --verbose explain what is being done
--help display this help and exit
--version output version information and exit
By default, rm does not remove directories. Use the --recursive (-r or -R)
option to remove each listed directory, too, along with all of its contents.
To remove a file whose name starts with a '-', for example '-foo',
use one of these commands:
rm -- -foo
rm ./-foo
Note that if you use rm to remove a file, it might be possible to recover
some of its contents, given sufficient expertise and/or time. For greater
assurance that the contents are truly unrecoverable, consider using shred.
简单的翻译一下:
使用方法:rm [选项].. 文件..
删除(unlink)文件
-f,--force 强制删除文件,无论文件是否存在,都不会提示确认 (和-i的作用刚好相反)
-i 在删除文件前给确认提示
-I 比-i提示的要少,只当文件多于3个或者删除有递归的文件的时候才提示,但也能阻止很多错误。
--interactive[=WHEN] 根据WHEN来决定提示:never,once(-I)或者always(-i)。如果没有WHEN,默认为always。
--one-file-system 递归删除一个层级时,跳过所有不符合命令行参数的文件系统上的文件 (这个我暂时还不懂)
--no-preserve-root 不特殊对待'/'
--preserve-root 不去删除'/'
-r,-R,--recursive 删除文件夹以及它下面递归的文件
-d,--dir 删除空文件夹
-v,--verbose 详细解释每一步删除
--help 显示帮助,并退出
--version 输出版本信息
默认,rm不会删除文件夹。使用--recursive(-r or -R)选项去删除文件夹以及它下面的目录文件
删除一个文件,例如删除-foo,可以使用rm如下
rm -- -foo
rm ./-foo
1.2 rm命令使用实例
yangchunsk@yangchunsk:~/Desktop$ ls
Document Document2 Document3 Document4 Untitled
yangchunsk@yangchunsk:~/Desktop$ rm Document
yangchunsk@yangchunsk:~/Desktop$ ls
Document2 Document3 Document4 Untitled
yangchunsk@yangchunsk:~/Desktop$ rm -i Document2
rm: remove regular empty file ‘Document2’? y
yangchunsk@yangchunsk:~/Desktop$ ls
Document3 Document4 Untitled
yangchunsk@yangchunsk:~/Desktop$ rm -iv Document3
rm: remove regular empty file ‘Document3’? y
removed ‘Document3’
yangchunsk@yangchunsk:~/Desktop$ ls
Document4 Untitled
yangchunsk@yangchunsk:~/Desktop$ rm -riv Untitled/
rm: descend into directory ‘Untitled/’? y
rm: remove regular empty file ‘Untitled/Document5’? y
removed ‘Untitled/Document5’
rm: remove directory ‘Untitled/’? y
removed directory: ‘Untitled/’
yangchunsk@yangchunsk:~/Desktop$ ls
Document4
2.trash命令
2.1 介绍
trasn删除是将文件删除到回收站中,但是trash不是自带的命令,需要使用sudo apt-get install trash-cil来安装trash。
2.2 --help
Usage: trash [OPTION]... FILE...
Put files in trash
Options:
--version show program's version number and exit
-h, --help show this help message and exit
-d, --directory ignored (for GNU rm compatibility)
-f, --force ignored (for GNU rm compatibility)
-i, --interactive ignored (for GNU rm compatibility)
-r, -R, --recursive ignored (for GNU rm compatibility)
-v, --verbose explain what is being done
To remove a file whose name starts with a `-', for example `-foo',
use one of these commands:
trash -- -foo
trash ./-foo
使用方法和rm基本相似,所以这里就不介绍了