`
JackyCheng2007
  • 浏览: 249667 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

档案与目录的检视: ls

阅读更多
引用

档案与目录的检视: ls

在Linux系统当中,这个 ls 指令可能是最常被执行的吧!因为我们随时都要知道档案或者是目录的相关信息啊~ 不过,我们Linux的档案所记录的信息实在是太多了,ls 没有需要全部都列出来呢~ 所以,当你只有下达 ls 时,预设显示的只有:非隐藏档的档名、 以档名进行排序及档名代表的颜色显示如此而已。举例来说, 你下达『 ls /etc 』之后,只有经过排序的档名以及以蓝色显示目录及白色显示一般档案,如此而已。
那如果我还想要加入其它的显示信息时,可以加入上头提到的那些有用的选项呢~ 举例来说,我们之前一直用到的 -l 这个长串显示资料内容,以及将隐藏档也一起列示出来的 -a 选项等等。 底下则是一些常用的范例,实际试做看看:

范例一:将家目录下的所有档案列出来(含属性与隐藏文件)
[root@www ~]# ls -al ~
total 156
drwxr-x---  4 root root  4096 Sep 24 00:07 .
drwxr-xr-x 23 root root  4096 Sep 22 12:09 ..
-rw-------  1 root root  1474 Sep  4 18:27 anaconda-ks.cfg
-rw-------  1 root root   955 Sep 24 00:08 .bash_history
-rw-r--r--  1 root root    24 Jan  6  2007 .bash_logout
-rw-r--r--  1 root root   191 Jan  6  2007 .bash_profile
-rw-r--r--  1 root root   176 Jan  6  2007 .bashrc
drwx------  3 root root  4096 Sep  5 10:37 .gconf
-rw-r--r--  1 root root 42304 Sep  4 18:26 install.log
-rw-r--r--  1 root root  5661 Sep  4 18:25 install.log.syslog
# 这个时候你会看到以 . 为开头的几个档案,以及目录文件 (.) (..) .gconf 等等,
# 不过,目录文件文件名都是以深蓝色显示,有点不容易看清楚就是了。

范例二:承上题,不显示颜色,但在档名末显示出该档名代表的类型(type)

[root@www ~]# ls -alF --color=never  ~
total 156
drwxr-x---  4 root root  4096 Sep 24 00:07 ./
drwxr-xr-x 23 root root  4096 Sep 22 12:09 ../
-rw-------  1 root root  1474 Sep  4 18:27 anaconda-ks.cfg
-rw-------  1 root root   955 Sep 24 00:08 .bash_history
-rw-r--r--  1 root root    24 Jan  6  2007 .bash_logout
-rw-r--r--  1 root root   191 Jan  6  2007 .bash_profile
-rw-r--r--  1 root root   176 Jan  6  2007 .bashrc
drwx------  3 root root  4096 Sep  5 10:37 .gconf/
-rw-r--r--  1 root root 42304 Sep  4 18:26 install.log
-rw-r--r--  1 root root  5661 Sep  4 18:25 install.log.syslog
# 注意看到显示结果的第一行,嘿嘿~知道为何我们会下达类似 ./command
# 之类的指令了吧?因为 ./ 代表的是『目前目录下』的意思啊!至于什么是 FIFO/Socket ?
# 请参考前一章节的介绍啊!另外,那个.bashrc 时间仅写2007,能否知道详细时间?

范例三:完整的呈现档案的修改时间 *(modification time)

[root@www ~]# ls -al --full-time  ~
total 156
drwxr-x---  4 root root  4096 2008-09-24 00:07:00.000000 +0800 .
drwxr-xr-x 23 root root  4096 2008-09-22 12:09:32.000000 +0800 ..
-rw-------  1 root root  1474 2008-09-04 18:27:10.000000 +0800 anaconda-ks.cfg
-rw-------  1 root root   955 2008-09-24 00:08:14.000000 +0800 .bash_history
-rw-r--r--  1 root root    24 2007-01-06 17:05:04.000000 +0800 .bash_logout
-rw-r--r--  1 root root   191 2007-01-06 17:05:04.000000 +0800 .bash_profile
-rw-r--r--  1 root root   176 2007-01-06 17:05:04.000000 +0800 .bashrc
drwx------  3 root root  4096 2008-09-05 10:37:49.000000 +0800 .gconf
-rw-r--r--  1 root root 42304 2008-09-04 18:26:57.000000 +0800 install.log
-rw-r--r--  1 root root  5661 2008-09-04 18:25:55.000000 +0800 install.log.syslog
# 请仔细看,上面的『时间』字段变了喔!变成较为完整的格式。
# 一般来说, ls -al 仅列出目前短格式的时间,有时不会列出年份,
# 藉由 --full-time 可以查阅到比较正确的完整时间格式啊!
其实 ls 的用法还有很多,包括查阅档案所在 i-node 号码的 ls -i 选项,以及用来进行档案排序的 -S 选项,还有用来查阅不同时间的动作的 --time=atime 等选项(更多时间说明请参考本章后面touch的说明)。而这些选项的存在都是因为 Linux 档案系统记录了很多有用的信息的缘故。那么 Linux 的档案系统中,这些与权限、属性有关的数据放在哪里呢? 放在 i-node 里面。关于这部分,我们会在下一章继续为你作比较深入的介绍啊!
无论如何, ls 最常被使用到的功能还是那个 -l 的选项,为此,很多 distribution 在预设的情况中, 已经将 ll (L 的小写) 设定成为 ls -l 的意思了!其实,那个功能是 Bash shell 的 alias 功能呢~也就是说,我们直接输入 ll 就等于是输入 ls -l 是一样的~关于这部分,我们会在后续 bash shell 时再次的强调滴~


分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics