Linux Learning Notes Command Chapter 1---command ls

Source: Internet
Author: User
Tags parent directory sorts

Objective:

Most of the contacts in Linux are commands and files.

  Command

The command is in its format, and the general format is command [option] Parameter1 parameter2 [paramete3 ...] ;

Comments:

command is an order. These are the command names that Linux can perform, similar to some of the keywords. If you enter an illegal command, Linux will not be prompted to find the command.

option is optional. This is enclosed in brackets to indicate that the option is available or not, if not the default. Options are usually started with a minus sign '-', multiple options can be combined to write one, or can be written separately.

Parameter1 is a parameter. If there are parameters to write, no arguments will not be written. If you have more than one parameter, use a space to split it, regardless of the number of spaces, the Linux system will follow a space processing.

A semicolon is a sign of the end of a command. If you have more than one command in a row, you can separate multiple commands with semicolons.

Linux is case-sensitive.

File

Linux files can be divided into ordinary files, linked files, pipeline files, block files, character files and so on. Most of the time we deal with ordinary files and folders.

File if the permissions according to the file can be divided into R (read), W (write), X (executable execute) file.

Linux commands are executed in two ways:

1. Enter Linux command execution directly in the Linux shell window.

2. Write the command into the shell script file and execute the executable script.

ls Command description:

The first command that most people have access to Linux is the LS command.

The LS command is the abbreviation for list. The missing LS is used to print out a list of current directories. If LS specifies a different directory, then the list of files and folders in the specified directory is displayed.

The LS command not only allows you to view the files contained in a Linux folder, but also to view file permissions (including directories, folders, file permissions), view directory information, and more. The LS command is used in a lot of everyday Linux operations!

1. Command format:

ls [options] [directory name]

2. Command function:

Lists all subdirectories and files in the destination directory.

3. Common parameters:

-a,–all lists all files under the directory, including the. The implied file at the beginning

-A with-a, but not listed "." (represents the current directory) and ".." (Represents the parent directory of the current directory).

-C CTime (the time the file state was last changed). Cooperate with-LT parameter, sort and display according to CTime, mate-L: Display CTime but sort by name. Otherwise, sort by ctime

-c list items from top to bottom of each column

--color[=when] Controls whether to use color-resolved files. When can be ' never ', ' always ' or ' auto ' one of them

-d,–directory Displays the directory as a file, rather than displaying the file below it.

-d,–dired results in the use of dired patterns for Emacs

-C: Multi-column display output results. This is the default option;

-L: In contrast to the "-C" option, all output information is output in a single-column format and not output as multiple columns;

-F: Append the type identifier of the file after each output item, meaning: "*" means a normal file with executable permissions, "/" for the Directory, "@" for the symbolic Link, "|" Represents a command pipeline FIFO, and "=" represents a sockets socket. When the file is a normal file, do not output any identifiers;

-B: Outputs the non-output characters in the file with the backslash "" and the character encoding;

-F does not sort the output files, the-au option is active, the-LST option is invalid

-g similar to-l, but does not list owner

-g,–no-group does not list any information about the group

-h,–human-readable list file sizes in an easy-to-understand format (e.g. 1K 234M 2G)

–si is similar to-H, but the file size takes 1000 times instead of 1024

-h,–dereference-command-line the true destination indicated by using symbolic links in the command column

The –indicator-style= method specifies that after each project name is followed by the indicator < >:none (default), classify (-f), File-type (-P)

-i,–inode Prints the inode number of each file

-i,–ignore= style does not print any items that match the shell character < style >

-K is the –block-size=1k that represents the size of the file in K-byte form.

- L lists the permissions, owner, file size, and so on, in addition to the file name.

-l,–dereference when displaying the file information for a symbolic link, displays the object indicated by the symbolic link instead of the information of the symbolic link itself

-m all items are separated by commas and fill the entire row width

-O is similar to-L, showing details of the file in addition to the group information.

-r,–reverse in reverse order.

-r,–recursive listing all subdirectory tiers at the same time

-s,–size to list the size of all files in block size

-s sort by file size

–sort=word The following are optional WORD and the corresponding options they represent:

Extension-x status-c

None-u time-t

Size-s Atime-u

Time-t Access-u

Version-v Use-u

-T sorted by file modification time

- u mates

-LT: Show access time and sort by access time

Mate-L: Show access time but sort by name

Otherwise: Sort by access time

-U does not sort, lists items according to the original order of the file system

-V Sort by version

-W,–WIDTH=COLS Specifies the screen width without using the current value

-X list items line by row instead of columns by column

-x Sort by extension

-1 list only one file per line

Help display this help message and leave

–version display version information and leave

-M: The name of each file and directory separated by the "," area;

-N: Replace its name with user identification code and group identifier;
-L: If you encounter a file or directory with a symbolic link, directly list the original file or directory that the link points to;

4. Common examples:

Example one: List the details of all files and directories under the/home/peidachang folder

Command: Ls-l-r/home/peidachang

When using the LS command, pay attention to the format of the command: At the command prompt, the first is the command keyword, followed by the command parameters, before the command parameters to have a short line "-", all the command parameters have a specific role, you can choose one or more parameters according to the need, After the command argument is the action object of the command. In the above command "Ls-l-r/home/peidachang", "LS" is the command keyword, "-l-r" is a parameter, "/home/peidachang" is the action object of the command. In this command, two parameters are used, respectively "L" and "R", and of course, you can also put them together, as shown below:

Command: Ls-lr/home/peidachang

This form is exactly the same as the result of the above command form execution. In addition, if the Operation object of the command is located in the current directory, the Operation object can be manipulated directly, if not in the current directory you need to give the full path of the action object, for example, in the example above, my current folder is the Peidachang folder, I want to operate the Peidachang file under the home folder, I can enter the LS-LR Peidachang directly, or I can use Ls-lr/home/peidachang.

Example two: Listing the details of all directories in the current directory that begin with "T", you can use the following command:

Command: Ls-l t*

You can view information for all files in the current directory that have a file name that begins with "T". In fact, in the command format, the contents of the square brackets can be omitted, for the command LS, if you omit the command parameters and Operation object, directly enter "LS", will be listed in the current working directory of the Content list.

Example three: Listing only subdirectories under a file

Command: ls-f/opt/soft |grep/$

List the subdirectories below the/opt/soft file

Output:

[Email protected] opt]# ls-f/opt/soft |grep/$

jdk1.6.0_16/

Subversion-1.6.1/

tomcat6.0.32/

command : ls-l/opt/soft | grep "^d"

Lists the subdirectory details under the/opt/soft file

Output :

[Email protected] opt]# Ls-l/opt/soft | grep "^d"

Drwxr-xr-x root root 4096 09-17 18:17 jdk1.6.0_16

Drwxr-xr-x 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 four: List the current working directory of all the names are the beginning of the file, the newer the new row, you can use the following command:

Command: Ls-ltr s*

Output :

[Email protected] 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 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 1016 1016 4096 10-11 03:25 subversion-1.6.1

Example five: List all the files and directories under the current working directory; directory after name add "/", executable file after the name plus "*"

Command : LS-AF

Output :

[Email protected] opt]# LS-AF

log/script/soft/src/svndata/web/

Example six: Calculating 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---directory number

Example VII: The absolute path of the file is listed in LS

Command: LS | Sed "s:^: ' pwd '/:"

Output :

[[email protected] opt]# ls | Sed "s:^: ' pwd '/:"

/opt/log

/opt/script

/opt/soft

/opt/src

/opt/svndata

/opt/web

Example nine: Lists the absolute path to all files (including hidden files) under the current directory, and does not recursively

Command: Find $PWD-maxdepth 1 | Xargs Ls-ld

Output:

[[email protected] 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 Ten: Recursively lists the absolute path of all files (including hidden files) under the current directory

Command: Find $PWD | Xargs Ls-ld

Example 11: Specifying the file time output format

Command:

LS-TL--time-style=full-iso

Output:

[Email protected] soft]# LS-TL--time-style=full-iso

Total 350644

Drwxr-xr-x 1016 1016 4096 2012-10-11 03:25:58.000000000 +0800 subversion-1.6.1

Ls-ctl--time-style=long-iso

Output:

[Email protected]st soft]# ls-ctl--time-style=long-iso

Total 350644

Drwxr-xr-x 1016 1016 4096 2012-10-11 03:25 subversion-1.6.1

Extended:

1. Display a list of color catalogs

Open/ETC/BASHRC and add the following line:

Alias ls= "LS--color"

The next time you start bash, you'll be able to display a list of colored catalogs as you would in Slackware, where the meanings of colors are as follows:

1. Blue---Directory

2. Green---executable file

3. Red--Compress files

4. Light blue--linked files

5. Gray--Other files

The parameter combinations of LS that I use often are as follows:

Ls-l: Lists the details of all files and folders under the current directory, with the output being sorted by file name by default.

Ls-alt: Lists the details of all files and folders under the current directory and sorts them according to their access times. From the newest to the old.

LS-ALTR: Lists the details of all files and folders under the current directory and sorts them according to their access times. from old to new.

LS-ALH: Lists the details of all the files and folders in the current directory, and displays the size of the file in m,g,k form.

L: Lists the details of all the files and folders in the current directory and sorts them by the name of the file.

Ls-1: A file name is listed per line.

Ls-f: Lists all files and folders in the current directory, and the folder ends with a/, and the executable file ends with a *.

Ls-r: Recursively lists the details of all files and folders in the current directory and sorts them according to their access times.

LS is used with grep, Find,awk,while, and other commands.

  

Linux Learning Notes Command Chapter 1---command ls

Related Article

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.