Command Line ExamplesFirst, an example to show why we might even bother learning the command line:
This tells the du command to show disk usage to a maximum depth of two directories, all the directories in the /usr directory. Then send the output of that to the sort command, sorting them numerically, in reverse order, and then send that to the less command to page them in case there are too many to view on a screen. There may be a GUI program to do that, but these commands would be available on virtually all Unix, Linux, or similar operating systems. If your disk is getting full, this would help you find where you might be able to delete some files. In all of our examples, unless we say otherwise, press Enter at the end of the red command line. Moving about
The pwd command shows you where you are in the directory tree. We will see why this is handy later.
The cd command allows you to change the working directory. If you type cd by itself it will take you back to your home directory. The command cd .. will take you up one level to the parent of this directory. In fact, the two dots signifies the parent directory, and a single dot means the current directory. To return to the directory where you were before this, type cd - Exploring files and directories
Wow! What did that do? We first used the mkdir command to create a new directory named examples. We already had a link to a directory named Examples, but remember filenames and directories in Linux are case sensitive, so that is OK. Then we told the cp command to copy, recursively and verbosely (show us what it is doing), everything from the Examples directory into the examples directory we made. That gives us some examples we can actually change. Finally we used the cd command to change into the directory we made. And to be sure where we are, we used the pwd command again.
We used the ls command to list the directory. Then we told the mv command to move the file ubuntu Sax.ogg to the filename ubuntu_sax.ogg which means rename it. Then we used the ls command again, but this time we told it to give a -l (long listing).
This copies a file called words from where it was into our working directory.
The alias command by itself lists all the aliases we have created. The one that was there was to make the ls command show certain filenames in color. Then we defined ll as an alias for ls -l so it will be easier to show a long listing. Then we tested the alias we had created.
For the last line, you could have pressed the Up Arrow key twice to get the same command from the command history. This is very handy, along with command and filename completion.
Here we made a new directory named ooo and then we used the mv command to actually move files rather than rename them. Then we asked for a long listing of the working directory.
We used the chmod command to remove the read permission from the ubuntu_sax.ogg file, for others who are not ubuntu or in the ubuntu group. How would you know how to use chmod? Well, we could check the manual page:
System information
The df command shows us how much is free on all our mounted file devices (something like drive letters on Windows).
The free command shows us how much memory is free. We asked for it in megabytes. The next one will show lots of information about running processes (programs) and more, that changes about every second. Press q or Q to quit:
Has anyone ever asked which kernel you are running? No? Well, in case they do, you can do this:
You might one day need some information about your network:
Searching and greppingSuppose you are looking for a file that has to do with the spelling dictionary in OpenOffice. There are a lot of files to look through, but we can use some powerful commands to help:
Whoa! Too many. The locate command found 3789 files.
The grep command got us closer. We are down to a few files that we could check.
|
This page is This page rendered by CodeIgniter in 0.0511 seconds. |