Use of Linux ls command

Use of Linux ls command

1. Introduction

The ls command is used to display the contents of a directory and is a frequently used command in Linux. The output of the ls command can be highlighted in color to separate different types of files.

2. Command format

ls [OPTION]... [FILE]...

3. Option Description

-a, --all: Display all files and directories (ls considers files or directories whose names begin with "." as hidden files and will not list them by default); 
-A, --almost-all: Displays a list of all files except the hidden files "." and ".."; 
--author: Used in conjunction with the -l option, print out the author of each file;
-b, --escape: Output the non-printable characters in the file in the form of backslash “\” plus character encoding;
--block-size=SIZE: Use the specified SIZE as the unit for statistical file size. SIZE can take the following strings or corresponding values: KB 1000, K 1024, MB 1000*1000, M 1024*1024, as well as G, T, P, E, Z, Y, etc.;
-B, --ignore-backups: Do not list implicit entries ending with ~, listed by default;
-c: When used with the "-l" option, display ctime; when used with the "-lt" option, the output is sorted by the time the file status changed, and the sorting is based on the ctime field in the file's inode;
-C: Display output results in multiple columns. This is the default option; 
--color[=WHEN]: Use different colors to highlight different types of files. The default value of WHEN is 'always', which can also be 'never' or 'auto';
-d, --directory: Display only the directory name, not the directory contents list. Display the symbolic link file itself, not the directory or file it points to; 
-D, --dired: Output in Emacs's dired mode;
-f: This parameter has the same effect as specifying the "aU" parameter at the same time, and turns off the effect of the "-ls --color" parameter; 
-F, --classify: Append the file type identifier after each output item. The specific meaning is: "*" represents a regular file with executable permission, "/" represents a directory, "@" represents a symbolic link, "|" represents a command pipe FIFO, and "=" represents a socket. When the file is a normal file, no identifier is output; 
--file-type: Same as the "-F" option, but "*" is not displayed; 
--format=WORD: The value of WORD is across, which is equivalent to the -x option. The value is commas, which is equivalent to -m. The value is horizontal, which is equivalent to -x. The value is long, equivalent to -l. The value is single-column, which is equivalent to -1. The value is verbose, which is equivalent to -l. The value is vertical, which is equivalent to -C;
--full-time: List the full date and time;
-g: Similar to -l, but does not list the owner;
--group-directories-first: Directories are listed before files;
-G, --no-group: Do not output group name when outputting in long format (-l);
-h, --human-readable: Display file size in human-readable format;
--si: Calculate the file size as 1000 instead of 1024;
-H, --dereference-command-line: Use the real destination indicated by the symbolic link in the command line;
--dereference-command-line-symlink-to-dir: Follow symbolic links listed on the command line;
--hide=PATTERN: Do not list hidden files that match the PATTERN model;
--indicator-style=WORD: Append indicator WORD to each file or directory name, none defaults to slash (-p), file-type (--file-type), classify (-F);
-i, --inode: Display the file index node number (inode). An inode represents a file; 
-I, --ignore=PATTERN: Do not list files or directory names matching PATTERN;
-k: Display file size in KB (kilobytes), similar to --block-size=1K;
-1: Number 1, opposite to the "-C" option function, all output information is output in a single column format, not in multiple columns;
-l: Display the directory contents list in long format. The output information includes file name, file type, permission mode, number of hard links, owner, group, file size and the last modification time of the file from left to right; 
-L, --dereference: If a file or directory that is a symbolic link is encountered, directly list the original file or directory pointed to by the link; 
-m: Use “,” to separate the names of each file and directory; 
-n: Replace the name with the user ID and group ID; 
-N, --literal: List file and directory names directly, including control characters;
-o: This parameter has a similar effect to "-l", but does not list user group information;
-p, --indicator-style=slash: Append slash/indicator to directory names;
-q, --hide-control-chars: Replace control characters with "?" and list file and directory names;
--show-control-chars: Display control characters in file and directory names;
-Q, --quote-name: Enclose file and directory names in double quotes "".
--quoting-style=WORD: Use the specified quotation mark pattern to identify the file name. The values ​​of WORD are: literal, locale, shell, shell-always, c, escape;
-r, --reverse: Output directory contents in reverse order of file names;
-R, --recursive: recursive processing, all files and subdirectories under the specified directory will be processed together; 
-s, --size: Display the size of files and directories in blocks; 
-S: Sort by file size;
--sort=WORD: Sort by the specified content instead of the default file name. The possible values ​​of WORD are: none (no sorting, equal to -U); extension (sort by the last extension of the entry name, equal to -X); size (sort by the size of the entry, equal to -S); time (sort by the last modification time of the entry content, equal to -t); version (sort by the entry version, equal to -v);
--time=WORD: When using -t or --sort=time to sort by time, the WORD value can be atime, access, use (indicates sorting by access time); or ctime, status (sorting by status change time), to replace the default sorting by content modification time;
--time-style=STYLE: When using the -l option, the time is displayed using the specified style STYLE. The possible values ​​are full-iso, long-iso, iso, locale, and +FORMAT, FORMAT. For the setting formats of these two items, please refer to the setting methods of the date command;
-t: Sort by the modification time of the files and directories; 
-T, --tabsize=COLS: Set the width of the tab separator between each column to COLS, the default is 8 spaces;
-u: used with -lt, it indicates sorting by access time. Used with -l, it displays access time instead of content modification time.
-U: Do not sort when listing file and directory names;
-v: The list of file and directory names is sorted by version;
-w, --width=COLS: Set the maximum number of characters per column to COLS;
-x: Display file and directory names in horizontal columns from left to right and from top to bottom;
-X: Sort by the last extension of files and directories;
--help: Display help information;
--version: Display version information;

4. Common Examples

(1) The ls command sorts in descending order by modification date

ls -t

If you want to increment by modification date, just use ls -rt .

(2) The ls command sorts files in descending order of size.

# Descending sort ls -hS

# Increasing sort ls -hrS

(3) Display hidden files, including the current directory and parent directories.

[dablelv@TENCENT64 ~]$ ll -a
total 148
drwxr-x--- 8 dablelv dablelv 4096 Nov 23 23:56 .
drwxr-xr-x 22 root root 4096 Jun 7 15:15 ..
-rw------- 1 dablelv dablelv 71812 Nov 24 00:38 .bash_history
-rw-r--r-- 1 dablelv dablelv 2153 May 2 2017 .bash_profile
-rw------- 1 dablelv dablelv 595 Nov 24 16:57 .lesshst
drwx------ 2 dablelv dablelv 4096 Jul 23 20:42 .ssh

ll is actually an alias of ls -l . You can use the alias command to view related commands.

[dablelv@TENCENT64 ~]$ alias
alias l.='ls -d .* --color=auto'
alias ll='ls -l --color=auto'
alias ls='ls --color=auto'
alias vi='vim'
alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'

(4) Display in the specified file size type.

[dablelv@TENCENT64 ~]$ ll --block-size=K
total 24K
drwxrwxr-x 10 dablelv dablelv 4K Nov 21 15:08 code_root
-rwxrwxr-x 1 dablelv dablelv 1K Nov 21 00:18 dable.php
-rw-rw-r-- 1 dablelv dablelv 1K Nov 21 00:18 dablelala.php
-rw-rw-r-- 1 dablelv dablelv 0K Nov 23 23:56 dablelv~
-rw-rw-r-- 1 dablelv dablelv 1K Nov 21 00:40 dablenewnew
drwxrwxrwx 2 dablelv dablelv 4K Nov 21 00:29 new
drwxrwxr-x 6 dablelv dablelv 4K Nov 21 00:24 test

The above is the detailed content of the use of Linux ls command. For more information about Linux ls command, please pay attention to other related articles on 123WORDPRESS.COM!

You may also be interested in:
  • Use of Linux gzip command
  • Usage of Linux userdel command
  • Use of Linux date command
  • How to run Linux commands in the background
  • Use of Linux stat command
  • Use of Linux ln command
  • Linux cut command explained
  • Use of Linux bzip2 command

<<:  Vue-router does not allow navigation to the current location (/path) Error reasons and fixes

>>:  Vue realizes the percentage bar effect

Recommend

What to do if you forget your mysql password

Solution to forgetting MySQL password: [root@loca...

Solve the problem of inconsistent front and back end ports of Vue

Vue front and back end ports are inconsistent In ...

How to install vim editor in Linux (Ubuntu 18.04)

You can go to the Ubuntu official website to down...

Example of troubleshooting method to solve Nginx port conflict

Problem Description A Spring + Angular project wi...

Steps to deploy Docker project in IDEA

Now most projects have begun to be deployed on Do...

Detailed process of using nginx to build a webdav file server in Ubuntu

Install nginx Note that you must install nginx-fu...

Implementation of dynamic particle background plugin for Vue login page

Table of contents The dynamic particle effects ar...

Detailed steps for QT to connect to MYSQL database

The first step is to add the corresponding databa...

Sample code for implementing 3D rotation effect using pure CSS

Mainly use the preserve-3d and perspective proper...

10 Best Practices for Building and Maintaining Large-Scale Vue.js Projects

Table of contents 1. Use slots to make components...

Getting Started: A brief introduction to HTML's basic tags and attributes

HTML is made up of tags and attributes, which are...

How to remove spaces or specified characters in a string in Shell

There are many methods on the Internet that, alth...

Solution to the problem of z-index not taking effect in CSS3

I recently wrote a combination of CSS3 and js, an...

Web design dimensions and rules for advertising design on web pages

1. Under 800*600, if the width of the web page is...