Welcome to the second installment of our Basic Linux Commands. In the last guide we went over ten of the most basic commands for getting around the console. This guide will continue down the same path and talk about file locations, filetypes and more. Lets get started.
1. su = As you may have noticed, while moving around in linux and trying to access certain files, you do not have permission to access, modify or delete a lot of things (if you are logged in as root I suggest logging out and logging back in as a normal user. You should not use linux as root unless it is necessary). The su command is there so that you can become the superuser (root) temporarily if you need to do something that requires root permissions. To temporarily become root type in su and hit Enter. A password prompt will come up. Type in the root password and hit enter. You will not see anything on the screen as you type but after you hit enter you will get a new prompt like this:
[email protected][~]$ su Password: [email protected][nugod]#
The easiest way to know if you are running as root is that your command prompt will have a # instead of a $. When you are through using the root privledges simply type exit and hit enter. You will be switched back to a normal user. You can also switch to any other user by using su. Simply type su username and hit enter. You will be asked for that users password. Key it in and hit enter and you will have that users permissions until you key in exit and hit enter.
2. file = You may have also noticed that files in linux do not always have an extension like they do in windows. A text file may end in .txt,.sh,.anything or nothing at all. If you ever need to know what kind of file something is simply type in file /path/to/file and hit enter. This will tell you the file type. For example to find out what filename.sh is in the directory I am currently in I do the following:
[email protected][~]$ file filename.sh filename.sh: ASCII text
Now I know that filename.sh is a text file.
3. locate = Sometimes you need to find a file that is on your linux system. The locate command is a super easy way to do that. The locate command uses a database of all the files on your system to tell you a file is located. Before using locate you will need to run another command first. Switch to root by using the su command described above. Once you are using root type in updatedb and hit enter. This may take a few minutes as it is basically indexing your entire drive. Once it is done (you will know because the command prompt will reappear) type exit and hit enter because you don’t need to be root to use locate. Note:You don’t need to updatedb each time you use locate but you will want to do it occasionally if you add a lot of new files. Now you can use locate. Type locate grep and hit enter (grep is a command you will learn about later). You will now see lots of text whizzing by. These are all of the locations on your hard drive where there is a file containing grep in the name. Since you are probably in a “Konsole” window you will easily be able to scroll up to read all of the locations.
4. find = Another way to locate files on your hard drive is by using the find command. The usage for using find to locate a file is find [path] -name [filename]. Type in find / -name grep and hit enter. You will see something like this:
nug[email protected][~]$ find / -name grep find: /lost+found: Permission denied
You will see a “Permission Denied” line for every directory it looks in that you do not have access to. If you want to run it as root then those lines will go away and you will only see the locations for grep. I personally prefer locate as the output is easier to read through but the choice is always yours.
5. tar = The tar command is used to interact with archive files. To extract tar.gz files type tar xvzf /home/-insertyourusernamehere-/filename.tar.gz and hit enter to extract the filename.tar.gz archive file. It will extract into the directory that it is located in. If it was a tar.bz2 file you would use tar xvjf /home/-insertyourusernamehere-/filename.tar.bz2 instead. Ark is the GUI program for dealing with archive files but it is good to know the command line way as well.
We will stop at five commands in this guide since these commands are a little more involved. As always you can find extra options for any of these commands by typing commandname –help at the command prompt. In Basic Linux Commands 103 we will start looking at file permissions and groups.