ls——进阶使用,遍历、匹配和过滤文件
# 最常用最屌的ls命令
ls -alF
ll -aF
、l -F
强大之处在于,显示详细信息的同时还区分了文件夹和文件(文件夹后带有“/”)
jim at LAPTOP-QQ68DGFG in ~
$ ls -alF
total 140
drwxr-xr-x 1 jim jim 4096 Dec 30 12:02 ./
drwxr-xr-x 1 root root 4096 Oct 30 11:46 ../
-rw------- 1 jim jim 645 Dec 17 22:14 .bash_history
-rw-r--r-- 1 jim jim 220 Oct 30 11:46 .bash_logout
-rw-r--r-- 1 jim jim 3771 Oct 30 11:46 .bashrc
drwx------ 1 jim jim 4096 Nov 9 18:30 .config/
drwxr-xr-x 1 jim jim 4096 Oct 30 11:46 .landscape/
-rw-r--r-- 1 jim jim 0 Dec 17 21:53 .motd_shown
drwxr-xr-x 1 jim jim 4096 Dec 30 11:36 .oh-my-zsh/
-rw-r--r-- 1 jim jim 807 Oct 30 11:46 .profile
-rw-r--r-- 1 jim jim 0 Dec 15 13:52 .sudo_as_admin_successful
drwxr-xr-x 1 jim jim 4096 Oct 30 12:01 .vim/
-rw------- 1 jim jim 4232 Dec 22 10:40 .viminfo
-rw-r--r-- 1 jim jim 48971 Dec 17 22:06 .zcompdump
-rw-r--r-- 1 jim jim 50324 Dec 30 11:36 .zcompdump-LAPTOP-QQ68DGFG-5.8
-rw------- 1 jim jim 2007 Dec 30 12:02 .zsh_history
-rw-r--r-- 1 jim jim 3674 Dec 17 22:35 .zshrc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# 遍历文件夹(递归)
ls -R
jim at LAPTOP-QQ68DGFG in ~
$ ls -R
.:
Doc Img
./Doc:
test.txt
./Img:
Snipaste_2021-12-20_12-47-23.png
1
2
3
4
5
6
7
8
9
10
2
3
4
5
6
7
8
9
10
ls -FR
jim at LAPTOP-QQ68DGFG in ~
$ ls -FR
.:
Doc/ Img/
./Doc:
test_1.txt test_2.txt test_3.pdf
./Img:
Snipaste_2021-12-20_12-47-23.png
1
2
3
4
5
6
7
8
9
10
2
3
4
5
6
7
8
9
10
# 文件扩展匹配符
*
——指代多个?
——指代一个
将 pdf 文件过滤掉:
ls *.txt
jim at LAPTOP-QQ68DGFG in ~/Doc
$ ls
test_1.txt test_2.txt test_3.pdf
jim at LAPTOP-QQ68DGFG in ~/Doc
$ ls *.txt
test_1.txt test_2.txt
1
2
3
4
5
6
7
2
3
4
5
6
7
ls test_?.txt
jim at LAPTOP-QQ68DGFG in ~/Doc
$ ls test_?.txt
test_1.txt test_2.txt
1
2
3
2
3
# 元字符通配符
ls t[a-x]st.txt
jim at LAPTOP-QQ68DGFG in ~/Doc
$ ls
tast.txt tbst.txt tcst.txt tzst.txt
jim at LAPTOP-QQ68DGFG in ~/Doc
$ ls t[a-x]st.txt
tast.txt tbst.txt tcst.txt
1
2
3
4
5
6
7
2
3
4
5
6
7
编辑 (opens new window)
上次更新: 2022/09/26, 16:55:15