ls command is the most commonly used command under Linux. The ls command is the abbreviation of list. By default, ls is used to print out the list of the current directory. If ls specifies another directory, the list of files and folders in the specified directory will be displayed. Through the ls command, you can not only view the files contained in the Linux folder, but also view file permissions (including directory, folder, file permissions), view directory information, and so on. The ls command is used a lot in daily Linux operations!
1. Command format:
ls [option] [directory name]
2 . Command function:
List all subdirectories and files in the target directory.
3. Commonly used parameters :
-a, –all lists all files in the directory, including implicit files starting with .
-a Same as -a, but do not list "." (indicating the current directory) and ".." (indicating the parent directory of the current directory).
-c With -lt: Sort by ctime and display ctime (the time when the file status was last changed) With -l: Display ctime but sort by name Otherwise: Sort by ctime
-c Each column is listed from top to bottom Item
–color[=when] Controls whether color resolution files are used. when can be one of 'never', 'always' or 'auto'
-d, –directory will display the directory as a file, rather than displaying the files below it.
-d, –dired produces results suitable for the dired mode of emacs
-f does not sort the output files, the -au option takes effect, and the -lst option fails
-g is similar to -l, but does not List owners
-g, –no-group Do not list any information about groups
-h, –human-readable List file sizes in an easy-to-understand format (e.g. 1k 234m 2g)
–si Like -h, but the file size is taken to the power of 1000 instead of 1024
-h, –dereference-command-line uses the real destination
–indicator-style= method indicated by the symbolic link in the command line Specify the indicator symbol
-i, –inode prints the inode of each file No.
-i, –ignore=style does not print out any items that match the shell wildcard character
4. Common examples:
Example 1: List the details of all files and directories under the /home/peidachang folder
Command:ls -l -r /home/peidachang
Be careful when using the ls command The format of the command: after the command prompt, first is the keyword of the command, followed by the command parameters. There should be a dash "-" before the command parameters. All command parameters have specific functions. You can customize them according to your needs. Select one or more parameters. Following the command parameters is the operation object of the command. In the above command "ls -l -r /home/peidachang", "ls" is the command keyword, "-l -r" is the parameter, and "/home/peidachang" is the operation object of the command. In this command, two parameters are used, namely "l" and "r". Of course, you can also use them together, as shown below:
Command: ls -lr /home/peidachang
The execution result of this form is exactly the same as the above command form. In addition, if the operation object of the command is located in the current directory, you can directly operate the operation object; if it is not in the current directory, you need to give the full path of the operation object. For example, in the above example, my current folder is the peidachang folder. I want to operate the peidachang file in the home folder. I can directly enter ls -lr peidachang, or I can use ls -lr /home/peidachang.
Example 2: To list the detailed contents of all directories starting with "t" in the current directory, you can use the following command:
Command: ls -l t*
You can view information about all files in the current directory whose file names begin with "t". In fact, in the command format, the content within the square brackets can be omitted. For the command ls, if the command parameters and operation objects are omitted and "ls" is entered directly, the contents of the current working directory will be listed.
Example 3: List only the subdirectories under the file
Command: ls -f /opt/soft |grep /$
List Subdirectory under the /opt/soft file
Output:
[root@localhost opt]# ls -f /opt/soft |grep /$
jdk1.6.0_16/
subversion-1.6. 1/
tomcat6.0.32/
Command: ls -l /opt/soft | grep "^d"
List the subdirectories under the /opt/soft file Details
Output:
[root@localhost opt]# ls -l /opt/soft | grep "^d"
drwxr-xr-x 10 root root 4096 09-17 18:17 jdk1. 6.0_16
drwxr-xr-x 16 1016 1016 4096 10-11 03:25 subversion-1.6.1
drwxr-xr-x 9 root root 4096 2011-11-01 tomcat6.0.32
Example 4: List all files in the current working directory whose names begin with s. After the newer ones, you can use the following command:
Command: ls -ltr s*
Output:
[root@localhost opt]# ls -ltr s*
src:
Total 0
script:
Total 0
soft:
Total 350644
drwxr-xr-x 9 root root 4096 2011-11-01 tomcat6.0.32
-rwxr-xr-x 1 root root 81871260 09-17 18:15 jdk-6u16-linux-x64.bin
drwxr-xr-x 10 root root 4096 09-17 18:17 jdk1.6.0_16
-rw-r--r-- 1 root root 205831281 09-17 18:33 apache-tomcat-6.0.32.tar .gz
-rw-r--r-- 1 root root 5457684 09-21 00:23 tomcat6.0.32.tar.gz
-rw-r--r-- 1 root root 4726179 10-10 11:08 subversion-deps-1.6.1.tar.gz
-rw-r--r-- 1 root root 7501026 10-10 11:08 subversion-1.6.1.tar.gz
drwxr- xr-x 16 1016 1016 4096 10-11 03:25 subversion-1.6.1
Example 5: List all files and directories in the current working directory; add "/" after the directory name, executable file Add "*"
to the name. Command: ls -af
Output:
[root@localhost opt]# ls -af
log/ script/ soft / src/ svndata/ web/
Example 6: Calculate the number of files and directories in the current directory
Command:
ls -l * |grep "^-" |wc -l ---Number of files
ls -l * |grep "^d"|wc -l ---Number of directories
Example 7: List in ls Absolute path to the file
Command: ls | sed "s:^:`pwd`/:"
Output:
[root@localhost opt]# ls | sed "s:^:`pwd`/:"
/opt/log
/opt/script
/opt/soft
/opt/src
/opt/svndata
/ opt/web
Example 8: List the absolute paths of all files (including hidden files) in the current directory, without recursion on the directory
Command: find $pwd -maxdepth 1 | xargs ls -ld
Output:
[root@localhost opt]# find $pwd -maxdepth 1 | xargs ls -ld
drwxr-xr-x 8 root root 4096 10-11 03:43 /opt
drwxr-xr-x 2 root root 4096 2012-03-08 /opt/log
drwxr-xr-x 2 root root 4096 2012-03-08 /opt/script
drwxr-xr -x 5 root root 4096 10-11 03:21 /opt/soft
drwxr-xr-x 2 root root 4096 2012-03-08 /opt/src
drwxr-xr-x 4 root root 4096 10 -11 05:22 /opt/svndata
drwxr-xr-x 4 root root 4096 10-09 00:45 /opt/web
Example 9: Recursively list all files in the current directory ( Absolute path including hidden files)
Command: find $pwd | xargs ls -ld
Example 10: Specify file time output format
Command :
ls -tl --time-style=full-iso
Output:
[root@localhost soft]# ls -tl --time-style=full-iso
Total 350644
drwxr-xr-x 16 1016 1016 4096 2012-10-11 03:25:58.000000000 0800 subversion-1.6.1
ls -ctl --time-style=long-iso
Output:
[root@localhost soft]# ls -ctl --time-style=long-iso
Total 350644
drwxr-xr-x 16 1016 1016 4096 2012-10-11 03 :25 subversion-1.6.1
Extension:
1. Display color directory list
Open /etc/bashrc and add the following line:
alias ls="ls --color"
The next time you start bash, you can display a colored directory list like in slackware. The meaning of the color is as follows:
1. Blue--> Directory
2. Green-->Executable file
3. Red-->Compressed file
4. Light blue-->Linked file
5. Gray--> Other files
The above is the detailed content of How to use the linux ls command. For more information, please follow other related articles on the PHP Chinese website!

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.

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.

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.

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.

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

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

When choosing a Hadoop version suitable for Debian system, the following key factors need to be considered: 1. Stability and long-term support: For users who pursue stability and security, it is recommended to choose a Debian stable version, such as Debian11 (Bullseye). This version has been fully tested and has a support cycle of up to five years, which can ensure the stable operation of the system. 2. Package update speed: If you need to use the latest Hadoop features and features, you can consider Debian's unstable version (Sid). However, it should be noted that unstable versions may have compatibility issues and stability risks. 3. Community support and resources: Debian has huge community support, which can provide rich documentation and

This article describes how to use TigerVNC to share files on Debian systems. You need to install the TigerVNC server first and then configure it. 1. Install the TigerVNC server and open the terminal. Update the software package list: sudoaptupdate to install TigerVNC server: sudoaptinstalltigervnc-standalone-servertigervnc-common 2. Configure TigerVNC server to set VNC server password: vncpasswd Start VNC server: vncserver:1-localhostno


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Zend Studio 13.0.1
Powerful PHP integrated development environment

SublimeText3 English version
Recommended: Win version, supports code prompts!

Dreamweaver CS6
Visual web development tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft