Linux 命令精讲
1、Linux 复习
1.1 提问
markdown
# 1、shell 是干嘛的?
# 2、什么是相对路径、绝对路径
# 3、命令字格式:
命令:核心:(基本功能)
选项:核心:(附加、额外功能)
参数:指令功能处理的对象
2、Linux 学习
2.1 ls 选项
markdown
# ls -R 选项 ,递归显示指定目录的所有子目录的文件列表
[root@localhost usr]# ls -R local/
local/:
bin etc games include lib lib64 libexec sbin share src
....省略
local/sbin:
local/share:
applications info man
local/share/applications:
local/share/info:
local/share/man:
man1 man2 man3 man4 man5 man6 man7 man8 man9 mann
man1x man2x man3x man4x man5x man6x man7x man8x man9x
local/share/man/man1:
local/share/man/man1x:
....省略
# ls -h ,友好显示(简单来说就是显示单位)
[root@localhost opt]# ls -l
总用量 4
-rw-r--r--. 1 root root 0 4月 13 16:04 1.txt
-rw-r--r--. 1 root root 310 4月 13 14:49 ifcfg-ens33
[root@localhost opt]# ls -lh
总用量 4.0K
-rw-r--r--. 1 root root 0 4月 13 16:04 1.txt
-rw-r--r--. 1 root root 310 4月 13 14:49 ifcfg-ens33
小结:ls -R 表示递归显示,递归:逐级目录进行操作
2.2 通配符
**定义:**通配符是系统自带的用于模糊匹配的功能
markdown
# 通配符 "?"
[root@localhost opt]# ls
1.txt 2.txt 3.txt 4.txt ifcfg-ens33
[root@localhost opt]# ls ?.txt
1.txt 2.txt 3.txt 4.txt
[root@localhost opt]# ls 1.tx?
1.txt
[root@localhost opt]# ls 1?txt
1.txt
[root@localhost opt]# ls ????t
1.txt 2.txt 3.txt 4.txt
# 通配符 "*"
[root@localhost opt]# ls *txt
1txt 1.txt 2.txt 3.txt 4.txt
[root@localhost opt]# touch txt
[root@localhost opt]# ls
1txt 1.txt 2.txt 3.txt 4.txt ifcfg-ens33 txt
[root@localhost opt]# ls *txt
1txt 1.txt 2.txt 3.txt 4.txt txt
[root@localhost opt]# ls 1*t
1txt 1.txt
小结:"?":匹配文件名中的一个未知字符,而 "*":匹配文件名中的任意多个字符
2.3 du 查看目录和文件占用磁盘的信息
markdown
# 命令字格式
du [选项] [文件或目录... ]
du 基本功能:统计目录或文件的大小
# 选项 -a -h -s
-a 选项:表示统计所有目录及其子目录/子文件的大小,最后求和,例如:
[root@localhost etc]# du -ah
...省略
8.0K ./man_db.conf
4.0K ./e2fsck.conf
4.0K ./mke2fs.conf
4.0K ./sudo-ldap.conf
4.0K ./sudo.conf
8.0K ./sudoers
0 ./sudoers.d
4.0K ./vconsole.conf
4.0K ./locale.conf
4.0K ./hostname
4.0K ./.updated
12K ./aliases.db
31M .
-h 友好显示
-s 只统计总占用空间
[root@localhost etc]# du -sh
31M .