SYNOPSIS ls [OPTION]... [FILE]... ls (选项)... (参数)...
选项
DESCRIPTION List information about the FILEs (the current directory by default). Sort entries alphabetically if none of -cftuvSUX nor --sort is specified.
Mandatory arguments to long options are mandatory for short options too.
-a, --all do not ignore entries starting with .
-A, --almost-all do not list implied . and ..
--author with -l, print the author of each file
-b, --escape print C-style escapes for nongraphic characters ... ... -h, --human-readable with -l and/or -s, print human readable sizes (e.g., 1K 234M 2G)
--si likewise, but use powers of 1000 not 1024
-H, --dereference-command-line follow symbolic links listed on the command line
root@VM-16-13-ubuntu:~# ls linux linux-command.text swap.sh ---------------------------------- root@VM-16-13-ubuntu:~# ls -1 linux linux-command.text swap.sh
显示目录隐藏文件与目录
root@VM-16-13-ubuntu:~# ls -a . .bash_history .cache linux-command.text .profile .ssh .viminfo .. .bashrc linux .pip .pydistutils.cfg swap.sh
列出文件和文件夹的详细信息
root@VM-16-13-ubuntu:~# ls -l total 8 drwxr-xr-x 2 root root 4096 Nov 03 19:10 linux -rw-r--r-- 1 root root 0 Nov 03 19:08 linux-command.text -rw-r--r-- 1 root root 2217 Sep 6 2018 swap.sh
root@VM-16-13-ubuntu:~# ls -s total 8 4 linux 0 linux-command.text 4 swap.sh
root@VM-16-13-ubuntu:~# ls -1s total 8 4 linux 0 linux-command.text 4 swap.sh
显示递归文件
root@VM-16-13-ubuntu:~# ls -R .: linux linux-command.text swap.sh
./linux: doc
./linux/doc:
组合查询
列出可读文件和文件夹详细信息。h组合有意思 -h, --human-readable root@VM-16-13-ubuntu:~# ls -lh total 8.0K drwxr-xr-x 3 root root 4.0K Nov 03 19:22 linux -rw-r--r-- 1 root root 0 Nov 03 19:08 linux-command.text -rw-r--r-- 1 root root 2.2K Sep 6 2018 swap.sh
root@VM-16-13-ubuntu:~# ls -sh total 8.0K 4.0K linux 0 linux-command.text 4.0K swap.sh
root@VM-16-13-ubuntu:~# ls -1sh total 8.0K 4.0K linux 0 linux-command.text 4.0K swap.sh
root@VM-16-13-ubuntu:~# ls -lh /swapfile -rw------- 1 root root 2.0G Nov 16 00:37 /swapfile
-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 sys‐ tem different from that of the corresponding command line argument
--no-preserve-root do not treat '/' specially
--preserve-root
-f, --force 忽略不存在的文件,从不给出提示。
-i, --interactive 进行交互式删除
-r, -R, --recursive 指示rm将参数中列出的全部目录和子目录均递归地删除。
-v, --verbose 详细显示进行的步骤
--help 显示此帮助信息并退出
--version 输出版本信息并退出
参数
文件:指定被删除的文件列表,如果参数中含有目录,则必须加上-r或者-R选项。
例
删除文件file,系统会先询问是否删除
root@VM-16-13-ubuntu:~# rm -i rm.txt rm: remove regular empty file 'rm.txt'? n root@VM-16-13-ubuntu:~# ls hello linux linux-command.text project rm.txt swap.sh test1 test2 test3 tmp root@VM-16-13-ubuntu:~# rm -i rm.txt rm: remove regular empty file 'rm.txt'? y root@VM-16-13-ubuntu:~# ls hello linux linux-command.text project swap.sh test1 test2 test3 tmp
强行删除file,系统不再提示
root@VM-16-13-ubuntu:~# touch log.log root@VM-16-13-ubuntu:~# ls hello linux linux-command.text log.log project rm.txt swap.sh test1 test2 test3 tmp root@VM-16-13-ubuntu:~# rm -f log.log root@VM-16-13-ubuntu:~# ls hello linux linux-command.text project rm.txt swap.sh test1 test2 test3 tmp
将 tmp子目录及子目录中所有档案删除
root@VM-16-13-ubuntu:~# ls hello if linux linux-command.text project swap.sh tmp root@VM-16-13-ubuntu:~# rm -rf tmp root@VM-16-13-ubuntu:~# ls hello if linux linux-command.text project swap.sh
删除以-开头的文件
root@VM-16-13-ubuntu:~# touch -- ./{-aaa,-bbb,-ccc,ddd}.log root@VM-16-13-ubuntu:~# ls -- -aaa.log -bbb.log -ccc.log ddd.log hello if linux linux-command.text project swap.sh root@VM-16-13-ubuntu:~# rm -- -* root@VM-16-13-ubuntu:~# ls ddd.log hello if linux linux-command.text project swap.sh
root@VM-16-13-ubuntu:~# ls ddd.log hello if linux linux-command.text project swap.sh root@VM-16-13-ubuntu:~# mv ddd.log aaa.log root@VM-16-13-ubuntu:~# ls aaa.log hello if linux linux-command.text project swap.sh
移动文件、并重命名
root@VM-16-13-ubuntu:~# ls aaa.log hello if linux linux-command.text project swap.sh root@VM-16-13-ubuntu:~# ls linux root@VM-16-13-ubuntu:~# mv aaa.log linux root@VM-16-13-ubuntu:~# ls linux aaa.log root@VM-16-13-ubuntu:~# ls hello if linux linux-command.text project swap.sh
root@VM-16-13-ubuntu:~# mv linux/aaa.log bbb.log root@VM-16-13-ubuntu:~# ls bbb.log hello if linux linux-command.text project swap.sh
移动前备份
root@VM-16-13-ubuntu:~# touch hello/bbb.log root@VM-16-13-ubuntu:~# mv hello/bbb.log bbb.log -b root@VM-16-13-ubuntu:~# ls bbb.log bbb.log~ hello if linux linux-command.text project swap.sh