胡思乱想的找自己
   
  我常在此处意淫!
 

昨日浏览

 
时 间 记 忆



站 内 搜 索

友 情 连 接
· 歪酷博客
· 管理我的Blog
· DEV365
· XiaoShen's BLOG
小宝看过&读过
订阅 RSS
0162090
歪酷博客
 
· 所有网志 · 胡说八不道 · 天天都要贱 · 每日淫意淫 · 日日都要唧 ·
 
« 上一篇: [书摘]别人和你说话你该怎么听 下一篇: [翻译]通过Unix命令行成为一个优秀的写作者 »
韦小宝 @ 2009-07-14 19:48

Unix LS Command: 15 Practical Examples
原文链接

无论是Unix用户还是Unix系统管理员都离不开LS命令,不管你是一天内使用10次还是100次,掌握LS命令对你在命令行下的旅程绝对是有意义的。

在这篇文章中,我们展示强大的LS命令15个实例。

1.显示最后一次编辑过的文件    ls -t

2.每行显示一个文件  ls -1

3.显示文件/目录的详细信息  ls-l

4.显示更易理解的文件大小样式  ls -lh

$ ls -l
-rw-r----- 1 ramesh team-dev 9275204 Jun 12 15:27 arch-linux.txt.gz*

$ ls -lh
-rw-r----- 1 ramesh team-dev 8.9M Jun 12 15:27 arch-linux.txt.gz


5.显示目录的信息 ls -ld
使用“ls -l”命令将得到目录所含内容的细节,但如果想显示文件夹的细节你可以使用-d选项,如下例子,使用 ls -l /etc 将显示所有在etc文件夹下的文档和目录。但是,如果你想要显示/etc/目录的信息,你就要使用 -ld命令
$ ls -l /etc
total 3344
-rw-r--r--   1 root root   15276 Oct  5  2004 a2ps.cfg
-rw-r--r--   1 root root    2562 Oct  5  2004 a2ps-site.cfg
drwxr-xr-x   4 root root    4096 Feb  2  2007 acpi
-rw-r--r--   1 root root      48 Feb  8  2008 adjtime
drwxr-xr-x   4 root root    4096 Feb  2  2007 alchemist

$ ls -ld /etc
drwxr-xr-x 21 root root 4096 Jun 15 07:02 /etc

6.根据文件最后使用时间进行排序 ls -lt
$ ls -lt
total 76
drwxrwxrwt  14 root root  4096 Jun 22 07:36 tmp
drwxr-xr-x 121 root root  4096 Jun 22 07:05 etc
drwxr-xr-x  13 root root 13780 Jun 22 07:04 dev
drwxr-xr-x  13 root root  4096 Jun 20 23:12 root
drwxr-xr-x  12 root root  4096 Jun 18 08:31 home
drwxr-xr-x   2 root root  4096 May 17 21:21 sbin
lrwxrwxrwx   1 root root    11 May 17 20:29 cdrom -> media/cdrom
drwx------   2 root root 16384 May 17 20:29 lost+found
drwxr-xr-x  15 root root  4096 Jul  2  2008 var


7.根据文件最后使用时间进行排序(逆序) ls -lt
$ ls -ltr

total 76
drwxr-xr-x  15 root root  4096 Jul  2  2008 var
drwx------   2 root root 16384 May 17 20:29 lost+found
lrwxrwxrwx   1 root root    11 May 17 20:29 cdrom -> media/cdrom
drwxr-xr-x   2 root root  4096 May 17 21:21 sbin
drwxr-xr-x  12 root root  4096 Jun 18 08:31 home
drwxr-xr-x  13 root root  4096 Jun 20 23:12 root
drwxr-xr-x  13 root root 13780 Jun 22 07:04 dev
drwxr-xr-x 121 root root  4096 Jun 22 07:05 etc
drwxrwxrwt  14 root root  4096 Jun 22 07:36 tmp


8.显示隐藏文件 ls-a 或 ls -A
在Unix中隐藏文件是以‘.’开头的
$ ls -a
[rnatarajan@asp-dev ~]$ ls -a
.                             Debian-Info.txt
..                            CentOS-Info.txt
.bash_history                 Fedora-Info.txt
.bash_logout                  .lftp
.bash_profile                 libiconv-1.11.tar.tar
.bashrc                       libssh2-0.12-1.2.el4.rf.i386.rpm

如果不想显示‘.’当前目录和'..'父目录可以使用选项 -A
$ ls -A
Debian-Info.txt               Fedora-Info.txt
CentOS-Info.txt               Red-Hat-Info.txt
.bash_history                 SUSE-Info.txt
.bash_logout                  .lftp
.bash_profile                 libiconv-1.11.tar.tar
.bashrc                       libssh2-0.12-1.2.el4.rf.i386.rpm
[Note: . and .. are not displayed here]


9.递归显示目录 ls -R
$ ls  /etc/sysconfig/networking
devices  profiles

$ ls  -R /etc/sysconfig/networking
/etc/sysconfig/networking:
devices  profiles

/etc/sysconfig/networking/devices:

/etc/sysconfig/networking/profiles:
default

/etc/sysconfig/networking/profiles/default:


如用此命令显示/ ,将不会显示隐藏文件

10.显示文件索引号 ls -i
$ ls -i /etc/xinetd.d/
279694 chargen      279724 cups-lpd  279697 daytime-udp
279695 chargen-udp  279696 daytime   279698 echo


11.隐藏控制字符 ls -q

12.显示文件的UID和GID ls -n

$ ls -l ~/.bash_profile
-rw-r--r--  1 ramesh ramesh 909 Feb  8 11:48 /home/ramesh/.bash_profile
$ ls -n ~/.bash_profile
-rw-r--r--  1 511 511 909 Feb  8 11:48 /home/ramesh/.bash_profile


13.利用特殊字符直观显示文档 ls -F
$ ls -F
Desktop/  Documents/  Ubuntu-App@  firstfile  Music/  Public/  Templates/


    *  / – 目录.
    * 无显示 – 正常文件.
    * @ – 链接文件.
    * * – 可执行文件

14.色彩分辨文件 ls --color=auto
目录显示蓝色,软链接显示绿色,普通文件显示默认颜色

15.有用的ls别名
*  直观显示文件大小.

alias ll="ls -lh"

* 特殊字符直观显示文档.

alias lv="ls -F"

* 特殊字符直观显示文档并进行色彩分辨.

alias ls="ls -F --color=auto"


曾经的这一天...



评论 / 个人网页 / 扔小纸条
*昵称

已经注册过? 请登录

Email
网址
*评论