Sooner or later, we all realize, that no matter how elegant and intuitive the GUI appears, getting familiarized with the CLI (Command Line Interface) never hurts, right? For example, a couple of years ago we were taught MS DOS (Command Prompt) at school, and I really got fascinated with it. Ubuntu's Shell is the equivalent of Windows Command Prompt, but rest assured, shell is way more powerful and versatile than command prompt can ever hope to be. Windows Powershell, compared to that, is somewhat closer to shell in its versatility, but for me it's shell any day.
In a future post, I'll try to describe shell in greater detail, and give some examples showing how and why it is powerful. And believe me, once you practise a bit, and learn the value of task automation with commands such as at, sleep, crontab etc you wouldn't want to get back to GUI programs.
For now, treat this article as a ready reference for Linux commands. I'll post it as a series of article, listing 10 commands each time.
How to start shell?
Shell is essentially the thing that runs inside the terminal, and it's also called the console. More or less, they can be treated as the same thing, for now, although there are some subtle differences. Ubuntu (and most other Linux distros) allow us a multitude of options of dealing with shell. The most common, is the use of the dedicated Terminal program that you have preinstalled.
Just go to unity's dash (or press the Window key on your keyboard) and dash comes into view. Or else, if you're using an old-time menu, just go to Menu=> Applications=>Terminal.
HINT: For quicker access, you can assign a keyboard shortcut to launch the terminal. By default, it's Ctrl+Alt+T, but you can change it easily with keyboard shortcuts.
![]() |
| Here's my favourite one, cowsay! :D |
30 useful shell commands (that I find very useful)
Ok, so there can be thousands of shell commands, because you can create your custom commands with it. Essentially, those commands are scripts that you write, and add to the system. I'll describe the process, but in a separate and more detailed post. For now, let us focus on the builtin shell commands.
HINT: Before we begin, let me quickly tell you about 2 very powerful and helpful commands, whatis and man. The first has a syntax: $ whatis <commandname> and it returns a single-line definition of the command. For example typing $ whatis cp will tell you about the cp command. And man is even more powerful! It gives you a whole article on each command, and serves as a handy manual for them. The syntax is similar, $ man <commandname>. Feel free to use them both, as you explore these basic commands.
alias
The Alias command is a versatile and powerful utility, that helps you create custom commands. For example, the date command is used to display the current date and time, and say you'd like to make a duplicate, say whatstheday. For that, you have to enter:
$ alias whatstheday=date
Mind the gaps, extra spaces would return errors. And the $ symbol is just the prompt, it's already there and we needn't write it.
Now, if you enter whatstheday and press ENTER, the current time and date are shown.
arch
This command is a simple but useful one. It shows you the architecture of your machine. Not very helpful on our own computers, though, but while checking someone else's computer that you are to fix, it's useful.
For example, my machine (like most others) runs i686, i.e Intel Pentium Pro. For a brief overview of architectures, you can go HERE (courtesy: Mr. Arun GP).
at
This is a very important command, which is used to schedule your commands for automatic execution by the system at a specific time. By default, Ubuntu doesn't have it installed, so you can enter sudo apt-get install at to get it installed. I'll describe it in detail at a later time, while touching on the concept of automation, but for now, here's a quick example.
First, install festival (a text-to-speech synthesizer for Linux) using
sudo apt-get install festival
And then, enter the following commands:
$ at <time>
> echo "Hello, this is your computer talking" | festival --tts
<Ctrl+D>
Now, after at, you enter the time at which you'd like your command to get executed. It may be 14:02 am, or 23:08, for that matter. Also, after you enter your commands (after each command, press enter and a new line following a > will start), end the at process using Ctrl+D combination. That schedules the job for execution.
For my fellow Indians who've watched the movie Kahaani, at is like our next door friendly assassin Bob Bishwas, right? ;)
cal
Well, this is rather easy. cal simply displays a calendar on your terminal, and the current date is highlighted. Not very fancy, but it's kinda geeky anyway. Especially because you can use it to view the calendar of any month, any year!
Just enter
$ cal 1 2100
And you'll see the calendar for January, 2100! Way faster than using an actual calendar.
cd
cd refers to change directory. It is a frequently used command, used to navigate from one directory (folder) to the other while using the terminal or shell. When you start the terminal, usually your home folder is opened, whose address is /home/<yourusername>. But using cd, you can move back and forth between folders and paths.
For example, say you have a folder named music (everyone does, eh?). Then, to move inside music, you have to type:
$ cd music
Your prompt changes immediately, showing that you're inside music directory. Again, to come back to your home folder:
$ cd /home/<yourusername>
Here, ~ is a nomenclature for your home folder's path. Two important ways of using it are:
$ cd ..
(switches to the higher directory, from /home/anirban/example to /home/anirban, and from /home/anirban to /home, for example)
$ cd ~
(takes you back to your home folder)
chmod
This command is used to change the permissions of any file or directory. And thus, it is quite useful (but advanced) in its own regard. You can use GNOME's GUI tools to basically do the same task, but when you have a large number of files and folders etc to change the permissions of, or would like to automate the process, or would want to write a script that does it for your friend, chmod is the way to go.
While using chmod:
u => user
g => group
a => all others
r => read
w => write
x => execute
For adding permissions, + sign is used, and - is used to remove permissions.
For example, let there be a file called readme.txt, inside your home folder. Then,
$ chmod ug+rw readme.txt
This gives read and write (i.e modify) permissions to the user (i.e you) and your group. So, you won't be able to access (read or modify) the file.
clear
It's quite self-explanatory, the command just clears the screen of your terminal, allowing you a better.
cp
cp command is used to copy files or directories. The most common syntax is:
$ cp <file1> <file2>
where <file1> is the original file, and <file2> is the copy. You can specify the address of the files, and <file2> is newly created. It becomes useful especially with wildcards, such as:
$ cp *.mp3 /home/anirban/Music/Songs
The above command, for instance, copies all mp3 files from the current location, to the folder Songs under Music on my home folder.
date
As already described in the example of alias, date simply returns the current date and time. It is a versatile command, documenting all of it requires a whole article dedicated to it, but here are some examples:
$ date -u => shows the current GMT
$ date +'%m' => shows the current month
$ date +'%Y' => shows the current year
And so on. Obviously, this is just barely scratching the surface.
dir
This command is similar to its DOS equivalent. To see the contents of the directory, we usually use it. Use the man dir command to know more about it.
Conclusion
Well, that's it for now. BASH commands are many, and it'll take a while to document them all (most of them, I mean). In future articles of this series, I'll list more of them, 10 at a time, and we all can practise them together.
Most importantly, we need to practise with these commands, to ensure that we innately know how to tackle any real-life problem with the power and flexibility of BASH.
Image Credits
Pixabay
Distrowatch.com


No comments:
Post a Comment