Detailed explanation of examples of ls command in Linux

黄舟
Release: 2017-09-29 11:24:54
Original
1735 people have browsed it

ls command is the most commonly used command under Linux. The ls command is the abbreviation of list. Let’s share with you the detailed explanation of the ls command in Linux through this article. Friends who are interested should take a look.

ls command is used to display the target list. It is a highly used command in Linux. . The output information of the ls command can be displayed with color highlighting to partition different types of files.

Syntax


ls(选项)(参数)
Copy after login

Options


-a:显示所有档案及目录(ls内定将档案名或目录名称为“.”的视为影藏,不会列出);
-A:显示除影藏文件“.”和“..”以外的所有文件列表;
-C:多列显示输出结果。这是默认选项;
-l:与“-C”选项功能相反,所有输出信息用单列格式输出,不输出为多列;
-F:在每个输出项后追加文件的类型标识符,具体含义:“*”表示具有可执行权限的普通文件,“/”表示目录,“@”表示符号链接,“|”表示命令管道FIFO,“=”表示sockets套接字。当文件为普通文件时,不输出任何标识符;
-b:将文件中的不可输出的字符以反斜线“”加字符编码的方式输出;
-c:与“-lt”选项连用时,按照文件状态时间排序输出目录内容,排序的依据是文件的索引节点中的ctime字段。与“-l”选项连用时,则排序的一句是文件的状态改变时间;
-d:仅显示目录名,而不显示目录下的内容列表。显示符号链接文件本身,而不显示其所指向的目录列表;
-f:此参数的效果和同时指定“aU”参数相同,并关闭“lst”参数的效果;
-i:显示文件索引节点号(inode)。一个索引节点代表一个文件;
--<span class=&#39;wp_keywordlink&#39;><a href="http://man.linuxde.net/file" rel="external nofollow" title="file命令" target="_blank">file</a></span>-<span class=&#39;wp_keywordlink&#39;><a href="http://man.linuxde.net/type" rel="external nofollow" title="type命令" target="_blank">type</a></span>:与“-F”选项的功能相同,但是不显示“*”;
-k:以KB(千字节)为单位显示文件大小;
-l:以长格式显示目录下的内容列表。输出的信息从左到右依次包括文件名,文件类型、权限模式、硬连接数、所有者、组、文件大小和文件的最后修改时间等;
-m:用“,”号区隔每个文件和目录的名称;
-n:以用户识别码和群组识别码替代其名称;
-r:以文件名反序排列并输出目录内容列表;
-s:显示文件和目录的大小,以区块为单位;
-t:用文件和目录的更改时间排序;
-L:如果遇到性质为符号链接的文件或目录,直接列出该链接所指向的原始文件或目录;
-R:递归处理,将指定目录下的所有文件及子目录一并处理;
--full-<span class=&#39;wp_keywordlink&#39;><a href="http://man.linuxde.net/time" rel="external nofollow" title="time命令" target="_blank">time</a></span>:列出完整的日期与时间;
--color[=WHEN]:使用不同的颜色高亮显示不同类型的。
Copy after login

Parameters

Directory: Specify the directory to display the list, or it can be a specific file.

Example

Display non-shadow files and directories in the current directory


[root@localhost ~]# lsanaconda-ks.cfg install.log install.log.syslog satools
Copy after login

Display the current List of all files in the directory including shadow files


[root@localhost ~]# ls -a
.  anaconda-ks.cfg .bash_logout  .bashrc install.log     
.mysql_history <span style="color:#0000cd;">satools</span> 
.tcshrc  
.vimrc
.. .bash_history  
.bash_profile 

.cshrc  install.log.syslog .rnd      
.<span class=&#39;wp_keywordlink&#39;>
<a href="http://man.linuxde.net/ssh" rel="external nofollow" title="ssh命令" target="_blank">ssh</a></span>   
.viminfo
Copy after login

Output long format list


[root@localhost ~]# ls -1anaconda-ks.cfginstall.loginstall.log.syslogsatools
Copy after login

Display files Inode information

Index inode (index inode is referred to as "inode") is a special concept in Linux. Two texts with the same inode number are essentially the same file (except for the different file names) ).


[root@localhost ~]# ls -i -l anaconda-ks.cfg install.log
2345481 -rw------- 1 root root  859 Jun 11 22:49 anaconda-ks.cfg
2345474 -rw-r--r-- 1 root root 13837 Jun 11 22:49 install.log
Copy after login

Horizontal output file list


[root@localhost /]# ls -m
bin, boot, data, dev, etc, home, lib, lost+found, media, misc, mnt, opt, proc, root, sbin, selinux, srv, sys, tmp, usr, var
Copy after login

Modify the last edited file

Recently modified The files are displayed at the top.


[root@localhost /]# ls -ttmp root 
etc dev lib boot s
ys proc data home bin sbin 
usr var lost+found 
media mnt 
opt selinux srv misc
Copy after login

Display recursive files


[root@localhost ~]# 
ls -R.:anaconda-ks.cfg 
install.log 
install.log.syslog 
satools./satools:black.txt freemem.sh 
iptables.sh 
lnmp.sh mysql 
php502_check.sh 
ssh_safe.sh
Copy after login

Print the UID and GID of the file


[root@localhost /]# ls -ntotal 254drwxr-xr-x  
2 0 0 4096 Jun 12 04:03 bindrwxr-xr-x  
4 0 0 1024 Jun 15 14:45 bootdrwxr-xr-x  
6 0 0 4096 Jun 12 10:26 datadrwxr-xr-x 
10 0 0 3520 Sep 26 15:38 devdrwxr-xr-x 
75 0 0 4096 Oct 16 04:02 etcdrwxr-xr-x 
 4 0 0 4096 Jun 12 10:26 homedrwxr-xr-x 
14 0 0 12288 Jun 16 04:02 libdrwx------ 
 2 0 0 16384 Jun 11 22:46 lost+founddrwxr-xr-x 
 2 0 0 4096 May 11 2011 mediadrwxr-xr-x  
2 0 0 4096 Nov 8 2010 miscdrwxr-xr-x 
 2 0 0 4096 May 11 2011 mntdrwxr-xr-x 
 2 0 0 4096 May 11 2011 optdr-xr-xr-x 
232 0 0   0 Jun 15 11:04 procdrwxr-x---  
4 0 0 4096 Oct 15 14:43 rootdrwxr-xr-x  
2 0 0 12288 Jun 12 04:03 sbindrwxr-xr-x  
2 0 0 4096 May 11 2011 selinuxdrwxr-xr-x  
2 0 0 4096 May 11 2011 srvdrwxr-xr-x 
11 0 0  
 0 Jun 15 11:04 sysdrwxrwxrwt  
3 0 0 98304 Oct 16 08:45 tmpdrwxr-xr-x 
13 0 0 4096 Jun 11 23:38 usrdrwxr-xr-x 
 19 0 0 4096 Jun 11 23:38 var
Copy after login

List file and folder details


[root@localhost /]# ls -ltotal 254drwxr-xr-x  
2 root root 4096 Jun 12 04:03 bindrwxr-xr-x 
 4 root root 1024 Jun 15 14:45 bootdrwxr-xr-x 
 6 root root 4096 Jun 12 10:26 datadrwxr-xr-x 
10 root root 3520 Sep 26 15:38 devdrwxr-xr-x 
75 root root 4096 Oct 16 04:02 etcdrwxr-xr-x  
4 root root 4096 Jun 12 10:26 homedrwxr-xr-x 
14 root root 12288 Jun 16 04:02 libdrwx------ 
 2 root root 16384 Jun 11 22:46 lost+founddrwxr-xr-x  2 root root 4096 May 11 2011 mediadrwxr-xr-x  2 root root 4096 Nov 8 2010 miscdrwxr-xr-x 
 2 root root 4096 May 11 2011 mntdrwxr-xr-x 
 2 root root 4096 May 11 2011 optdr-xr-xr-x 
232 root root   0 Jun 15 11:04 procdrwxr-x--- 
 4 root root 4096 Oct 15 14:43 rootdrwxr-xr-x 
 2 root root 12288 Jun 12 04:03 sbindrwxr-xr-x 
 2 root root 4096 May 11 2011 selinuxdrwxr-xr-x  2 root root 4096 May 11 2011 srvdrwxr-xr-x 
 11 root root   0 Jun 15 11:04 sysdrwxrwxrwt 
 3 root root 98304 Oct 16 08:48 tmpdrwxr-xr-x 
13 root root 4096 Jun 11 23:38 usrdrwxr-xr-x 
 19 root root 4096 Jun 11 23:38 var
Copy after login

List readable file and folder details


[root@localhost /]# ls -lhtotal 254Kdrwxr-xr-x 
 2 root root 4.0K Jun 12 04:03 bindrwxr-xr-x 
 4 root root 1.0K Jun 15 14:45 bootdrwxr-xr-x 
 6 root root 4.0K Jun 12 10:26 datadrwxr-xr-x
 10 root root 3.5K Sep 26 15:38 devdrwxr-xr-x 
 75 root root 4.0K Oct 16 04:02 etcdrwxr-xr-x 
 4 root root 4.0K Jun 12 10:26 homedrwxr-xr-x 
14 root root 12K Jun 16 04:02 libdrwx------ 
 2 root root 16K Jun 11 22:46 lost+founddrwxr-xr-x  2 root root 4.0K May 11 2011 mediadrwxr-xr-x  2 root root 4.0K Nov 8 2010 miscdrwxr-xr-x 
 2 root root 4.0K May 11 2011 mntdrwxr-xr-x 
 2 root root 4.0K May 11 2011 optdr-xr-xr-x 
235 root root  0 Jun 15 11:04 procdrwxr-x--- 
 4 root root 4.0K Oct 15 14:43 rootdrwxr-xr-x  
2 root root 12K Jun 12 04:03 sbindrwxr-xr-x  
2 root root 4.0K May 11 2011 selinuxdrwxr-xr-x 
 2 root root 4.0K May 11 2011 srvdrwxr-xr-x
 11 root root  0 Jun 15 11:04 sysdrwxrwxrwt 
 3 root root 96K Oct 16 08:49 tmpdrwxr-xr-x 
13 root root 4.0K Jun 11 23:38 usrdrwxr-xr-x 
 19 root root 4.0K Jun 11 23:38 var
Copy after login

Show folder information


[root@localhost /]# ls -ld /etc/drwxr-xr-x 75 root root 4096 Oct 16 04:02 /etc/
Copy after login

List file and folder details by time


[root@localhost /]# ls -lttotal 254drwxrwxrwt 
 3 root root 98304 Oct 16 08:53 tmpdrwxr-xr-x 
 75 root root 4096 Oct 16 04:02 etcdrwxr-x--- 
 4 root root 4096 Oct 15 14:43 rootdrwxr-xr-x 
 10 root root 3520 Sep 26 15:38 devdrwxr-xr-x
 14 root root 12288 Jun 16 04:02 libdrwxr-xr-x
  4 root root 1024 Jun 15 14:45 bootdrwxr-xr-x
 11 root root   0 Jun 15 11:04 sysdr-xr-xr-x 
232 root root   0 Jun 15 11:04 procdrwxr-xr-x 
 6 root root 4096 Jun 12 10:26 datadrwxr-xr-x 
 4 root root 4096 Jun 12 10:26 homedrwxr-xr-x 
 2 root root 4096 Jun 12 04:03 bindrwxr-xr-x  
2 root root 12288 Jun 12 04:03 sbindrwxr-xr-x 
13 root root 4096 Jun 11 23:38 usrdrwxr-xr-x 
19 root root 4096 Jun 11 23:38 vardrwx------ 
 2 root root 16384 Jun 11 22:46 lost+founddrwxr-xr-x  2 root root 4096 May 11 2011 mediadrwxr-xr-x  2 root root 4096 May 11 2011 mntdrwxr-xr-x  
2 root root 4096 May 11 2011 optdrwxr-xr-x  
2 root root 4096 May 11 2011 selinuxdrwxr-xr-x
  2 root root 4096 May 11 2011 srvdrwxr-xr-x 
 2 root root 4096 Nov 8 2010 misc
Copy after login

List file and folder details by modification time


[root@localhost /]# ls -ltrtotal 254drwxr-xr-x 
 2 root root 4096 Nov 8 2010 miscdrwxr-xr-x 
 2 root root 4096 May 11 2011 srvdrwxr-xr-x  
2 root root 4096 May 11 2011 selinuxdrwxr-xr-x 
 2 root root 4096 May 11 2011 optdrwxr-xr-x  
2 root root 4096 May 11 2011 mntdrwxr-xr-x  
2 root root 4096 May 11 2011 mediadrwx------ 
 2 root root 16384 Jun 11 22:46 lost+founddrwxr-xr-x 19 root root 4096 Jun 11 23:38 vardrwxr-xr-x 
13 root root 4096 Jun 11 23:38 usrdrwxr-xr-x  
2 root root 12288 Jun 12 04:03 sbindrwxr-xr-x 
 2 root root 4096 Jun 12 04:03 bindrwxr-xr-x 
 4 root root 4096 Jun 12 10:26 homedrwxr-xr-x 
 6 root root 4096 Jun 12 10:26 datadr-xr-xr-x 
232 root root   0 Jun 15 11:04 procdrwxr-xr-x 
 11 root root   0 Jun 15 11:04 sysdrwxr-xr-x 
 4 root root 1024 Jun 15 14:45 bootdrwxr-xr-x 
14 root root 12288 Jun 16 04:02 libdrwxr-xr-x 
10 root root 3520 Sep 26 15:38 devdrwxr-x--- 
 4 root root 4096 Oct 15 14:43 rootdrwxr-xr-x
 75 root root 4096 Oct 16 04:02 etcdrwxrwxrwt
  3 root root 98304 Oct 16 08:54 tmp
Copy after login

Category files by special characters


[root@localhost nginx-1.2.1]# ls -Fauto/ CHANGES CHANGES.ru conf/ configure* contrib/ html/ LICENSE Makefile man/ objs/ README src/
Copy after login

List files and mark color categories


[root@localhost nginx-1.2.1]# ls --color=autoauto CHANGES CHANGES.ru conf configure 
contrib 
 html LICENSE Makefile man objs 
README src
Copy after login

Summary

The above is the detailed content of Detailed explanation of examples of ls command in Linux. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!