Common Linux advanced file operation commands

Source: Internet
Author: User

Common Linux advanced file operation commands

Cat view text
# Cat file name print the file content to the current screen
# Cat-n the row number displayed for the file name
# Cat> a.txt can be used to modify or create a file.
Manually enter text
Continue Input
...
The shortcut key (ctrl + d) ends.
 
> Output redirection (overwrite the original text content)
> Output redirection (append based on the original content)
<Input redirection
 
# Cat <a. sh
12345
Abcde
 
Ctrl + d end
Ctrl + c interrupt
 
Tac display in reverse order
# Display text in reverse order of tac file names
 
Tee writes text content
# Ls | tee a.txt: Write the specified text file while executing the preceding command
# Ls | tee-a.txt-a appended with the original content
 
Cut
# Cat/etc/passwd | cut-d ":"-f 1
# Cat/etc/passwd | cut-d:-f 1
# Cat/etc/passwd | cut-d:-f 1
Column 1, 2, and 7
# Cat/etc/passwd | cut-d ":"-f 1, 2, 7
Retrieve 2nd columns to 7th Columns
# Cat/etc/passwd | cut-d ":"-f 2-7
Retrieve 1st columns to 6th Columns
# Cat/etc/passwd | cut-d ":"-f-6
Retrieve all columns after 6 Columns
# Cat/etc/passwd | cut-d ":"-f 6-
"" Must be added when it is a special character (which can be interpreted by shell)
 
-D delimiter
Specifies the delimiter. There can be no space between the delimiter and the specified delimiter. The default Delimiter is a tab key.
-F field specifies the number of columns to be split.
 
Wc statistics
# Number of lines in wc-l file names
# Wc-c file name count characters (including all characters, such as line breaks)
# Wc-w file name statistics word count (no space, it will be considered as a word)
 
Sort sorting
 
# Cat a.txt
Abcd
Defb
Caef
 
Sort different characters in the first column
# Cat a.txt | sort
Abcd
Caef
Defb
 
Sorting with the same characters in the first column
# Cat a.txt | sort
AAbcd
ACaef
ADefb
 
-T
-K
# Cat a.txt
E: Abcd
D: Defb
A: Caef
 
# Cat a.txt | sort-t:-k 2
E: Abcd
A: Caef
D: Defb
 
# Cat a.txt | sort-t:-k 2.2
A: Caef
E: Abcd
D: Defb
 
# Cat a.txt | sort-n
9d: Defb
50a: Caef
60e: Abcd
 
# Cat a.txt | sort-n-r
60e: Abcd
50a: Caef
9d: Defb
 
Uniq unique
Uniq calculates consecutive duplicate rows.
# Cat a.txt Source Text
12345
Abcde
12345
Abcde
Abcde
 
After being processed
[Root @ bkjia/var/ftp/1118ule] # cat a.txt | uniq-c
1 12345
1 abcde
1 12345
2 abcde
 
Number of consecutive duplicate rows
[Root @ bkjia/var/ftp/1118ule] # cat a.txt | sort | uniq-c
2 12345
3 abcde
 
Only list rows without consecutive duplicates
[Root @ bkjia/var/ftp/1118ule] # cat a.txt | uniq-u
12345
Abcde
12345
 
Only duplicate rows are listed.
[Root @ bkjia/var/ftp/1118ule] # cat a.txt | uniq-d
Abcde
 
Diff compares different text content
# Diff-u a.txt B .txt> pacth. diff
Patch Patching
# Patch a.txt pacth. diff
 
Exercise:
Use previous commands to count the ip addresses of eth0 NICs on the local machine (as long as the ip addresses)

Count the number of identical commands in the/bin and/usr/bin directories.

11 Linux commands that are rarely known but useful

Common text processing commands in Linux

Organize common Linux Network commands

Linux Command sorting

20 required commands for Linux beginners

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.