Monday, July 4, 2011

*nix Cheat Sheet

How to copy line in a file and paste it into a new file?
(http://askubuntu.com/questions/59432/how-to-copy-line-in-a-file-and-paste-it-into-a-new-file)

There are several ways to do this. If your file has some known structure, you can use grep. The grep command searches a file for a specific phrase and returns lines that match that phrase. So if your file looks like

Name: Sally

Date of Birth: 7.31.76

Address: 1234 Main St.

SSN: 123-45-6789

you can run grep Name info.txt and it will return Name: Sally. You can then redirect the output to another file. So calling

grep Name info.txt > info2.txt

will output the line to the new file info2.txt. If you want to append new lines, you can do

grep Address info.txt >> info2.txt

otherwise the file will be overwritten.

You could also learn to use a command line text editor like vim.


How to flush dns in ubuntu 12.04?

sudo /etc/init.d/nscd restart


Ever try to cut (or copy) some lines and paste to another place?
 If you need to count the lines first, then try these to eliminate counting task.

Cut and paste:

Position the cursor where you want to begin cutting.
Press v (or upper case V if you want to cut whole lines).
Move the cursor to the end of what you want to cut.
Press d to cut or y to copy.
Move to where you would like to paste.
Press P to paste before the cursor, or p to paste after.
Copy and paste can be performed with the same steps, only pressing y instead of d in step 4.

The name of the mark used is related to the operation (d:delete or y:yank).

I found that those mark names requires minimal movement of my finger.

(http://vim.wikia.com/wiki/Copy,_cut_and_paste)

No comments:

Post a Comment