In recent months just turned from windows, and began to slowly familiar with Linux, first not to rip than which is better, first of all with the spirit of mutual reference to understand each platform.
Linux on the development, remove the use of text editor to do the development of the Big God, everyone (including my rookie novice) need to master the Linux is a common command, can make some occasional trivial and troublesome needs to simplify. This time we'll tidy up a few.
- Cat
- Paste
- Cut
- Grep
One by one, starting with cat, yesterday the interview was asked to answer not to come up ...
Cat
Mainly three functions: displaying file contents, creating files, merging files
The basic syntax is: Cat [-parameter] file name
Specific parameters, please enter your own cat--help view, here first introduce a few I think commonly used
Cat Test.cpp
The Terminal Small Black window will directly print out all the contents of this file, if the file is too long, you can pass the pipeline to less to slowly see
Cat Test.cpp|less
- Display a file and add line numbers
Add line numbers to all rows
Cat-n Test.cpp
Add line numbers to non-blank lines
Cat-b Test.cpp
Cat > Test.txt << EOF
Simply execute the cat > Test.txt, then the terminal will wait for you to continue typing, all your input will be written to the Test.txt, finally can use CTRL + C to end, but this is not excellent (zhuang) Ya (BI), where the << EOF means that when the terminal detects that you are entering the EOF string, end the input.
- Merging files (similar to paste's basic functionality)
Cat Test.cpp test.txt > Testall
The meaning of this sentence is to output test.cpp and test.txt in sequence, and then put the results into testall this file, note here > if changed to >> that is splicing to testall the original content, otherwise it is covered by the original content
So much for the moment, a few other commands to follow. Incidentally, cat can also be used in combination with piping and paste, grep, etc., for example:
The cat test.cpp|grep-a 3 ' haha ' function is to take out all the contents of the test.cpp into grep to find the haha string and enter the line of the string that satisfies the condition and the following 3 rows
Resources:
Http://www.cnblogs.com/perfy/archive/2012/07/23/2605550.html
http://my.oschina.net/hebad/blog/346408
Common commands on Linux (i)--cat