1. Using tab for autocompletion
I’ll start with something really obvious and yet really important: tab completion.
When you are starting to type something in Linux terminal, you can hit the tab key and it will suggest all the possible options that start with string you have typed so far.
For example, if you are trying to copy a file named my_best_file_1.txt, you can just type ‘cp m’ and hit tab to see the possible options.
2. Switch back to the last working directory
Suppose you end up in a long directory path and then you move to another directory in a totally different path. And then you realize that you have to go back to the previous directory you were in. In this case, all you need to do is to type this command:
This will put you back in the last working directory. You don’t need to type the long directory path or copy paste it anymore.
3. Go back to home directory
This is way too obvious. You can use the command below to move to your home directory from anywhere in Linux command-line:
However, you can also use just cd to go back to home directory:
Most modern Linux distributions have the shell pre-configured for this command. Saves you at least two keystrokes here.
4. List the contents of a directory
You must be guessing what’s the trick in the command for listing the contents of a directory. Everyone knows to use the ls -l for this purpose.
And that’s the thing. Most people use ls -l to list the contents of the directory, whereas the same can be done with the following command:
5. Running multiple commands in one single command
Suppose, you have to run multiple Linux commands one after another. Do you wait for the first command to finish running and then execute the next one?
You can use the
; separator for this purpose. This way, you can run a number of commands in one line. No need to wait for the previous commands to finish their business.
command_1; command_2; command_3
6. Running multiple commands in one single command only if the previous command was successful
In the previous command, you saw how to run several commands in one single command to save time. But what if you have to make sure that commands don’t fail?
Imagine a situation where you want to build a code and then if the build was successful, run the make?
You can use
&& separator for this case.
&& makes sure that the next command will only run when the previous command was successful.
command_1 && command_2
A good example of this command is when you use
sudo apt update && sudo apt upgrade to upgrade your system.
7. No more type yes to continue
You can just add the -y flag right before typing in the apt get command.
Example when I need to type yes to continue.
sudo apt-get install apache2
Example when I don't need to type yes to continue.
sudo apt-get install apache2 -y
Speaking about Apache. Do you want to learn how to install Apache on YOUR Ubuntu Machine?? Just Click here!
8. Using alias to fix typos
You probably already know what is an alias command in Ubuntu. What you can do is, to use them to fix typos.
For example, you might often mistype grep as gerp. If you put an alias in your bashrc in this fashion:
This way you won’t have to retype the command again.
I left the last 2 for some amusing commands!
The cowsay command draws out little animals using ascii art in the terminal or shell. It is not very graphical but does a nice job at the drawing. On ubuntu or debian systems you can install cowsay with apt.
sudo apt-get install cowsay -y
Cowsay is a talking cow that will speak out anything you want it to.
cowsay "Hi, How are you" _________________ < Hi, How are you > ----------------- \ ^__^ \ (oo)\_______ (__)\ )\/\ ||----w | || ||
Don't like cows ? No problem there are other animals in the cow zoo. To find out how many, use the l option to get a list
cowsay -l Cow files in /usr/share/cowsay/cows: apt beavis.zen bong bud-frogs bunny calvin cheese cock cower daemon default dragon dragon-and-cow duck elephant elephant-in-snake eyes flaming-sheep ghostbusters gnu head-in hellokitty kiss kitty koala kosh luke-koala mech-and-cow meow milk moofasa moose mutilated pony pony-smaller ren sheep skeleton snowman sodomized-sheep stegosaurus stimpy suse three-eyes turkey turtle tux unipony unipony-smaller vader vader-koala www
cowsay -f ghostbusters Who you Gonna Call ____________________ < Who you Gonna Call > -------------------- \ \ \ __---__ _- /--______ __--( / \ )XXXXXXXXXXX\v. .-XXX( O O )XXXXXXXXXXXXXXX- /XXX( U ) XXXXXXX\ /XXXXX( )--_ XXXXXXXXXXX\ /XXXXX/ ( O ) XXXXXX \XXXXX\ XXXXX/ / XXXXXX \__ \XXXXX XXXXXX__/ XXXXXX \__----> ---___ XXX__/ XXXXXX \__ / \- --__/ ___/\ XXXXXX / ___--/= \-\ ___/ XXXXXX '--- XXXXXX \-\/XXX\ XXXXXX /XXXXX \XXXXXXXXX \ /XXXXX/ \XXXXXX > _/XXXXX/ \XXXXX--__/ __-- XXXX/ -XXXXXXXX--------------- XXXXXX- \XXXXXXXXXXXXXXXXXXXXXXXXXX/ ""VXXXXXXXXXXXXXXXXXXV""
10. The Matrix
sudo apt-get install cmatrix -y
The command cmatrix draws the Neo style matrix on your terminal and makes you feel a little more geekier.
Once installed just type the following:
Wait a couple of seconds and you will see this.
This may cause lag on your screen!!!
To exit just press
CRTL+C and your out!