Linux basic command-ls
Ls
Displays everything in the current directory.
The scope of this command: RedHat, RHEL, Ubuntu, CentOS, SUSE, openSUSE, Fedora.
1. Grammar
Ls [OPTION]... [FILE]...
2. List of options
Option
Description
-- version
Display command version information
-- help
Show help documentation
-a |-- all
List all the files
-A |-- almost-all
List all files, but do not include. Or... Beginning of the file
-- author
Use with "- l" to print out the author of each file
-b |-- escape
Output the non-exportable characters in the file name as "\ + character encoding". Code in octal
-- block-size = SIZE
Set the bytes of block
-B |-- ignore-backups
Do not list implicit entries that end with "~". It is actually a backup file.
-c
Sorted by the time the state of the file changes when used with "- lt" and sorted by name when used with "- l"
-C
Multi-column display results, default option
-- color [= WHEN]
Display different files in highlighted color. The values can be always, never, auto
-d |-- directory
Only the directory name is displayed, not the contents of the directory. Do not display the directory that the symbolic link points to
-D |-- dired
Output designed for Emacs's dired pattern
-f
Do not sort, enable "- aU", turn off "- ls-color"
-F |-- classify
After each output item, append the file type identifier.
*, which represents a normal file with executable permissions.
/, which represents the directory.
@, which represents symbolic links.
|, represents a named pipeline.
=, representing the socket.
-- file-type
Same as "- F", but does not output *
-- format = WORD
Span-x, comma-m, horizontal-x, long-l, single column-1, detailed-l, vertical-c
-- full-time
Show the full time,-l-- time-style=full-iso
-g
Same as "- l", but does not show the owner
-- group-directories-first
Group the directories in front of the files, but any use of "--sort" disables grouping.
-G |-- no-group
Do not print the group name in the long list
-h
Display in a more readable way, used with "- l"
-si
Same as "- h", but with 1000 digits instead of 1024
-H |-- dereference-command-line
Follow the symbolic links listed on the command line
-- dereference-command-line-symlink-to-dir
Follow each command line symbolic link to the directory
-- hide = PATTERN
Do not list implicit entries that match the shell pattern (overridden by-an or-A)
-- indicator-style = WORD
Append an indicator with a style word to the item name: none (default), slash (- p), file type (- file type), category (- F)
-I
Show the index node of the file
-I |-- ignore = PATTERN
Do not list implied entries that match the shell pattern
-k
Equivalent to "--block-size=1K"
-L |-- dereference
When displaying file information for symbolic links, display information about the link referencing the file, not the link itself.
-l
Display in long format
-m
Display horizontally, separating files with "," and a space
-n |-- numeric-uid-gid
Similar to-l, but lists the user ID and group ID.
-N |-- literal
Print the original entry name (do not specifically deal with control characters)
-o
Same as the option "- l", but does not display group information
-p |-- indicator-style = slash
Add a slash "/" in front of the directory
-Q |-- hide-control-chars
Characters that cannot be displayed, use "?" Replace
-- show-control-chars
Display non-graphic characters as is
-Q |-- quote-name
Enclose the item name in double quotation marks
-- quoting-style = WORD
Use a reference style word for the entry name: literal,locale,shell,shell-always,c,escape
-r |-- reverse
When sorting, sort in reverse by file name
-R |-- recursive
Recursively display subdirectories
-s |-- size
Displays the file size in blocks. The default is 1024k.
-S
Sort by file size
-t
Sort in descending order according to the modification time of the file
-- sort = WORD
Sort by specified requirements, not by name: no sort (- U), extension (- X), size (- S), time (- t), version (- v)
-- time = WORD
With "- l", the time is displayed as specified, not modified: atime (- u), access (- u), use (- u), ctime (- c), or state (- c); if "--sort=time" is specified, the specified time is used as the sort key.
-- time-style = STYLE
With "- l", the time is displayed in the specified style: full-iso,long-iso,locale,+FORMAT. FORMAT is interpreted as "date"; if the format is FORMAT1FORMAT2,FORMAT1 for non-recent files, FORMAT2 applies to recent files; if the style is prefixed with "POSIX-", the style takes effect only outside the POSIX locale.
-T |-- tabsize = COLS
Refers to the size of the custom table character. The default is 8.
-u
Use with "- lt": sort by access time and display; use with "- l": display access time, sort by name; other cases: sort by access time
-U
Do not sort; list entries in catalog order
-v
Naturally sorted (version) numbers in text
-w |-- width = COLS
Sets the screen width instead of the current value
-x
List entries by line rather than by
-X
Sort alphabetically by input extension
-1
List one file per line
-- lcontext
Displays the security context. Enable "- l". The line may be too wide for most monitors.
-Z,-- context
Displays the security context to fit most displays. Only modes, users, groups, security contexts, and file names are displayed.
-- scontext
Only the security context and file name are displayed.
3. Description
By default, the use of colors to distinguish file types is disabled, and "--color=never" is used. Ls issues a color code only when the standard output is connected to the terminal. The LS_CONERS environment variable can be changed and set using the dircolors command.
The size can be KB,1000;K,1024,;MB,1000*1000;M,1024*1024
4. Examples
1) display all files and append file types to the end
[root@localhost weijie] # ls-lF
The total dosage is 1072
-rw-r--r-- 1 root root 7 September 09:11 1.c
-rw-r--r-- 3 root root 358400 September 7 15:46 link
-rw-r--r-- 3 root root 358400 September 7 15:46 link1
Lrwxrwxrwx 1 root root June 10 12:13 link2-> my.iso
-rw-r--r-- 3 root root 358400 September 7 15:46 my.iso
Drwxrwxrwx 2 root root 4096 September 10 11:33 test/
Drwxr-xr-x 2 root root 4096 September 10 16:10 test02/
Drwxr-xr-x 2 root root 4096 September 10 11:35 testt/
-rw- 1 root root 7 September 14:55 wj234.q1C
Drwx- 2 root root 4096 September 7 14:50 wjtpflR/
2) display the directory name, not the contents under the directory
[root@localhost /] # ls / weijie/ list all files in the weijie directory
1.c link link1 link2 my.iso test test02 testt wj234.q1C wjtpflR
[root@localhost /] # ls-ld / weijie/ displays only the information of the weijie directory itself
Drwxr-xr-x 6 root root 4096 September 10 15:28 / weijie/
[root@localhost /] #