search
HomeOperation and MaintenanceLinux Operation and MaintenanceDetailed explanation of examples of ls command in Linux

Detailed explanation of examples of ls command in Linux

Sep 29, 2017 am 11:24 AM
linuxExampleDetailed explanation

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(选项)(参数)

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]:使用不同的颜色高亮显示不同类型的。

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

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

Output long format list


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

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

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

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

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

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

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

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

Show folder information


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

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

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

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/

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

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!

Statement
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
The 5 Core Components of the Linux Operating SystemThe 5 Core Components of the Linux Operating SystemMay 08, 2025 am 12:08 AM

The five core components of the Linux operating system are: 1. Kernel, 2. System libraries, 3. System tools, 4. System services, 5. File system. These components work together to ensure the stable and efficient operation of the system, and together form a powerful and flexible operating system.

The 5 Essential Elements of Linux: ExplainedThe 5 Essential Elements of Linux: ExplainedMay 07, 2025 am 12:14 AM

The five core elements of Linux are: 1. Kernel, 2. Command line interface, 3. File system, 4. Package management, 5. Community and open source. Together, these elements define the nature and functionality of Linux.

Linux Operations: Security and User ManagementLinux Operations: Security and User ManagementMay 06, 2025 am 12:04 AM

Linux user management and security can be achieved through the following steps: 1. Create users and groups, using commands such as sudouseradd-m-gdevelopers-s/bin/bashjohn. 2. Bulkly create users and set password policies, using the for loop and chpasswd commands. 3. Check and fix common errors, home directory and shell settings. 4. Implement best practices such as strong cryptographic policies, regular audits and the principle of minimum authority. 5. Optimize performance, use sudo and adjust PAM module configuration. Through these methods, users can be effectively managed and system security can be improved.

Linux Operations: File System, Processes, and MoreLinux Operations: File System, Processes, and MoreMay 05, 2025 am 12:16 AM

The core operations of Linux file system and process management include file system management and process control. 1) File system operations include creating, deleting, copying and moving files or directories, using commands such as mkdir, rmdir, cp and mv. 2) Process management involves starting, monitoring and killing processes, using commands such as ./my_script.sh&, top and kill.

Linux Operations: Shell Scripting and AutomationLinux Operations: Shell Scripting and AutomationMay 04, 2025 am 12:15 AM

Shell scripts are powerful tools for automated execution of commands in Linux systems. 1) The shell script executes commands line by line through the interpreter to process variable substitution and conditional judgment. 2) The basic usage includes backup operations, such as using the tar command to back up the directory. 3) Advanced usage involves the use of functions and case statements to manage services. 4) Debugging skills include using set-x to enable debugging mode and set-e to exit when the command fails. 5) Performance optimization is recommended to avoid subshells, use arrays and optimization loops.

Linux Operations: Understanding the Core FunctionalityLinux Operations: Understanding the Core FunctionalityMay 03, 2025 am 12:09 AM

Linux is a Unix-based multi-user, multi-tasking operating system that emphasizes simplicity, modularity and openness. Its core functions include: file system: organized in a tree structure, supports multiple file systems such as ext4, XFS, Btrfs, and use df-T to view file system types. Process management: View the process through the ps command, manage the process using PID, involving priority settings and signal processing. Network configuration: Flexible setting of IP addresses and managing network services, and use sudoipaddradd to configure IP. These features are applied in real-life operations through basic commands and advanced script automation, improving efficiency and reducing errors.

Linux: Entering and Exiting Maintenance ModeLinux: Entering and Exiting Maintenance ModeMay 02, 2025 am 12:01 AM

The methods to enter Linux maintenance mode include: 1. Edit the GRUB configuration file, add "single" or "1" parameters and update the GRUB configuration; 2. Edit the startup parameters in the GRUB menu, add "single" or "1". Exit maintenance mode only requires restarting the system. With these steps, you can quickly enter maintenance mode when needed and exit safely, ensuring system stability and security.

Understanding Linux: The Core Components DefinedUnderstanding Linux: The Core Components DefinedMay 01, 2025 am 12:19 AM

The core components of Linux include kernel, shell, file system, process management and memory management. 1) Kernel management system resources, 2) shell provides user interaction interface, 3) file system supports multiple formats, 4) Process management is implemented through system calls such as fork, and 5) memory management uses virtual memory technology.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment