Shell basic command ls, shell basic ls

Source: Internet
Author: User

Shell basic command ls, shell basic ls

Shell basic command ls

1 Command Format

Ls [Option] [command name]

2. command functions

List all subdirectories and files in the target directory

3. Common Parameters

-A,-all: list all directories and files in the directory, including hidden files starting.

-A is the same as-a, but does not list the current directory starting with. And the parent directory starting.

-C with-lt: sort by ctime and display ctime (the last time when the file was changed); with-l: Display ctime but sort by file name; otherwise, sort by ctime

-C. List projects from top to bottom in each column

-Color [= WHEN] controls whether to use color to distinguish files. WHEN can be one of never, always, and auto.

-D: display the directory like a file instead of the file under it.

-F does not sort the output files. The-aU option takes effect and the-lst option is invalid.

-G is similar to-l, but does not list the owner

-G-no-group does not list all group information

-H-human-readable lists the file size in a way that is easily understood by humans (for example, 1 k 234 M 1G)

-I-inode: List inode numbers of each file.

-K-block-size = 1 k, representing the file size in k bytes

-L list the object owner, permission, and file size except the object name.

-M all items are separated by commas (,) and the whole row width is filled.

-O is similar to-l. All information except group information is displayed.

-R-reverse in reverse order

-R-recursive: list all sub-project layers at the same time

-S-size: list all sub-directory layers in Block size

-S sort by file size

-T sort by file modification time

-U with-lt display access time and sort by access time

-V sort by version

-U is not sorted in the original order of the file system.

-W-width = COLS: Specify the screen width without using the current value.

-X: list items row by row instead of column by column.

-X sort by extension

-1: list an object in each row.

-Help: Display help information and exit

-Version: displays the help information and leaves.

4 Examples of Common commands

Example 1: calculate the number of items and directories in the current directory

Ls-l * | grep "^-" | wc-l-file count

Ls-l * | grep "^ d" | wc-l-number of directories

Example 2: List the absolute paths of all files in the current directory without recursion

Find $ PWD-maxdepth 1 | xargs ls-ld

 

Extension

1. display the color directory list

 

Open/etc/bashrc and add the following line:

Alias ls = "ls-color"

 

The color directory list will be displayed as shown in Slackware when bash is started next time. The color meanings are as follows:

1. Blue-> directory

2. Green-> executable files

3. Red-> compressed file

4. Light blue-> link file

5. Gray-> other files

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.