Quickly Find a PID with pgrep



pgrep looks through the currently running processes and lists the process IDs which matches the selection criteria.



pgrep ssh

- This will list all PIDs associated with the ssh process.



Execute The Last Executed Command



!!

This will execute the last command you used on the command line.



Isn't the UP arrow for that?



The !! command is very useful when you forget to start a command with sudo :

apt-get update

sudo !!



Execute The Last Command Starting With ...



If you want to execute a command from history starting with the letter S you can use the following:



!s

- This will execute the last command used on the command line that started with s.



Last Argument



You can use the last argument from the last command by refering to it as $_



so you only need to type a long path like this once:

cp assignment.htm /home/phill/reports/2008/

cd $_

to go straight to the 2008 folder as well.



You can use this however you like. Always the last argument of the command above.



Like using $_ for the last argument of the last command, you can also hit ALT+. to quickly paste it at the cursor.



Run a Command Repeatedly and Display the Output



watch runs a command repeatedly, displaying its output. This allows you to watch the program output change over time. By default, the program is run every 2 seconds. watch is very similar to tail .



watch -d ls -l

- This will watch the current directory for any file changes and highlight the change when it occurs.



Save Quickly in VI/VIM



Save and quit the file you’re editing in vi by exiting insert mode, holding shift, and hitting z twice ( ZZ ). That is quick or not, it depends.



You can use :wq OR more easily :x



Quickly Log Out of a Terminal



You can quickly log out of a terminal session by using: CTRL+D



Navigate to the Last Directory You Were In



cd –

will take you to the last directory you were in.



Make Parent Directories the Smart Way



mkdir -p /home/adam/make/all/of/these/directories/ will create all directories as needed even if they do not exist. Why waste time doing something silly like: mkdir make ; cd make ; mkdir all ; cd all ; mkdir of ; cd of … you get the point. Use mkdir -p ! This is one command I really lacked.



Delete the Entire Line



If you’ve just typed a long string of commands that you don’t need to enter anymore, delete the entire line by using: CTRL+U,K . That is not easy. CTRL+U deletes whatever is to the left of the cursor and CTRL+K deletes what is to the right. If you are at the end of command, CTRL+U will do. Especially if you start typing password and you make a mistake. Alternatively, you can use CTRL+C , which discards the current typed command, and gives you a new line.

CTRL+L will clear the screen.



Set the Time stamp of a File



touch -c -t 0801010800 filename.c will show the time stamp as 2008-01-01 8:00. The format is (YYMMDDhhmm).



Command to File



fc will open the last command from your shell history in the default editor. You can also specify a text editor. You can add a history line number or the first few letters of the most recent command.

fc -e kate wget

- will open kate with the last shell command starting with wget. You can edit the command, and when you save and close kate, the command will execute.



Ampersand



Ending a command with & runs the command with a new PID, releasing the command line back to you. Useful for running a background process.



Resetting your session



Instead of killing and re-starting your terminal session, you can merely type the command reset . This will reset your terminal back to its defaults, clear the screen, and everything will be as it was before.



Source : Foogazi.com



You have unchartered commands, pls share...



The post got lots of comments across the web. I have compiled the comments and is posting it ...



» Linux Commands I Hardly Knew - Reloaded



See also... » 10.1 Linux Commands I Can't Live Without



» Effective Use of VIM - Part 2



» Effective Use of VIM - Part 1



» Placing Adsense in Blogger Post



» Unlock a PC on Windiows XP ???



» A Hole through the Centre of the Earth

