Obscure Linux bash shell tricks and tips.

Posted: January 18, 2018. At: 9:35 PM. This was 1 month ago. Post ID: 11751
Page permalink.
WordPress uses cookies, or tiny pieces of information stored on your computer, to verify who you are. There are cookies for logged in users and for commenters. These cookies expire two weeks after they are set.

A very cluttered network setup.
A very cluttered network setup.

There are a lot of obscure shell tricks for the bash shell that are useful for showing off shell tricks and making your shell usage easier.

For a first example, run this command.

ubuntu ~ $ ls -hula

Then run this and the previous command parameters will be applied again.

ubuntu ~ $ ls !:*

This is one very cool trick.

To re-run a previous command, use this trick.

ubuntu ~ $ !!

Or if you forget to use the sudo command.

ubuntu ~ $ sudo !!

This is another way to rerun a command like ls -hula.

!:0 !:*

If there are 2 arguments to the command, then use this.

!:0 !:1-2

This also works, get the last executed command and all parameters.

ubuntu ~ $ !:t:r:p
ls -hu -la

Another way to add the previously used command-line parameter like -hula to the ls command is by pressing the Alt key and then the . key. This will paste the previously used command line parameters onto the command. If you keep pressing it, it will go back in the history. Good if you wish to get parameters from 3 commands back.

Run this command on the bash shell; and the previous command will be run again.

ubuntu ~ $ !:h

Another way to get a previously run command.

ubuntu ~ $ !!:0
ls
3aa21b8c106cab742bf1f20d60629e3f                                                                             index.html                    openvpn
74567486745764985674876397573487563653874653875634865378653653485364753748653465348765348653865348756487365  index.html.1                  out.gif
account.sh                                                                                                   ip2.c                         out.txt
a.out                                                                                                        ip.c                          pass.out
bae64                                                                                                        ipinfo                        pentestlab.txt
bandit14.txt                                                                                                 jail                          results.xml
base64                                                                                                       john.conf                     rockyou.txt
boards.4chan.org                                                                                             key.key                       root.jpeg
capture.log                                                                                                  keys                          SAM
chan.c                                                                                                       libhd16_16.0-2.2_amd64.deb    SECURITY
clock.txt                                                                                                    libhd21_21.6-1_amd64.deb      shellcode.c
crunch-3.6                                                                                                   linux-4.13.11.tar.xz          sycall.c
crunch-3.6.tgz                                                                                               linux-4.13.11.tar.xz.1        SYSTEM
Documents                                                                                                    loop.c                        test.gz
easy-rsa                                                                                                     mempodipper.c                 testingunit
echo                                                                                                         metrosexual.zip               tmp
gtl.out                                                                                                      my2.text                      uptime.py
guru.sh                                                                                                      my.text                       uudecode
hackme                                                                                                       my.txt2                       vim
hash                                                                                                         nmap-log-54.159.49.238-.txt   vpn.sh
hash.txt                                                                                                     nmap-log-healthcare.gov-.txt  xyz-wordlist.txt
hwinfo_16.0-2.2_amd64.deb                                                                                    nohup.out
id_rsa.pub                                                                                                   nt

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

Leave a Reply