21. splicing with cat the 1cat command is a simple command that is commonly used. cat itself indicates concatenate (splicing) 2. reading files with cat generally & amp; 26684; is catfile1file2file3.
2.1 splice with cat
1 cat command is a simple command that is commonly used. cat itself indicates concatenate (splicing)
2. the general format for reading files with cat is
Cat file1 file2 file3. .. // This command concatenates the file content of the command line parameters and outputs them together.
3 The cat command not only reads files and concatenates data, but also reads data from standard input. To read data from the standard input, use the MPs queue.
Stand_ouput | cat
4 cat commands can be used to compress multiple empty lines so that they can be compressed into a single
Cat-s file
5 The tr command can also compress multiple '\ n' characters into a single' \ n'
6 The-n option of the cat command will add a line number before each line of output content, but this does not modify the file content
2.2 Recording and Playback terminal session
1 The script and scriptreplay commands can be found in most GNU/Linux distributions.
2 The scritp command can also be used to create a video session for broadcasting between multiple users.
Step 1: open two terminals T1 and T2
Step 2: Enter mkfifo scriptfifo in T1
Step 3: Enter the following command in T2: cat scriptfifo
Step 4: Enter the following command in T1: script-f scriptfifo
Step 5: The commands entered in T1 can be viewed in T2.
2.3 file search and file list
1 find is one of the best tools in the UNIX/Linux command line toolkit.
2. the find command works as follows: Traverse down the file hierarchy, match the files that meet the conditions, and perform the corresponding operations.
3. list all files and folders in the current directory and subdirectory: find base_bash
4. two important parameters of the find Command
-Print indicates the name of the file to be matched. when-print is used, '\ n' is used as the delimiter for splitting the file.
-Print0 indicates that '\ 0' is used as the delimiter to print each matching file name.
5. search by file name or regular expression. the-name parameter specifies the string matching the file name.
For example, find.-name "*. txt"-print // command to find all txt files in the current directory and print them out.
6. the find command has an option-iname, which is similar to-name, but is case-insensitive during matching.
7. the find command can also be used! To deny the parameter meaning.
Find .! -Name "*. txt"-print // command is used to find all non-txt files in the current directory
8. when the find command is used, all subdirectories are traversed. we can use the depth parameter to limit the depth of the traversal of the find command.
-Maxdepth and-mindepth specify the maximum recursive depth and the minimum recursive depth (from which layer to start searching down)
9-maxdepth and-mindepth should appear as the third parameter of find, so that you can immediately limit the search conditions and improve the efficiency.
The 10-class UNIX system regards everything as a file. the file has different types, such as common files, directories, character devices, block devices, symbolic links, hard links, sockets, and FIFO.
11. the-type option of the find command can be used to filter file searches.
12 type parameter to match the required file type
File type parameters
Common File f
Match link l
Directory d
Character device c
Block device B
Socket s
Fifo p
13. delete the matching file.-delete can be used to delete the matching file found by find.
Find.-type f-name "*. txt"-delete // The function of the command is to find all the txt files in the face-to-face directory, and then delete
14 search based on file permissions and ownership
Find.-type f-name "*. txt"-perm 644-print // The command is used to find all txt files with 644 permissions in the current directory.
2.4 conversion using tr
1 tr can be used to replace, delete, and compress standard input characters. it can convert a group of characters into another group. Therefore, it is also called a conversion command.
2 tr can only use stdin, but cannot accept input through command line parameters.
Tr [options] set1 set2 // map the input character from stdin from set1 to set2 and input it to stdout.
Set1 and set2 are character classes or character sets. if the two character sets are not of the same length, set2 repeats the last character until they are equal to set1, if the length of set2 is greater than set1, the part length beyond set1 in set2 is ignored.
3. convert the input characters from uppercase to lowercase. you can use the following command:
Echo "hello who is this" | tr 'A-z'' A-Z' // Both 'A-Z and 'A-Z' are collections.
4 tr has an option-d. You can delete a specific character in stdin by specifying the character set to be deleted.
Echo "Hello 13 world 345" | tr-d '0-9' // The command deletes and outputs the numbers in stdin.
5. we can use option-c to use the set1 supplement set.-c set1 is equivalent to defining a set, which contains no characters in set1.
6 tr can use different character classes like a set. These character types are as follows:
Alnum: letters and numbers
Alpha: letter
Cntrl: control character
Digit: number
Graph: graphical character
Lower: lowercase letter
Print: Printable characters
Punct: Punctuation marks
Space: White space
Upper: uppercase letters
Xdigit: hexadecimal character
7. select the character set to use as follows: tr [: class1:] [: class2:]
2.5 sorting, single and repeated
The 1 sort command can get input from a specific file or stdin and write the input to stdout. the uniq working mode is the same as that of sort.
2. we can sort a group of files in the following way.
Sort file1 file2 file3...> sorted // command to sort multiple files and redirect to sorted
3. sort by number: sort-n file
Sort in reverse order: sort-r file
Sort by month: sort-M file
4. to merge two sorted files without sorting the merged files, you can use
Sort-m sorted1 sorted2
5 The uniq command finds a single line from a given input by eliminating repeated content. It can also be used to find repeated rows in the input.
6 uniq can only be used for sorting data input. Therefore, uniq either uses an MPs queue or a file that has been sorted as the input.
Show only unique rows: uniq-u sorted
Count the number of times displayed in a row: uniq-c sorted
Find the duplicate row in the file: uniq-d sorted
2.6 split files and data
1. generate a KB test file
Dd if =/dev/zero bs = 100 K count = 1 of = data. file
The above Command will create a file with a capital of KB, all of which are 0
2. we can specify the split size to split the file into multiple smaller files.
Split-B 10 k data. file // This command splits data. file into multiple files, each of which is 10 KB
2.7 split file names by extension
1 with %, we can easily extract the name from the file name in the format of "name. extension"
2 $ {var %. *} indicates
First, remove the matching string of the wildcard located on the right of % from $ var. the wildcard matches from right to left.
Second, assign var=sample.jpg to var=, and assign .jpg to the right to remove it.
3% is a non-greedy operation. it matches the shortest result of a wildcard from right to left. Another one is that % is greedy and the longest matching result is returned.
4. Similar # is the same as %, that is, it matches from left to right and is a non-greedy operation.
So ## is similar to %