The second day of Linux study notes, basic file processing commands

Learned the following commands today: touch, cat -n, tac, more, less, head -n, tail -n -f.

touch (create file)

Very simple, direct touch + location/file name

Directly touch /tmp/hanjing/clj/mytest.list, you will find that the mytest.list file has been created under clj, if you give a name with spaces in the name, then you need to put your name Add double quotation marks, but we generally do not recommend adding spaces when naming the name, because in subsequent operations, you must also add double quotation marks to operate the file, which is very annoying.

cat (browse files, mostly used to browse small files)

This is very simple, directly cat + file location

Execute the cat command: cat /tmp/hanjing/clj/mysecond.test, you can browse the contents of the mysecond.test file. If you execute the cat -n /tmp/hanjing/clj/mysecond.test command, it will add line numbers to your content, so it's comfortable! (ps: please ignore my broken english)

tac

tac is the same command as cat, and it is also used to browse files, but it just reverses the content. As mentioned above, this is very simple, but he does not have the operation of -n, so let's not talk about it!

more (pagination to display the contents of the file)

The format is also more + file location: more /etc/service

This is used to view frequently used files. You can press the f key to turn the page, use the carriage return to change the line (one line each time you press it), and the q or Q key to exit

less (paginate the contents of the file)

This has the same function as the more above, but it has more functions than more, because it can turn back pages, while more cannot. In addition to the functions of more, he can also use the page Up key to turn the page up and the pageDn key to down. Turn pages. In addition, he can also search, just enter/add what you want to search for

After you execute the less command (mine is less /etc/services), just enter/add the content you want to find

Pressing the n key will jump to the next searched position.

head -n (view the beginning of the file)

If you want to view the beginning of a file, then just use the head command (head + file location). Some people will ask, what is the use of looking at the beginning of a file. In fact, the beginning of many files is written with comments , is the function of this file and some records of the author. You may know what this file is doing when you read the comments at the beginning. However, there are no comments in the picture I took below, but when the subset writes the script in the future, Best to add a note.

I directly executed head /var/log/message without adding -n, which will display 10 lines by default. When you add -n, you can limit it to display a few lines. eg: head -n 5 /var/log/message

Finally, 5 lines can be displayed.

tail (to see the end of the file)

The tail command is the same as head, except that tail looks at the end of the file. The usage is the same, except that tail has a -f, which can be used to display the end of the file in real time. For example, if you want to monitor the changes of the log in real time, just You can use the tail -f command! !

ok end.

 

 

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326995358&siteId=291194637