If you want to become a true Linux master, having some knowledge of terminal commands is a good idea. Here are four different methods you can use to start teaching yourself.
Tip of the Day
A great way to gradually learn more about terminal commands is to have a “Tip of the Day” style message appear each time you open up the terminal. These messages can tell you about useful commands, as well as advanced tricks for certain commands you may already know. You can easily set this up by going into your .bashrc file (located at /home/<user>/.bashrc) and add the following to the end of the file on a new line:
echo "Did you know that:"; whatis $(ls /bin | shuf -n 1)
That’s all you have to do! If you’d like to make it slightly more entertaining, you can make a cow say all of these tips. To do so, run the command sudo apt-get install cowsay for Ubuntu/Debian or sudo yum install cowsay for Fedora. Then, instead of the code above, add the following to your .bashrc file:
cowsay -f $(ls /usr/share/cowsay/cows | shuf -n 1 | cut -d. -f1) $(whatis $(ls /bin) 2>/dev/null | shuf -n 1)
Sadly, this doesn’t work with all distributions, so your success with cowsay isn’t guaranteed. However, this entire tip uses “whatis” on random commands, which we’ll cover next.
If you don’t want to learn random things, maybe you want to learn about commands you need to use right at that moment. To do this, simply prefix all of your commands with “whatis”. The command should then be able to tell you piece by piece what the command consists of.
A great example whatis sudo yum install cheese, can be seen above. It tells you that sudo gives you administrative rights, yum is the package manager, install tells YUM to install a package, and cheese is the photo booth application you’re wishing to install. It doesn’t quite always work, especially on more complex or less common commands, but it’s still worthwhile to try out if you want to learn what a command actually does.
View All Available Command Options
If you’re using a new command, there are two good ways to take a detailed look at it. The first way is to run the command “man <program>”, where <program> is the name of the program you’re running. So, running “man cp” will tell you all there is to know about the cp command in the man file viewer.
A quicker way to learn the major parts of the command is to run “<program> –help”, where <program> is the name of the program you’re running. So, running “cp –help” will also tell you a good deal of info about the cp command, printed right to the terminal. In other words, –help is the only flag that doesn’t have alternating meanings from program to program.
Crash Course – Yes, Now!
Lastly, you can learn something about command syntax…right here! Knowing the general syntax of terminal commands can help quite a bit in understanding all commands, so it’s worth studying and understanding before you look at specific commands as examples.
All commands share the following structure: [sudo] program [parameter] [parameter] … [parameter] [-flag] [parameter] [-flag] [parameter] … [flag] [parameter]
Let me break down what the above structure means:
- If a command requires administrative rights (known as root access), then they must be preceded with “sudo”, which requires you to enter in your password before the command executes.
- “program” is where the name of the application goes. Application names include yum, apt-get, cheese, tar, cp, mv, firefox, and much more. Unless additional configuration has been done, all programs that are accessible this way have an executable located in /usr/bin. This should apply to all installed applications on your system. For some applications, you just have to write it, and that’s all. For example, you can just type “firefox” and hit Enter, and it’ll launch Firefox.
- Following the program, you can start using parameters and flags. This varies greatly from program to program. For example, the command “cp file1 file2” copies the file “file1” and saves it in the same location with the name “file2”. Those are that command’s two parameters. Some also take flags that modify its behavior – for example, the command “sudo yum install cheese -y” has “install” as a parameter to yum, “cheese” as a parameter to install, and “-y” as a flag to yum saying that it should assume yes for all instances where it would normally ask you if you’d like to continue. While this example doesn’t show it, some flags don’t require their own parameters, and some flags do. Each program has its own set of flags and meanings, which you’ll learn over time through repetition.
Learning terminal commands really isn’t that hard – once you get going and understand how they generally work and are structured, learning others will become a lot easier. If it doesn’t make sense after a few hours, don’t give up. Repetition is your best friend, and you’ll start seeing the patterns eventually. From there, it’s all about memorization through practice. We also have various other resources for learning commands, such as this Linux command cheatsheet, the 40 essential Linux commands, and another quick intro to Linux commands.
What tips do you have for others who are trying to learn? Do you know of a command that does something cool or is just for fun? Let us know in the comments!