In the first part of this guide, we looked at some bash tricks that help you find things in the command history. In this section of the BASH (Born Again Shell) guide, we will look at some other functions.
Suffix command history
In the last post, we explained how to append the prefix from the previous command. This method uses the suffix. For example, if you ran the command:
$ !ls -al
You could then use !ls:p to append that suffix automatically:
Insert the last part of a command
You can also insert part of a command from the previous one !$
$ ls -al /home/user/something
Replace it with:
rm -rf !$
This would actually remove /home/user/something
Replace specific text from a command
If you ever make a typo, you can use ^A^B to fix it. For example, if you typed:
$ ls /home/user/somtheing
but you meant to spell “something”, simply enter:
Show directory structure
By using / followed by the tab key twice “/[TAB][TAB]”, you can see the directory structure.
Show commands with specific prefix
If you want to show only commands that have the prefix “mk” for example, you would enter:
And you would get an output like:
mk-build-deps mkfontscale mkfs.ext4dev mkfs.xfs mknod
mkdir mkfs mkfs.jfs mkhomedir_helper mkntfs
As you can see, BASH is extremely powerful, and we have only scratched the surface. Try out some of these and see how a few simple keystrokes can make your server management much easier.