学习Linux命令之:ls命令

ls命令是Linux最常用的命令之一。

ls解释:

   ls - list directory contents 列出目录内容

ls描述:

   按照字母排列的顺利列出文件的信息。

ls语法:

   ls [OPTION]... [FILE]...   =      ls 选项 目录名

        常用参数:

                    -a      列出目录里的全部文件(包括隐藏文件)

                    -l       以长格式列出文件

                   -d       目录条目列表,而不是内容,不要引用符号链接

                   -p       是为目录加上一个标识/

                   -F       为所有目录和文件加上标识(¥……*/ 等等)

        常用的参数就以上三个。还有很参数,可在在linux 中用 man ls 查询。

例1:列出root目录下的目录

[root@moban ~]# ls
aaa anaconda-ks.cfg bbb ccc install.log install.log.syslog

例2:以长格列出root目录下的目录

[root@moban ~]# ls -l
drwxr-xr-x. 2 root root 4096 Apr 5 15:16 aaa
-rw-------. 1 root root 1096 Apr 5 10:08 anaconda-ks.cfg
drwxr-xr-x. 2 root root 4096 Apr 5 15:23 bbb
drwxr-xr-x. 3 root root 4096 Apr 5 15:25 ccc
-rw-r--r--. 1 root root 23571 Apr 5 10:08 install.log
-rw-r--r--. 1 root root 6240 Apr 5 10:04 install.log.syslog

例3:以长格列出root目录下的所有目录

[root@moban ~]# ls -la
dr-xr-x---. 5 root root 4096 Apr 6 13:34 .
dr-xr-xr-x. 22 root root 4096 Apr 6 13:23 ..
drwxr-xr-x. 2 root root 4096 Apr 5 15:16 aaa
-rw-------. 1 root root 1096 Apr 5 10:08 anaconda-ks.cfg
-rw-------. 1 root root 1339 Apr 6 13:30 .bash_history
-rw-r--r--. 1 root root 18 May 20 2009 .bash_logout
-rw-r--r--. 1 root root 176 May 20 2009 .bash_profile
-rw-r--r--. 1 root root 176 Sep 23 2004 .bashrc
drwxr-xr-x. 2 root root 4096 Apr 5 15:23 bbb
drwxr-xr-x. 3 root root 4096 Apr 5 15:25 ccc
-rw-r--r--. 1 root root 100 Sep 23 2004 .cshrc
-rw-r--r--. 1 root root 23571 Apr 5 10:08 install.log
-rw-r--r--. 1 root root 6240 Apr 5 10:04 install.log.syslog
-rw-r--r--. 1 root root 129 Dec 4 2004 .tcshrc

例4:列出/etc/init.d 目录中的文件

[root@moban ~]# ls /etc/init.d
abrt-ccpp crond killall nfs-rdma restorecond svnserve
abrtd functions lvm2-lvmetad ntpd rngd sysstat
abrt-oops haldaemon lvm2-monitor ntpdate rsyslog udev-post
acpid halt mdmonitor postfix sandbox
atd ip6tables messagebus psacct saslauthd
auditd iptables netconsole quota_nld single
blk-availability irqbalance netfs rdisc smartd
cpuspeed kdump network rdma sshd

 

例:为/data目录里的目录加上标识

[root@moban data]# ls -lp
total 16
-rw-r--r--. 1 root root 7 Apr 11 13:33 a.txt
-rw-r--r--. 1 root root 9 Apr 11 13:34 b.txt
drwxr-xr-x. 2 root root 4096 Apr 11 13:17 test1.txt/
drwxr-xr-x. 2 root root 4096 Apr 11 13:17 test.txt/

 

例:为/data目录里的所有文件加上标识

[root@moban data]# ls -Fl
total 16
-rw-r--r--. 1 root root 7 Apr 11 13:33 a.txt
-rw-r--r--. 1 root root 9 Apr 11 13:34 b.txt
drwxr-xr-x. 2 root root 4096 Apr 11 13:17 test1.txt/
drwxr-xr-x. 2 root root 4096 Apr 11 13:17 test.txt/

 

posted @ 2016-04-06 16:20  单机才牛  阅读(174)  评论(0编辑  收藏  举报