Friday 8 March 2013

Bash Tips


SHELL CONTROLS

Ctrl l Clear screen
Ctrl a Beginning of command line.
Ctrl e End of command line.
Ctrl r Reverse search history.
Ctrl k Delete to the end of the line.
Ctrl u Delete to the beginning of the line.
Ctrl y Insert the deleted.
Ctrl _ Undo command line edit.
Ctrl p Previous command.
Ctrl n Next command.
Alt t Switches first and second word.
Alt f Forward one word.
Alt b Backward one word.
Alt d Delete forward one word.
Alt Last Argument.
!X Execute last command started with X.
!4 Repeat the 4th command in history.
!$ Last argument.

pageup First command in history
^word1^word2 Substitute word1 with word2 in previous command

COMMANDS
ls -ld */ Lists all the directories.
mv /home/user/public_html/directory1/directory2/badscript.php{,.old}

VARIABLES
echo $RANDOM gives a random number.
echo $? gives the exit status of last process executed.
echo $_ echo the last argument.

ESC . last argument