The Handy Linux Commands You Should Be Aware Of
I remember myself when first starting to learn about linux and unix that i was pretty intimidated about the several unix commands and how i would go about using them. It was a pretty long going process before getting used to them and so i thought that it would be nice if i wrote a post describing what are the various linux commands or tools that i tend to use almost everyday.
As you can understand, learning about linux commands really requires that you spend some time on them and practice through the various system administration jobs that you can do on your system. However, i think it would be a nice idea to enlist what i feel is most important and describe some of the important aspects of these commands.
Note that i will be describing what i feel is really important for beginners in linux or unix. Your point of view may differ from my own and you may feel that i should be describing other commands or i should also be including some more. I understand that there would be really a lot of handy commands that you can suggest, but please bear in mind that this resembles my experience on what i feel is important. Also, i cannot really be writing about everything and there is a chance that i forget something important, so please bear with me
Before going any further, i would suggest that you take a look at this tutorial i wrote a while ago that will introduce you to the unix commands and ideas.
The File and Directories Operation Commands
The first things that every user should know on linux is how to change directories, create, move and delete files. Luckily these commands are very easy to execute and also very easy to remember :
ls – The handy ls command that you easily remember if you remember the word list. Mostly used as ‘ls -al’ to list the files with long details and also list hidden files (-a as in all). Note that “ls -al” alone would print the contents of the current folder. You can also specify something like “ls -al ~/Desktop” that would actually list the files on your Desktop.
pwd – Print Working Directory to just print the directory you are in currently at your shell. Not used much, but important to know
cd – Change Directory used like “cd Directory”. The character “.” is used to specify the current directory and the character “..” is used to specify the previous directory. Also, in case you need it, “cd -” changes to your previous working dir.
mkdir – Creates a new directory. Used like “mkdir ../newdir” that will create a new dir called “newdir” in the previous dir of your current one.
rm – Removes files or folders. Use as ‘rm -r foldername’ to remove folders and its subfolders. Also use ‘rm -f’ to force the delete.
touch – Creates a new file
chmod – Changes the permissions of a file. I will not be discussing permissions in detail but i will say that you do not have to use numbers like 755 to change to certain permissions. Just use r for read, w for write and x for execute. Also use u for user, g for group and o for others.
Therefore, if you need to give read permissions to your group you can do something like (give with +, remove with -):
chmod g+r folderName
Use -R to do it recursively, thus changing to these permissions for all these files. Chmod is a command that needs lots of explanation and it’s one of those commands that a whole post can be written for. Maybe i will elaborate in the future and also explain more about permissions.
cp, mv – CP for copy and MV for move. Copy is used just to copy a file and move is used to cut the file and paste it to another location. The syntax is like :
cp source target mv source target
So, you first specify the file that you want to copy and then the destination that you want to copy it to. How to remember that ? This is what i do. Source starts with an S, target starts with a T. S comes before T so it’s the first operand. Funny, but it works. However, if you are a casual linux/unix user you would just know without even thinking of that trick.
cat – Comes from the word catalog. It actually shows the contents of a file to the standard output(the shell). Used like “cat filename”.
tail, head – Used to appear the last 10(tail) or first 10(head) lines of a file. “tail -f” variation is very much used to display the changes of a file in real time.
grep – An incredibly versatile command that is used in order to find certain patterns of text in a file. I’ve written a pretty detailed post about grep usage by examples here.
find – A very important and versatile command that i will be surely writing a separate post for. It’s used to locate folders and files in your system but it is very powerful and can be used in lots of circuimstances for various tasks.
tar, bzip2, gzip – Used to compress files. Extensively discussed in this post about how to use tar, gzip and bzip2 to compress files under the unix shell.
More Generic Commands
ps – Lists the processes of your system, mostly used as “ps aux” an then fed to grep like “ps aux | grep svn” that would in this example check if svn is actually running.
top – A great utility that lists the processes of your system and gives details about their cpu, ram usage and more.
ssh – The powerful remote shell command that allows you to connect to a computer remotely. If you use it, make sure that you have also generated your own ssh keys to simplify authentication process.
As i said there are many more commands that one could describe, but i feel this are sufficient for beginners. I’ll be seeing you soon in the next post, till then, take care