Nontoxic Commands

 < Day Day Up > 



As you now know, all of this typing is easy enough, but in order to actually do something useful with your Terminal, you need to type commands, and there are more of them than you could ever hope or need to know. To get you started, we will begin with some commands that are easy to understand, nontoxic, and completely child-friendly.

$ whoami

There is no command as easy, safe, and even as seemingly useless, as whoami. Rather than help those with multiple-personality disorders discover who they are at any given moment, the whoami command simply tells you what user is currently logged in. Try it out by typing whoami after the $ and then pressing the ENTER key. Remember that commands are case sensitive, so type accordingly. The Terminal will now tell you the username of the person currently logged in. If you are logged in as frog, you should get frog as the answer to your command.

$ pwd

If you essentially know who you are but aren’t exactly sure where you are, the pwd command (print working directory) should come in handy. The pwd command tells you exactly where the Terminal is in your directory tree.

Let’s say, for example, that my Terminal is in my rg Home directory when I use the pwd command; I would, after pressing the ENTER key, get /home/rg printed to my Terminal. You should get similar results if you try it out.

Note 

The word print, in this case, has nothing to do with your printer; it merely means that the response will be printed to, or displayed in, the Terminal.

$ df

Another safe and easy, but much more useful, command is df (disk filesystem). The df command tells you how much disk space you have used, as well as how much space you still have available, on each of the partitions on your various mounted disks. Try it out by typing df and then pressing ENTER. Your output should look something like that shown in Figure 9-3 (depending, of course, on the size of your mounted disks and how they are set up).

click to expand
Figure 9-3: Output from the df command

As you will notice, the sizes are given in kilobytes (KB) rather than the GB (gigabytes) and MB (megabytes) you are probably more used to, but there is a way around this. Many commands accept a flag, or option, to further instruct the command how to perform. These flags are written directly after the main command and are preceded by a space and a hyphen.

In this case, you can try using the -h (human readable) flag to have your figures come out in the way you are most familiar with. Try this out by typing df -h on the command line and pressing ENTER. The output should now appear in a more familiar format (see Figure 9-4).

click to expand
Figure 9-4: Output from the df command with the -h flag

$ ls

Another harmless but handy command is ls (list directory contents). The ls command shows you what is in your current directory. This is the non-graphical equivalent of double-clicking a folder in Nautilus to see what is inside. Try it out by typing ls and then pressing the ENTER key.

If you’ve been following my commands so far, your results should list all of the folders in your Home directory. You can also use the -R flag to show not only the list of files in the folder, but also what is within the subfolders. Of course, you should have no subfolders in any of the folders you created in Chapter 5, so you can hold off experimenting with this for a while. Instead, try typing ls -a to see your invisible, or hidden, files.

$ su

When you have to change from being a normal user to being the root user, there are two simple and straightforward steps involved. Open a new Terminal window by clicking the Terminal launcher in your Panel, and then type su and press ENTER; you will be asked for your root password. As you type your password, the password itself will not appear in the Terminal, but that is how things are supposed to be, so don’t panic. When you are done, press the ENTER key and the prompt you usually see in your Terminal, [username@localhost username]$, will be replaced by your root prompt: [root@localhost username]#. Notice that instead of a $ at the end of the prompt, you now have a # instead, which indicates that you are in root mode.

As you can see, you are now root, but you are still in your Home folder. If you change to root while in a different folder, such as [username@localhost multimedia]$, the prompt will similarly be in a different folder: [root@localhost multimedia]#.

# exit

You can get out of root and back to your normal user mode by using the exit command. Just type exit and press ENTER and you will become your old self in user mode again. Very simple and handy. If you use the exit command while in user mode, you will exit the Terminal window.

$ locate

In contrast to the seemingly lightweight commands you have learned so far, the locate command is really quite useful. In fact, you might well find it a much easier, faster, and more effective method of finding files than the graphical search tool in the Main menu. Using the command is quite easy: You simply type the command followed by a space and the name of the file you are searching for. You can use this command in either root or user mode.

Before you can use this command, though, you will need to create a database of filenames for locate to use. This is quite easily done by becoming root using the su command, which you just learned in the previous section, and then typing in updatedb (Whoa, Nellie! Yet another command!), followed by a tap on the ENTER key. It will seem that nothing is happening for a while, but don’t worry. As long as the cursor in your Terminal is blinking, progress is being made, and when your root prompt returns, you will have successfully created the database file. After that, you can go on and use the locate command.

  1. To take this new command out for a test-drive, let’s look for the kolf.png file that we searched for via the graphical search tool in Chapter 3. Just type in locate kolf.png and press ENTER. Your results should look like those in Figure 9-5.

    click to expand
    Figure 9-5: Results of your locate search



 < Day Day Up > 



Linux for Non-Geeks. A Hands-On, Project-Based, Take-It-Slow Guidebook
Linux for Non-Geeks: A Hands-On, Project-Based, Take-It-Slow Guidebook
ISBN: 1593270348
EAN: 2147483647
Year: 2003
Pages: 188

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net