A Cat
1.cat file1 file2 file3 ...
2. Use a pipe to read from the standard input:
echo "Hadoop hive!" | Cat–file.txt
3. Compress Blank Lines
(1) Compress multiple continuous whitespace behaviors single
Cat-s file
(2) Remove blank lines
Cat File.txt | Tr-s ' \ n '
4.cat-t file; Show tab is ^
5.cat-n file; Show line Numbers
Two Recording and playback terminal answering
Script-t 2> Timing.log-aoutput.sessin
...
Exit
Scriptreplay Timing.log output.session
Three Find
1. Traverse down the file hierarchy to match the eligible files.
2. Find. –print;
-print is a delimiter using ' \ n ' as a delimiter,-print0 indicates using ' \ s ' as the delimiter.
-NAME specifies a string that matches the file name,-iname ignores the case
Find/usr/local-name "*.txt"-print
Find. ! -name "*.txt"-print; 。 Contains a negative meaning, not the txt end of the file name
Find. \ (-name "*.txt" –o–name "*.pdf" \) –print
Find/usr/local-path "*.txt"-print
3. Search based on directory depth and file type
Find. –maxdepth 1–type F-print
Find. –mindepth 2-type F-print
-type can filter the search file
Normal file |
F |
Symbolic Links |
L |
Directory |
D |
Character device |
C |
Block devices |
B |
Sockets |
S |
Fifo |
P |
4. File time-based search
Access time:-atime,-amin
Modified:-mtime,-mmin
Change time:-ctime,-cmin
Find. –type f–atime +7–print; Print all files that have been accessed for longer than 7 days
-newer: Find all files that are updated (longer modified) than the reference file
Find. –type F-newer File.txt-print
5. File-size-based search
Find. –type f-size +2k
6. Delete matching files
Find. –type-f–name "*txt" –delete
7. File-based permissions and ownership matching
Find. –type F-perm 666–print
8. Find files owned by a specific user
Find. –type F-user Cw-print
9.find combined with –exec{}
Find. –type f–name "*.txt" –exec cp {}/usr/local \;
Find. –type f–name "*.pdf" –exec printf "text file:%s\n" {} \;
Find. Type F–name "*.cpp" –exec Cat {} \;>all.out
Four Xargs
1.xargs specializes in converting standard input data to command line parameters
2. Convert multi-line input to single-line output
Cat File.txt | Xargs
3. Convert single-line input to multi-line output
Cat File.txt | Xargs–n 4
4. Splitting parameters with delimiters
echo "Splitxshellxhadoop" | Xargs–d X-n 2
Cat file.txt |xargs-n 2./demo.sh;//The data in file is passed to demo.sh as a parameter every 2 times.
Five TR Conversion command
1.tr can only be accepted by stdin, not by command-line arguments
2. Convert the input character from uppercase to lowercase
echo "HELLO" | Tr ' A-Z ' A-Z
echo 1234 | Tr ' 0-9 ' 9876543210 '
Cat File.txt | Tr ' \ n '
3. Specify the character set to delete
Cat File.txt | Tr–d ' 0-9 '
4. Delete complement-C
echo "Hello 1 hive3 hadoop2" | Tr–d–c ' 0-9 \ n ';
Delete all characters except the collection
5.tr Compression character-S
echo "Gun isn't right?" | Tr–s "; Compress spaces
Add a number from a file
Cat Sum.txt
1
2
3
4
Cat Sum.txt | echo$[$ (tr ' \ n ' + ') 0], the tail is more than a + number all plus 0.
Six Sort
1.sort file1.txt file2.txt > Sort.txt
2.sort-n file.txt; Sort by number
3.sort-r file.txt; Reverse order
4.sort-m file.txt; Sort by month
5.sort-m Sort1.txt sort2.txt; merging merged files, no longer sorted
6.sort-k 2 file.txt; sort the second column
7.SORT-NRK 1 file.txt; Sort the first column in reverse order by number
Seven. grep
grep is used to search for a specified string in a file
1. Search for files with string bin under directory
Grep bin *
2. explicitly require search subdirectories; grep-r
3. Ignore subdirectories: grep-d Skip
4. Search by case insensitive: Grep-i pattern files
5. List only matching filenames: Grep-l pattern files
6. List filenames that do not match: Grep-l pattern files
7. Match only the entire word, not part of the string: Grep-w pattern files
8. Match the previous afternoon showing [number] line: Grep–c number pattern files
9. Show rows Matching pattern1 or pattern2: grep pattern1 | PATTERN2 files
10. Show rows that match both: grep pattern1 Files | grep pattern2
\< and \> each mark the beginning and end of a word.
12. ' ^ ' means match string at the beginning of the line, ' $ ' refers to the string at the end of the line