Posts Tagged ‘ Bash ’

Bash Tips

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

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

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


Bash History: Display Date And Time For Each Command

It comes in handy particularly if there are multiple people maintaining a given server (so you can see when a command was performed) or even if you are the sole maintainer, but can’t remember exactly when you did or changed something.

Edit your /etc/bashrc and append to the bottom:

export HISTTIMEFORMAT=”%h/%d – %H:%M:%S “