View and related combination commands

1. View:

cat view text file -A can also display symbols such as line breaks -b display line numbers without blank lines -n display line numbers with blank lines -s merge blank lines when viewing

tac (reverse cat, so it is displayed in reverse)

nl display line number = cat -b

rev reverses peers

more can turn the screen, but can not look back, after reading, automatically exit ls -R / etc / | more list all the files in / etc /

All the functions of less more, you can look back, q exit ls -R / etc | more

head default header 10 lines -n header lines -c header bytes 

            Take the first 10 digits of random numbers or letters: cat / dev / urandom | tr -dc '[: alnum:]' | head -c 10

            Set a random password for the user: cat / dev / urandom | tr -dc '[: alnum:]' | head -c 10 | tee passwd.txt | passwd --stdin username

tail defaults to 10 lines at the end -n how many lines at the end -c how many bytes at the end (note that the last newline also takes one character)

tail -f tracks file descriptors, delete files at this time, without prompting. Create a file with the same name again

tail -F tracks the file name, delete the file at this time, there is a prompt. After creating a file with the same name, you can continue to track

            Only show the second line: ifconfig | head -2 | tail -1

Cut column extraction -d specifies the delimiter -f takes the first few columns such as 1; 1, 3, 6; 1-6; 1-3, 6

            Only take the IP address in ifconfig: ifconfig | head -2 | tail -1 | tr -s "" | cut -d "" -f3

            Take the utilization rate in df and keep only the numbers: df | tr -s ""% | cut -d% -f5 | tr -d "[: alpha:]"

paste horizontal merge -d specifies the merge separator -s turns the column into a row

            Example: First create a and b files: seq 1 5> a; echo {a..h} | tr "" "\ n" and then paste ab [multiple files are OK]

wc -l number of lines (the original file name will not be printed using the pipeline) -L shows the maximum length -m number of characters (one Chinese character counts one) -c total number of bytes -w total number of words

           Removed the first line of df in English: df | tail -n $ (echo `df | wc -l`-1 | bc)

lastb -f specifically view the login file information recorded by the server

sort default character order a> A> b> B> c> C> ...> z> Z -n number row -r reverse order -R random ordering -t specify separator -k specify row number -f ignore size Write -u after sorting and merging the same

Uniq deduplication, can only merge consecutive repeats -c shows the number of times each line repeats -d shows repeated -u shows that it has not been repeated

           View the IP addresses of the top three most visited users (assuming the files are separated by "", the first column is ip): cut -d "" -f1 file | sort | uniq -c | sort -nr | head -3

           There are two files, a and b. Assuming that there are no duplicate lines in the file, how to find the same line and different lines? Same: cat ab | sort | uniq -d different: cat ab | sort | uniq -u

diff comparison -u more detailed

patch Patch, combined with diff -u -b backup, otherwise it will overwrite the original file

           例:diff -u 1.txt 2.txt >diff.txt         rm -rf 2.txt            patch -b 1.txt diff.txt

cmp compare binary

hexdump View binary text -C is more intuitive echo {a..z} | tr -d "" | hexdump -C

od is similar to hexdump od -t

xxd is similar to hexdump

Use vim to convert windows format file to Linux format file: after vim is opened,: set ff = unix

Guess you like

Origin www.cnblogs.com/ldyaly/p/12732953.html