目錄
介紹
ls命令用來顯示當前目錄下的文件和目錄名稱。
使用
基本列表功能
使用 ls 命令顯示當前目錄下的文件和目錄名稱:
>>> ls
Applications FusionStudent_lite Movies PycharmProjects eclipse kvm rsaDemo
Code Goland-workspace Music SubwayTraffic eclipse-workspace learn ux_client
Desktop HBuilder Pictures SubwayTrafficWEB go log uxcloudcmd
Documents HBuilderProjects Postman a.txt.temp gormexe nova uxcloudrc1
Downloads Library Public awesomeProject gotable oldcloud
💡提示:ls命令輸出的列表是按照英文字母按列排序的。ls命令還可以用不同的顏色區分不同類型的文件(前提是用戶使用的是支持彩色的終端仿真器)
區分文件和目錄
使用 ls -F 命令可以在顯示結果中明顯的區分文件和目錄。所有的目錄後方都會加上正斜線“/”。
>>> ls -F
alert/ config/ dwm/ license/ monitor/ scheduler/ utils/
auth/ config.conf.sample ha/ main.go network/ session/ vmstatus/
compute/ controller/ history/ model/ rabbitmq/ storage/
顯示隱藏文件
要把隱藏文件和普通文件及目錄一起顯示出來,就得用到-a參數。
ls -a
使用示例:
$ ls -a
. .vimplus
.. .vimrc
.CFUserTextEncoding .vimrc.local
.DS_Store .vscode
.LfCache .ycm_extra_conf.py
.Trash .zcompdump-一條小路通羅馬的MacBook Pro-5.3
.android .zsh_history
.anydesk .zshrc
.appletviewer Applications
.bash_history Code
.bash_profile Desktop
.bash_profile.pysave Documents
.bash_sessions Downloads
.bashrc FusionStudent_lite
.cups Goland-workspace
.dlv HBuilder
.downloader HBuilderProjects
.eclipse Library
.gitconfig Movies
.idlerc Music
.ipython Pictures
.lesshst Postman
.m2 Public
.mysql_history PycharmProjects
.node_repl_history SubwayTraffic
.nuuid.ini SubwayTrafficCMD
.oh-my-zsh SubwayTrafficWEB
.oracle_jre_usage awesomeProject
.p2 eclipse
.pyenv eclipse-workspace
.python_history go
.python_history-31920.tmp gotable
.python_history-44346.tmp kvm
.python_history-59192.tmp learn
.python_history-63533.tmp log
.python_history-77145.tmp nova
.python_history-87385.tmp oldcloud
.ssh oldcloudweb
.swt rsaDemo
.tooling ux_client
.vim uxcloudcmd
.viminfo uxcloudrc1
⚠️所有以"."開頭的文件表示隱藏文件。
顯示目錄中的所有文件
-R參數是ls命令的遞歸參數,它可以列出當前目錄下包含的所有文件,包括子目錄中的文件。
ls -R
使用示例:
$ ls -R
README.md api conf doc logs server_init.py templates util.py
__pycache__ conductor db errors main.py static test
./__pycache__:
main.cpython-37.pyc server_init.cpython-37.pyc util.cpython-37.pyc
./api:
__init__.py __pycache__ email.py line.py station.py system.py user.py
./api/__pycache__:
__init__.cpython-37.pyc email.cpython-37.pyc line.cpython-37.pyc system.cpython-37.pyc user.cpython-37.pyc
./conductor:
__init__.py __pycache__ line.py process_stack.py system.py user.py
./conductor/__pycache__:
__init__.cpython-37.pyc process_stack.cpython-37.pyc user.cpython-37.pyc
line.cpython-37.pyc system.cpython-37.pyc
./conf:
database.conf depend_packages.json platform.conf stp.version tips_en.ini tips_zh.ini
./db:
__init__.py __pycache__ engine.py line.py user.py
./db/__pycache__:
__init__.cpython-37.pyc engine.cpython-37.pyc line.cpython-37.pyc user.cpython-37.pyc
./doc:
new_features_v1.0.0.txt project.txt
./errors:
HTTPcode.py __init__.py __pycache__
./errors/__pycache__:
HTTPcode.cpython-37.pyc __init__.cpython-37.pyc
./logs:
__init__.py __pycache__ logger.py
./logs/__pycache__:
__init__.cpython-37.pyc logger.cpython-37.pyc
./static:
404_pages.html login.html
./templates:
send_code.html
./test:
__init__.py test1.py test2.py
顯示文件長列表
在基本的輸出列表中,ls命令並未輸出太多每個文件的相關信息。要顯示更多附加信息,使用-l參數。
ls -l
使用示例
$ ls -l
total 32
-rw-r--r-- 1 root staff 16 11 18 14:24 README.md
drwxr-xr-x 5 root staff 160 12 26 15:02 __pycache__
drwxr-xr-x 9 root staff 288 12 28 21:00 api
drwxr-xr-x 8 root staff 256 12 28 21:03 conductor
drwxr-xr-x 8 root staff 256 12 28 21:03 conf
drwxr-xr-x 7 root staff 224 12 27 10:46 db
drwxr-xr-x 5 root staff 160 12 28 21:09 doc
drwxr-xr-x 5 root staff 160 12 24 11:18 errors
drwxr-xr-x 5 root staff 160 11 28 09:40 logs
-rw-r--r-- 1 root staff 1796 12 17 15:08 main.py
-rw-r--r-- 1 root staff 584 12 16 11:23 server_init.py
drwxr-xr-x 4 root staff 128 12 27 17:36 static
drwxr-xr-x 3 root staff 96 12 16 17:22 templates
drwxr-xr-x 5 root staff 160 12 26 17:39 test
-rw-r--r-- 1 root staff 3663 12 26 15:01 util.py
我們以-rw-r--r-- 1 root staff 16 11 18 14:24 README.md爲例,顯示的附加內容含義如下表所示:
- 類型:- (表示一個文件)
- 權限:rw-r--r-- (表示屬主可讀可寫,其餘用戶僅可讀)
- 硬連接總數:1
- 屬主的用戶名:root
- 屬組的組名:staff
- 大小(單位是字節):16
- 上次修改時間:11 18 14:24 (指11月18日14:24 最後一次修改)
- 名稱:README.md
📖在有些Linux系統中,使用ll命令和 ls -l命令效果是一致的。
參數組合使用
可以將多個參數組合使用。例如 ls -a -R的意思是查看當前目錄下所有文件,包括隱藏文件。一個更簡便的寫法是 ls -aR。