3 2 Linux ls命令 顯示當前目錄下的檔案

2022-08-24 13:21:17 字數 2632 閱讀 9148

ls是最常見的目錄操作命令,主要作用是顯示目錄下的內容,這個命令的基本資訊如下:

命令名稱:ls

英文原意:list

所在路徑:/bin/ls

執行許可權:所有使用者

功能描述:顯示目錄下的內容

命令格式:

[root@localhost ~]#ls [選項][檔名或目錄名]

選項:

-a:顯示所有檔案

--color=when:支援顏色輸出,when的預設值是always(總顯示顏色),也可以是never(從不顯示顏色)和auto;

-d:顯示目錄資訊,而不是目錄下的檔案

-h:人性化顯示,按照我們習慣的單位顯示檔案大小

-i:顯示檔案的i節點號

-l:長格式顯示

常見用法

a:「-a」選項

-a選項中的a是all的意思,也就是顯示隱藏檔案,例如

[root@localhost ~]# ls

anaconda-ks.cfg install.log

install.log.syslog

[root@localhost ~]# is -a

.anacondaks

.cfg.bash_logout

.bashrcinstall.log

.mysql_history

.viminfo ...bash_history

.bash_profile

.cshrc

install.log

.syslog

.tcshrc

當加入-a選項後,顯示出來的檔案明顯增多,多出來的檔案都有乙個共同的特徵,就是以「.」開頭,在linux中以「.」開頭的檔案都是隱藏檔案,只有通過-a選項才能看到。

b:「-l」選項

[root@localhost

~]# ls -l

總用量44

-rw-------.1 root root 1207 1 月14 18:18

anaconda-ks.cfg

-rw-r-r--.1 root root 24772 1 月14 18:17

install.log

-rw-r-r--.1 root root 7690 1 月14 18:17

install.log.syslog

#許可權 引用計數 所有者 所屬組 大小 檔案修改時間 檔名

-l選項用於顯示檔案的詳細資訊,以上#後面表示顯示資訊的7列資訊

第一列:許可權,具體含義將在後續講解

第二列:引用計數,代表該檔案的硬連線個數,而目錄的引用計數代表該目錄的一級子目錄數。

第三列:所有者,也就是這個檔案屬於哪個使用者,預設的所有者是檔案的建立使用者

第四列:所屬組,預設所屬組是檔案建立使用者的有效組,一般情況下就是建立使用者的所在組。

第五列:大小,預設單位是位元組

第六列:檔案修改時間,檔案狀態修改時間或檔案資料修改時間都會更改這個時間,注意這個時間不是檔案的建立時間。

第七列:檔名

c:「-d」選項

如果想檢視某個目錄的詳細資訊,例如

[root@localhost

~]# ls -l /root/

總用量44

-rw-------.1 root root 1207 1 月14 18:18

anaconda-ks.cfg

-rw-r-r--.1 root root 24772 1 月14 18:17

install.log

-rw-r-r--.1 root root 7690 1 月14 18:17

install.log.syslog

這個命令會顯示目錄下的內容,而不會顯示這個目錄本身的詳細資訊,如果想顯示目錄本身的資訊,就必須加入-d選項

[root@localhost

~]# ls -ld /root/

dr-xr-x---.2 root root 4096 1 月20 12:30

/root/

d:「-h」選項

ls–l顯示的檔案大小是位元組,但我們更加習慣的用千位元組kb顯示,兆位元組用mb表示,而-h就是按照人們習慣的單位來顯示檔案大小。

例如:[root@localhost

~]# ls -lh

總用量44k

-rw-------.1 root root1.2k 1 月14 18:18

anaconda-ks.cfg

-rw-r-r--.1 root root25k 1 月14 18:17

install.log

-rw-r-r--.1 root root7.6k 1 月14 18:17

install.log.syslog

e: 「-i」選項

每個檔案都有乙個被稱作inode(i節點)的隱藏屬性,可以看成是系統搜尋這個檔案的id,而-i就是用來檢視這個檔案的inode號的,例如:

[root@localhost

~]# ls -i

262418 anaconda-ks.cfg 262147

install.log 262148 install.log.syslog

從理論上講,每個檔案的inode號都不一樣,當然也有例外,如硬鏈結。

linux ls命令按時間顯示檔案

附,ls命令的引數中文詳解 a 列出目錄下的所有檔案,包括以 開頭的隱含檔案。b 把檔名中不可輸出的字元用反斜槓加字元編號 就象在c語言裡一樣 的形式列出。c 輸出檔案的 i 節點的修改時間,並以此排序。d 將目錄象檔案一樣顯示,而不是顯示其下的檔案。e 輸出時間的全部資訊,而不是輸出簡略資訊。f ...

linux ls 命令只顯示目錄和只顯示檔案

ls f grep bin build dir config dl docs feeds include package scripts staging dir target tmp toolchain tools ls al grep d drwxr xr x 17 cheng cheng 409...

linux顯示當前目錄命令

檢視當前路徑命令 pwd pwd命令能夠顯示當前所處的路徑。這個命令比較簡單,如果有時在操作過程中忘記了當前的路徑,則可以通過此命令來檢視路徑,其執行方式為 第一行為執行的命令,第二行的內容為執行pwd命令後顯示的資訊,即顯示使用者當前所在的工作目錄的路徑為 home samlee。應該經常使用pw...