IT开放社区

ls命令详解--目录基本操作(一)

ls命令 

ls命令用来显示目标列表,是Linux中最常用的命令。

语法

ls [选项] [参数]
选项
      -l   列出当前目录文件属性信息
      -a  列出当前目录文件包括隐藏文件
      -d  显示当前目录属性
      -r   逆序显示当前目录文件
      -i   列出目录文件及索引节点号
      -R  递归显示当前目录文件
      -t   以文件修改时间排序
      -h  以更易读的文件大小单位(K、M等)显示文件大小,默认为B

参数

目录:指定要显示列表的目录,也可以是具体的文件。
实例

显示当前目录下非隐藏文件与目录

[root@itkaifang ~]# ls
anaconda-ks.cfg  Desktop  install.log  install.log.syslog

列出当前目录文件属性信息

[root@itkaifang ~]# ls -l 
total 60
-rw------- 1 root root  1146 Feb 21 20:34 anaconda-ks.cfg
drwxr-xr-x 2 root root  4096 Feb 25 19:14 Desktop
-rw-r--r-- 1 root root   38449 Feb 23 20:12 install.log
-rw-r--r-- 1 root root  3686 Feb 21 20:34 install.log.syslog

列出当前目录文件包括隐藏文件

[root@itkaifang ~]# ls -a
.                .bash_logout   .cshrc    .gconf   .gnome2_private    install.log         .recently-used.xbel  .viminfo
..               .bash_profile  Desktop   .gconfd  .gstreamer-0.10    install.log.syslog  .redhat              .xauthdNF63J
anaconda-ks.cfg  .bashrc        .dmrc     .gnome   .gtkrc-1.2-gnome2  .metacity           .tcshrc              .xauthWe630N
.bash_history    .config        .eggcups  .gnome2  .ICEauthority      .nautilus           .Trash

显示当前目录属性

[root@itkaifang ~]# ls -d
.

逆序显示当前目录文件

[root@itkaifang ~]# ls -r
install.log.syslog  install.log  Desktop  anaconda-ks.cfg

列出目录文件及索引节点号

[root@itkaifang ~]# ls -i
11675337 anaconda-ks.cfg  11675365 Desktop  11675407 install.log  11675331 install.log.syslog

递归显示当前目录文件

[root@itkaifang ~]# ls -R
.:
anaconda-ks.cfg  Desktop  install.log  install.log.syslog
./Desktop:

以文件修改时间排序

[root@itkaifang ~]# ls -t
Desktop  install.log  anaconda-ks.cfg  install.log.syslog

以更易读的文件大小单位(K、M等)显示文件大小,默认为B

[root@itkaifang ~]# ls -lh
total 60K
-rw------- 1 root root 1.2K Feb 21 20:34 anaconda-ks.cfg
drwxr-xr-x 2 root root 4.0K Feb 25 19:14 Desktop
-rw-r--r-- 1 root root  38K Feb 23 20:12 install.log
-rw-r--r-- 1 root root 3.6K Feb 21 20:34 install.log.syslog

扩展写法ll

[root@itkaifang ~]# ls -l 
total 60
-rw------- 1 root root  1146 Feb 21 20:34 anaconda-ks.cfg
drwxr-xr-x 2 root root  4096 Feb 25 19:14 Desktop
-rw-r--r-- 1 root root 38449 Feb 23 20:12 install.log
-rw-r--r-- 1 root root  3686 Feb 21 20:34 install.log.syslog
[root@itkaifang ~]# ll
total 60
-rw------- 1 root root  1146 Feb 21 20:34 anaconda-ks.cfg
drwxr-xr-x 2 root root  4096 Feb 25 19:14 Desktop
-rw-r--r-- 1 root root 38449 Feb 23 20:12 install.log
-rw-r--r-- 1 root root  3686 Feb 21 20:34 install.log.syslog
[root@itkaifang ~]# ll -h
total 60K
-rw------- 1 root root 1.2K Feb 21 20:34 anaconda-ks.cfg
drwxr-xr-x 2 root root 4.0K Feb 25 19:14 Desktop
-rw-r--r-- 1 root root  38K Feb 23 20:12 install.log
-rw-r--r-- 1 root root 3.6K Feb 21 20:34 install.log.syslog
[root@itkaifang ~]# ls -lh
total 60K
-rw------- 1 root root 1.2K Feb 21 20:34 anaconda-ks.cfg
drwxr-xr-x 2 root root 4.0K Feb 25 19:14 Desktop
-rw-r--r-- 1 root root  38K Feb 23 20:12 install.log
-rw-r--r-- 1 root root 3.6K Feb 21 20:34 install.log.syslog

组合选项及扩展使用方法:

1.列出当前目录文件属性及隐藏文件;

[root@itkaifang ~]# ls -al
total 216
drwxr-x--- 15 root root  4096 Feb 25 20:53 .
drwxr-xr-x 30 root root  4096 Feb 25 20:58 ..
-rw-------  1 root root  1146 Feb 21 20:34 anaconda-ks.cfg
-rw-------  1 root root 10066 Feb 25 21:03 .bash_history
-rw-r--r--  1 root root    24 Jun  7  2007 .bash_logout
-rw-r--r--  1 root root   191 Jun  7  2007 .bash_profile
-rw-r--r--  1 root root   176 Jun  7  2007 .bashrc

2.列出当前目录文件属性并逆序显示;

[root@itkaifang ~]# ls -lr
total 60
-rw-r--r-- 1 root root  3686 Feb 21 20:34 install.log.syslog
-rw-r--r-- 1 root root 38449 Feb 23 20:12 install.log
drwxr-xr-x 2 root root  4096 Feb 25 19:14 Desktop
-rw------- 1 root root  1146 Feb 21 20:34 anaconda-ks.cfg

3.列出当前目录文件属性、隐藏文件并逆序显示;

[root@itkaifang ~]# ls -alr
total 216
-rw-------  1 root root    55 Feb 23 10:56 .xauthWe630N
-rw-------  1 root root    55 Feb 22 18:49 .xauthdNF63J
-rw-------  1 root root  1394 Feb 23 20:12 .viminfo
drwx------  3 root root  4096 Feb 25 19:14 .Trash
-rw-r--r--  1 root root   129 Jun  7  2007 .tcshrc
drwxr-xr-x  3 root root  4096 Feb 21 14:09 .redhat

4.查看根目录文件

[root@itkaifang ~]# ls /
bin   dev  haha  lib    lost+found  lv-D   misc  net  proc  sbin     soft  sys       tmp  usr
boot  etc  home  lib64  lv-C        media  mnt   opt  root  selinux  srv   tftpboot  u01  var

5.查看根目录下的bin目录文件

[root@itkaifang ~]# ls /bin
alsacard    cut                   dumpkeys  gzip             login       nisdomainname    rview          tcsh           usleep
alsaunmute  date                  echo      hostname         ls          pgawk            sed            touch          vi

6.查看根目录下bin目录文件包括隐藏文件

[root@itkaifang ~]# ls -a /bin
.           cpio                  doexec      gtar      loadkeys.static  netstat          rpm        taskset        unicode_stop
..          csh                   domainname  gunzip    logger           nice             rvi        tcptraceroute  unlink


发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

网站分类
站点信息
  • 文章总数:119
  • 页面总数:2
  • 分类总数:3
  • 标签总数:12
  • 评论总数:2
  • 浏览总数:116129
友情链接

BlogPowerBy Z-BlogPHP 1.5 Zero ;Theme By 爱墙纸

Copyright © 2020-2030 ITkaifang.COM All Rights Reserved. 京ICP备13044647号.Email:dreamerqin@qq.com