Simple Linux Command Line notes: ls

Source: Internet
Author: User
ArticleDirectory
    • Parameters
    • Option
    • Example
    •  
    • Tips

Displays information about one or more files.

Ls [Options] [File-list]

 

Parameters

By default,LsList file information in alphabetical order of file names,File-listCan be any file or directory

WhenFile-listWhen multiple directories are included,LsThe directory name will be displayed, not the subdirectories and sub-Files

WhenFile-listWhen it is a common file,LsThe file information is displayed.

 

Option

-A: displays the list of all file names, including hidden files (the file name starts with a period)

-A is similar to-a, but does not list directory items such as. And.

-L list more information for each file

-M indicates the file name separated by commas (,). The width of the file list is the same as that of the screen.

-H select an appropriate unit from K (kilobytes), m (megabytes), and g (gigabytes) to display the file size

-R: List Directory hierarchies in reverse order

-R recursively lists sub-directory content

-T display files in the order of the last modification time

-U displays files in the order of the last access time

-X Display the file list by row (by column by default)

-X displays files in the order of file extensions. files without extension names are listed first.

-One Line displays a file

-D: Only displays the directory name.

-F this option displays a slash (/) after each directory, an asterisk (*) after each executable file, and a symbol @ after each symbolic link @

 

Example Ls
$LsA. Out demo1.java hello. c pink.CPPTest.txt workbin demo. JavaInstall.ShSu.ShTxt

File names are listed alphabetically and vertically arranged

 

Ls-x
 
$Ls-Xa. out bin demo1.java demo. Java hello. cInstall.ShPink.CPPSu.ShTest.txt TXT work

List file names in alphabetical order and arrange them horizontally

 

Ls-F
 
$Ls-Fa. Out* Demo1.java hello. c pink.CPPTest.txt work/Bin/Demo. JavaInstall.Sh*Su.Sh* TXT @

A slash (/) is displayed after the directory, an asterisk (*) is displayed after the executable file, and @ is displayed after the symbolic link @

 

Ls-l
$ Ls - L total usage  8  Drwxrwxr -X 2 Siu4096 January 7   20 : 00  Bin -Rwxrwxr-x 1 Siu 0 January 7   20 : 00   Install . Sh -RW-r -- 1 Siu 0 January7   20 : 06 Pink. CPP -RW-r -- 1 Siu 0 January 7   20 : 01  Test.txt lrwxrwxrwx  1 Siu 8 January 7   20 : 01 TXT-> Test.txt drwxrwxr -X 2 Siu 4096 January 7   20 : 02 Work

Use the long list method to list file names, that is, detailed information.

 

Ls-lH
$Ls-Total LH usage 57 m-RW -------1Siu 326 K December25 16:50Iartwork.Zip-RW -------1Siu 54 m December31 22:41Jtregex3_jb51.7z-RW -------1Siu2.9 mJanuary4 21:10Mboo.Zip

Use a proper unit to display the file size. Here I caught a few large files to check the total usage of 57 MB.

 

Ls-
$Ls-A... awtdemo. java. SWP BinInstall.ShPink.CPPTest.txt TXT work

List all files, including hidden files. In this example, "." indicates the current directory. "indicates the upper-level directory. (this is the case in Linux. Ignore this option)

 

Ls-Al
$ Ls - Total Al usage  28  Drwxr -XR-x 4 Siu 4096 January 7   20 :16  . Drwxr -XR-x 51 Siu 4096 January 7   14 : 09  .. -RW ------- 1 Siu 12288 December 12   14 : 22  . Awtdemo. java. swpdrwxrwxr -X2 Siu 4096 January 7   20 : 00  Bin -Rwxrwxr-x 1 Siu 0 January 7   20 : 00   Install . Sh -RW-r -- 1 Siu0 January 7   20 : 06 Pink. CPP -RW-r -- 1 Siu 0 January 7   20 : 01  Test.txt lrwxrwxrwx  1 Siu 8 January 7  20 : 01 TXT-> Test.txt drwxrwxr -X 2 Siu 4096 January 7   20 : 02 Work

Use a long list to list all objects

 

Ls-ral
$ Ls - Total ral usage  28  Drwxrwxr -X2 Siu 4096 January 7   20 : 02  Worklrwxrwxrwx  1 Siu 8 January 7   20 : 01 TXT-> Test.txt -RW-r -- 1 Siu 0 January7   20 : 01  Test.txt -RW-r -- 1 Siu 0 January 7   20 : 06 Pink. CPP -Rwxrwxr-x 1 Siu 0 January 7   20 :00   Install . Sh  Drwxrwxr -X 2 Siu 4096 January 7   20 : 00  Bin -RW ------- 1 Siu 12288 December 12   14 : 22 . Awtdemo. java. swpdrwxr -XR-x 51 Siu 4096 January 7   14 : 09  .. Drwxr -XR-x 4 Siu 4096 January 7   20 : 16 .

Lists all objects in a long list, but returns the reverse alphabetical order.

 

Ls-Tl
$Ls - Total TL usage  12 -RW-r -- 1 Siu 5 January 7   20 : 27  Demo. cdrwxrwxr -X 2 Siu 4096 January 7   20 : 02 Worklrwxrwxrwx  1 Siu 8 January 7   20 : 01 TXT-> Test.txt -RW-r -- 1 Siu 0 January 7   20 : 01  Test.txt -Rwxrwxr-x 1 Siu0 January 7   20 : 00   Install . Sh  Drwxrwxr -X 2 Siu 4096 January 7   20 : 00 Bin

Sort by file modification time. The last modified file information is at the top of the list.

 

Ls-RTL
$ Ls - Total RTL usage  12  Drwxrwxr -X 2 Siu 4096 January 7   20 : 00  Bin -Rwxrwxr-x 1 Siu 0 January 7   20 : 00   Install . Sh -RW-r -- 1 Siu 0 January 7   20 : 01  Test.txt lrwxrwxrwx  1 Siu 8 January 7   20 : 01 TXT-> Test.txt drwxrwxr -X 2 Siu 4096 January 7   20 : 02  Work -RW-r -- 1 Siu 5 January 7   20 : 27 Demo. c

Sort by file modification time. The last modified file information is at the bottom of the list.

 

Ls directory
 
$LsBina.txt B .txt c.txt

List contents in the directory. Bin is a directory.

 

Ls-DL directory
 
$Ls-DL bindrwxrwxr-X2Siu4096January7 20:41Bin

List bin directory details in a long list

 

Ls-r directory
 
$Ls-R Binbin: a.txt B .txt c.txtDirBin/Dir: D.txt e.txt

Recursively list all objects in the bin directory

 

Ls-l t *
$Ls-L T *-RW-r --1Siu0January7 20:01Test.txt lrwxrwxrwx1Siu8January7 20:01TXT-> test.txt

List all files starting with T

Tips

1. parameters can be used separately or together. The effects of LS-Al and LS-a-l are the same.

2. ls can be followed by various wildcards, various directories, common files, and various device files ...... Rely on, various messy ......

 

 

 

 

 

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.