-rw-r--r-- 1 paul paul 18691 2007-11-12 21:34 COPYING
-rw-r--r-- 1 paul paul 88167 2007-11-12 21:35 CREDITS
drwxrwxr-x 2 paul paul 4096 2007-11-12 21:35 crypto
That output shows four matches and prints a lot of information about each of them. The first row shows the arch
directory; you can tell it is a directory because its file attributes start with a d. The rwxrwxr-x
following that shows the access permissions, and this has special meaning because it is a directory. Read access for a directory allows users to see the directory contents, write access allows you to create files and subdirectories, and execute access allows you to cd
into the directory. If a user has execute access but not read access, he can cd into the directory but not list files.
Moving on, the next number on the line is 24
, which also has a special meaning for directories: It is the number of subdirectories, including .
and ..
. After that is paul paul
, which is the name of the user owner and the group owner for the directory. Next are the size and modification time, and finally the directory name itself.
The next line shows the file COPYING,
and most of the numbers have the same meaning, with the exception of the 1 immediately after the access permissions. For directories, this is the number of subdirectories, but for files, this is the number of hard links to this file. A 1
in this column means this is the only filename pointing to this inode, so if you delete it, it is gone.
Fedora comes configured with a shortcut command for ls -l
: ll
.
The --sort
parameter enables you to reorder the output from the default alphabetic sorting. You can sort by various things, although the most popular are extension (alphabetically), size (largest first), and time (newest first). To flip the sorting (making size sort by smallest first), use the -r
parameter also. So, this command lists all .ogg
files, sorted smallest to largest:
$ ls --sort size -r *.ogg
Finally, the -R
parameter recurses through subdirectories. For example, ls /etc
lists all the files and subdirectories in /etc
, but ls -R /etc
lists all the files and subdirectories in /etc
, all the files and subdirectories in /etc/acpi
, all the files and subdirectories in /etc/acpi/actions
, and so on until every subdirectory has been listed.
Reading Manual Pages with man
Time for a much-needed mental break: The man
command is easy to use. Most people use only the topic argument, like this: man gcc
. However, two other commands that are very useful work closely with man
— whatis
and apropos
.
The whatis
command returns a one-line description of another command, which is the same text you get at the top of that command's man page. For example:
[paul@caitlin ~]$ whatis ls
ls (1) - list directory contents
The output there explains what ls does but also provides the man page section number for the command so that you can query it further.
On the other hand, the apropos
command takes a search string as its parameter and returns all man pages that match the search. For example, apropos mixer
gives this list:
alsamixer (1) - soundcard mixer for ALSA soundcard driver
mixer (1) - command-line mixer for ALSA soundcard driver
aumix (1) - adjust audio mixer
So, use apropos
to help you find commands and use whatis
to tell you what a command does.
Making Directories with mkdir
Making directories is as easy as it sounds, although there is one parameter you should be aware of: -p
. If you are in /home/paul
and you want to create the directory /home/paul/audio/sound
, you get an error like this:
mkdir: cannot create directory `audio/sound`: No such file or directory
At first glance, this seems wrong because mkdir
cannot create the directory because it does not exist. What it actually means is that it cannot create the directory sound
because the directory audio
does not exist. This is where the -p
parameter comes in: If you try to make a directory within another directory that does not exist, as in the previous example, -p
creates the parent directories, too. So:
$ mkdir -p audio/sound
That first creates the audio
directory and then creates the sound
directory inside it.
Moving Files with mv
This command is one of the easiest around. There are two helpful parameters to mv
: -f
, which overwrites files without asking; and -u
, which moves the source file only if it is newer than the destination file. That's it!
Listing Processes with ps
This is the third and last 'command that should be simple, but isn't' that is discussed here. The ps
command lists processes and gives you an extraordinary amount of control over its operation.
The first thing to know is that ps
is typically used with what are known as find
,' we discussed UNIX-style, GNU-style, and X-style parameters (-c
, -- dosomething
, and -dosomething
, respectively), but BSD-style parameters are different because they use single letters without a dash.
The default use of ps
therefore lists all processes you are running that are attached to the terminal. However, you can ask it to list all your processes attached to any terminal (or indeed no terminal) by adding the x
parameter: ps
x. You can ask it to list all processes for all users with the a
parameter or combine that with x
to list all processes for all users, attached to a terminal or otherwise: ps ax
.
However, both of these are timid compared with the almighty u
option, which enables user-oriented output. In practice, that makes a huge difference because you get important fields such as the username of the owner, how much CPU time and RAM are being used, when the process was started, and more. This outputs a lot of information, so you might want to try adding the f
parameter, which creates a process forest by using ASCII art to connect parent commands with their children. You can combine all the options so far with this command: ps faux
(yes, with a little imagination, you spell words with the parameters!).