1. 程式人生 > >Centos中查詢目錄中內容命名ls

Centos中查詢目錄中內容命名ls

超級用戶 logs ges module cond 9.png img 文件信息 nac

技術分享

首先解釋下這塊, root代表當前登錄用戶,localhost代表主機名, ~代表當前主機目錄, #代表用戶權限 #表示超級用戶,$表示普通用戶;

查詢目錄中內容命令 ls (list縮寫)

格式 ls [選項] [文件或目錄]

選項:

-a 顯示所有文件,包括隱藏文件

-l 顯示詳細信息

-d 查看目錄屬性

-h 人性化顯示文件大小

-i 顯示inode

超級用戶root默認的當前目錄是 root目錄

我們可以用pwd命名(Print Working Directory 打印當前工作目錄)看到

技術分享

我們打印下當前目錄下文件信息:

[[email protected] ~]# ls

anaconda-ks.cfg

只有一個文件

假如我們要列出所有文件 用 ls -a 把隱藏文件也顯示出來

[[email protected] ~]# ls -a

. anaconda-ks.cfg .bash_logout .bashrc .tcshrc

.. .bash_history .bash_profile .cshrc

多了一些文件

我們也可以看其他目錄的文件:

[[email protected] ~]# ls /etc/

adjtime modprobe.d

aliases modules-load.d

aliases.db motd

alternatives mtab

anacrontab my.cnf

asound.conf my.cnf.d

audisp NetworkManager

audit networks

同樣也可以看具體某個文件

[[email protected] ~]# ls -l /etc/vconsole.conf

-rw-r--r--. 1 root root 37 6月 10 05:23 /etc/vconsole.conf

我們用 -l 或者 -la 組合 列出詳細信息;

[[email protected] ~]# ls -l

總用量 4

-rw-------. 1 root root 1237 6月 10 05:24 anaconda-ks.cfg

[[email protected] ~]# ls -la

總用量 24

dr-xr-x---. 2 root root 135 6月 11 21:13 .

dr-xr-xr-x. 17 root root 224 6月 10 05:23 ..

-rw-------. 1 root root 1237 6月 10 05:24 anaconda-ks.cfg

-rw-------. 1 root root 0 6月 11 21:13 .bash_history

-rw-r--r--. 1 root root 18 12月 29 2013 .bash_logout

-rw-r--r--. 1 root root 176 12月 29 2013 .bash_profile

-rw-r--r--. 1 root root 176 12月 29 2013 .bashrc

-rw-r--r--. 1 root root 100 12月 29 2013 .cshrc

-rw-r--r--. 1 root root 129 12月 29 2013 .tcshrc

[[email protected] ~]#

這裏第一列 比如 dr-xr-xr-x. 代表文件類型以及所有者,所屬組以及其他者權限

第一位d代表文件類型 常見的有 - 文件 d目錄 | 軟件鏈接文件

後面9位 每3位一個組 分別是 所有者u 所屬組g 以及 其他者o的權限

權限分三種 r讀 w寫 x執行

比如 dr-xr-xr-x 這個目錄 所有者 所屬組 以及其他者 都有 讀和執行權限;

比如 -rw------- 這個文件 所有者有讀寫權限 所屬組以及其他者沒有權限;

第二列 那個數字 是 硬鏈接次數 後面再說;

第三列 root 是 所有者;

第四列 root 是 所屬組;

第五列 是文件大小;假如看不慣 可用 ls -lh

[[email protected] ~]# ls -lh

總用量 4.0K

-rw-------. 1 root root 1.3K 6月 10 05:24 anaconda-ks.cfg

第六列的日期是該文件最後一次修改時間;

最後一列 是文件名稱;

查看目錄屬性 要加 -d

[[email protected] ~]# ls -ld /etc/

drwxr-xr-x. 78 root root 8192 6月 13 15:50 /etc/

[[email protected] ~]#

查看文件的inode屬性 類似 主鍵 唯一識別文件的Id 用 -i

[[email protected] ~]# ls -li

總用量 4

33574979 -rw-------. 1 root root 1237 6月 10 05:24 anaconda-ks.cfg

[[email protected] ~]#

33574979 就是inode屬性

Centos中查詢目錄中內容命名ls