每天一命令(5) rm (remove files or directories) 1分钟

man rm 查看文档

参数说明

NAME
       rm - remove files or directories

SYNOPSIS
       rm [OPTION]... FILE...

DESCRIPTION
       This  manual  page  documents  the  GNU  version of rm.  rm removes each specified file.  By default, it does not remove
       directories.

       If the -I or --interactive=once option is given, and there are more than three files or the -r, -R, or  --recursive  are
       given,  then  rm prompts the user for whether to proceed with the entire operation.  If the response is not affirmative,
       the entire command is aborted.

       Otherwise, if a file is unwritable, standard input is a terminal, and the -f or --force option is not given, or  the  -i
       or  --interactive=always  option  is  given, rm prompts the user for whether to remove the file.  If the response is not
       affirmative, the file is skipped.

OPTIONS
       Remove (unlink) the FILE(s).

       -f, --force
              ignore nonexistent files, 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

       -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 is usually possible to recover the contents of that file.  If you want more
       assurance that the contents are truly unrecoverable, consider using shred.
删除文件 rm java.txt 默认是带提示是否删除
root@guofeng  ~/java
# ls -al
total 8
drwxr-xr-x  2 root root 4096 Jun  9 19:42 .
dr-xr-x---. 6 root root 4096 Jun  9 19:20 ..
-rw-r--r--  1 root root    0 Jun  9 19:41 css.css
-rw-r--r--  1 root root    0 Jun  9 19:41 index.html
-rw-r--r--  1 root root    0 Jun  9 19:20 java.txt
-rw-r--r--  1 root root    0 Jun  9 19:42 jdbc.properties

root@guofeng  ~/java
# rm -v java.txt 
rm: remove regular empty file `java.txt'? y
removed `java.txt'
删除文件时,不提示是否是删除 rm -I css.css rm -f 忽略提示信息
root@guofeng  ~/java
# rm -vI css.css 
removed `css.css'

root@guofeng  ~/java
# ll
total 0
-rw-r--r-- 1 root root 0 Jun  9 19:41 index.html
-rw-r--r-- 1 root root 0 Jun  9 19:42 jdbc.properties

root@guofeng  ~/java
# rm -f index.html 

root@guofeng  ~/java
# ll
total 0
-rw-r--r-- 1 root root 0 Jun  9 19:42 jdbc.properti
递归删除文件,和文件夹 rm -rf web/
root@guofeng  ~/java
# mkdir -p web/css

root@guofeng  ~/java
# ll
total 4
-rw-r--r-- 1 root root    0 Jun  9 19:42 jdbc.properties
drwxr-xr-x 3 root root 4096 Jun  9 19:49 web

root@guofeng  ~/java
# cd web/

root@guofeng  ~/java/web
# ll
total 4
drwxr-xr-x 2 root root 4096 Jun  9 19:49 css

root@guofeng  ~/java/web
# cd css/

root@guofeng  ~/java/web/css
# ll
total 0

root@guofeng  ~/java/web/css
# touch index.css

root@guofeng  ~/java
# rm -rf web/

root@guofeng  ~/java
# ll
total 0
-rw-r--r-- 1 root root 0 Jun  9 19:42 jdbc.properties

rm 默认提示是否删除,因为在别名里面 就有

alias rm=’rm -i’

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值