Linux basics-1day-Linux document operation command-ls

Linu x document operation command -ls

 

1. Command function

The ls command is the abbreviation of list, which is used to list all subdirectories and files in the target directory. The ls command can not only view the files contained in the linux folder, but also view file permissions (including directories, folders, file permissions), directory information, and so on.

2. Command format

ls [parameter options] [directory name]

3. Common parameters

parameter

Features

-a

-All lists all files in the directory, including hidden files beginning with.

-c

With -lt: sort and display ctime according to ctime (the time when the file status was last changed)

-l

In addition to the file name, the file permissions, owner, and file size information are listed in detail, the same as -g.

- -color=WHEN

Controls whether to use color resolution files, WHEN can be one of never, always or auto.

-d

-Directory only displays the directory, not the files under it.

-h

--Human-readable lists file sizes in an easy-to-understand format (K/M/G)

-i

--Inode print out the inode number of each file

-L

--Dereference When displaying the file information of a symbolic link, display 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 line width

-R

--Recursive list all sub-directory layers

-s

--Size lists the size of all files in block size

-S

Sort by file size

-t

Sort by file modification time

-v

Sort by version

-w

--Width=COLS specify the width of the screen without using the current value

-F

The option will add a / after the directory when displaying directory entries, and * for executable files

-x

List items line by line instead of column by column

–help

Show this help message

–version

Display version information

 

4. Examples

( 1) List the detailed information of all directories starting with b in the current directory

ls -l b *

( 2) Only list the subdirectories of the current directory

 ls -F /root/back/ |grep /

( 3) List all directories in the current directory

ls -l | grep ^ d

Note: ^: the first position of the file, that is, the beginning of the line; ^d: the file or line starting with d

(4) Count the number of files and directories in the current directory

 ls -l * |grep "^-"|wc -l #Count the number of files 
 ls -l * |grep "^d"|wc -l #Count the number of directories

(5) List the absolute path of the file

 ls | sed "s:^:`pwd`/:"

Note: sed "s:^:`pwd`/:" pwd command returns the current directory, `pwd` takes the output of the pwd command as a string, and "s:^:`pwd`/:" replaces the beginning of the line with the current table of Contents.

 Personal public number:

 Picture.png

 

 

 


Guess you like

Origin blog.51cto.com/13440764/2576697