Misc BASH shell tricks for the Linux user.

Posted: August 27, 2012. At: 10:57 PM. This was 5 years ago. Post ID: 4502

To recall the last entered command on the Linux console, press the Ctrl-P key shortcut. You may also press the up arrow to recall the command, but the Ctrl-P shortcut is another good way to perform this feat. The CTRL-A shortcut will jump to the beginning of the line you are currently typing and CTRL-E will jump to the end. Use the CTRL-L command to clear the screen, this is similar to the clear command. There are more shortcut examples for the BASH shell here: http://www.howtogeek.com/howto/ubuntu/keyboard-shortcuts-for-bash-command-shell-for-ubuntu-debian-suse-redhat-linux-etc/.

Superimposing the arguments of the last command into the next… Using the $_ argument.

[email protected]:~$ ls -ahu
.ICEauthority        .              .xsession-errors.old  pcx2.ppm    .chocolate-doom  Music     .icons                     .bashrc    .local    .bash_logout
.Xauthority          .bash_history  .selected_editor      pcx1.ppm    .nv              Public    .themes                    Desktop    .presage  .config
.xsession-errors     DOOM00.png     doom2.png             DOOM01.pcx  Documents        Pictures  .mozilla                   Templates  .profile
.nvidia-settings-rc  .gconf         doom1.png             DOOM00.pcx  Downloads        Videos    .sudo_as_admin_successful  .cache     ..

Then running the ls command with the previous arguments.

[email protected]:~$ ls $_
.ICEauthority        .              .xsession-errors.old  pcx2.ppm    .chocolate-doom  Music     .icons                     .bashrc    .local    .bash_logout
.Xauthority          .bash_history  .selected_editor      pcx1.ppm    .nv              Public    .themes                    Desktop    .presage  .config
.xsession-errors     DOOM00.png     doom2.png             DOOM01.pcx  Documents        Pictures  .mozilla                   Templates  .profile
.nvidia-settings-rc  .gconf         doom1.png             DOOM00.pcx  Downloads        Videos    .sudo_as_admin_successful  .cache     ..

This is a very useful shortcut if the command-line arguments were very long and you do not wish to retype them again. I found this useful tip here: http://stefaanlippens.net/node/54. If you append an & character to the end of a command in the terminal exempli gratia the xterm command to load another terminal, it will relinquish control of your terminal and you will still be able to type in the original terminal as well as the new one. For example you would type xterm & and the xterm will load from the existing terminal and give it back to you. The CTRL-R key shortcut will allow you to search the command history for a certain command and execute it. Below is what the command search prompt looks like.

(reverse-i-search)`l': ls -ahul

No comments have been made. Use this form to start the conversation :)

Leave a Reply