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
Linux Operations: Utilizing the Maintenance ModeLinux Operations: Utilizing the Maintenance ModeApr 19, 2025 am 12:08 AM

Linux maintenance mode can be entered through the GRUB menu. The specific steps are: 1) Select the kernel in the GRUB menu and press 'e' to edit, 2) Add 'single' or '1' at the end of the 'linux' line, 3) Press Ctrl X to start. Maintenance mode provides a secure environment for tasks such as system repair, password reset and system upgrade.

Linux: How to Enter Recovery Mode (and Maintenance)Linux: How to Enter Recovery Mode (and Maintenance)Apr 18, 2025 am 12:05 AM

The steps to enter Linux recovery mode are: 1. Restart the system and press the specific key to enter the GRUB menu; 2. Select the option with (recoverymode); 3. Select the operation in the recovery mode menu, such as fsck or root. Recovery mode allows you to start the system in single-user mode, perform file system checks and repairs, edit configuration files, and other operations to help solve system problems.

Linux's Essential Components: Explained for BeginnersLinux's Essential Components: Explained for BeginnersApr 17, 2025 am 12:08 AM

The core components of Linux include the kernel, file system, shell and common tools. 1. The kernel manages hardware resources and provides basic services. 2. The file system organizes and stores data. 3. Shell is the interface for users to interact with the system. 4. Common tools help complete daily tasks.

Linux: A Look at Its Fundamental StructureLinux: A Look at Its Fundamental StructureApr 16, 2025 am 12:01 AM

The basic structure of Linux includes the kernel, file system, and shell. 1) Kernel management hardware resources and use uname-r to view the version. 2) The EXT4 file system supports large files and logs and is created using mkfs.ext4. 3) Shell provides command line interaction such as Bash, and lists files using ls-l.

Linux Operations: System Administration and MaintenanceLinux Operations: System Administration and MaintenanceApr 15, 2025 am 12:10 AM

The key steps in Linux system management and maintenance include: 1) Master the basic knowledge, such as file system structure and user management; 2) Carry out system monitoring and resource management, use top, htop and other tools; 3) Use system logs to troubleshoot, use journalctl and other tools; 4) Write automated scripts and task scheduling, use cron tools; 5) implement security management and protection, configure firewalls through iptables; 6) Carry out performance optimization and best practices, adjust kernel parameters and develop good habits.

Understanding Linux's Maintenance Mode: The EssentialsUnderstanding Linux's Maintenance Mode: The EssentialsApr 14, 2025 am 12:04 AM

Linux maintenance mode is entered by adding init=/bin/bash or single parameters at startup. 1. Enter maintenance mode: Edit the GRUB menu and add startup parameters. 2. Remount the file system to read and write mode: mount-oremount,rw/. 3. Repair the file system: Use the fsck command, such as fsck/dev/sda1. 4. Back up the data and operate with caution to avoid data loss.

How Debian improves Hadoop data processing speedHow Debian improves Hadoop data processing speedApr 13, 2025 am 11:54 AM

This article discusses how to improve Hadoop data processing efficiency on Debian systems. Optimization strategies cover hardware upgrades, operating system parameter adjustments, Hadoop configuration modifications, and the use of efficient algorithms and tools. 1. Hardware resource strengthening ensures that all nodes have consistent hardware configurations, especially paying attention to CPU, memory and network equipment performance. Choosing high-performance hardware components is essential to improve overall processing speed. 2. Operating system tunes file descriptors and network connections: Modify the /etc/security/limits.conf file to increase the upper limit of file descriptors and network connections allowed to be opened at the same time by the system. JVM parameter adjustment: Adjust in hadoop-env.sh file

How to learn Debian syslogHow to learn Debian syslogApr 13, 2025 am 11:51 AM

This guide will guide you to learn how to use Syslog in Debian systems. Syslog is a key service in Linux systems for logging system and application log messages. It helps administrators monitor and analyze system activity to quickly identify and resolve problems. 1. Basic knowledge of Syslog The core functions of Syslog include: centrally collecting and managing log messages; supporting multiple log output formats and target locations (such as files or networks); providing real-time log viewing and filtering functions. 2. Install and configure Syslog (using Rsyslog) The Debian system uses Rsyslog by default. You can install it with the following command: sudoaptupdatesud

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 Tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.