This section will contain a description of the Unix commands in the form of a FAQ, Titles will be things like: ``how to copy, move and remove files'', ``finding files by name'',etc.
Unix programs that will be discussed are:
basic: ls, cd, mkdir, rmdir, mv, rm, cp (recursive), more or less find,
grep, top (ps), scp, ssh, emacs, nedit, apropos, man, wc, wget, sort,
cat, diff
Directory and folder are two names for the same thing. Think of a directory as a special place where you can put files or even another directories. This resource helps you to organize your files and should be used extensively.
Any permanent information in located inside a directory. The main one is called ``root'' and referenced by '/'. Directories within other directories are indicated by separating the names with '/'. For instance, '/var/spool/mail' refers to the folder 'mail' which is located inside 'spool' which in turn is inside 'var'. 'var' is in the root directory.
When you are using the computer, you are always ``seated'' at one directory -- we call it your current directory. When you log in, you are placed in your ``home'' directory, which usually is /home/[your login name].
A file, and even a folder, may appear in more than one directory, using a 'shortcut' or 'link', see the ln command.
The command ls shows all the files and directories located in the current directory.
If you want to list another directory, just pass it as an argument
to ls:
EXEMPLOS
You can also restrict the list to a subset, using '*' for any part
of the name, '?' for any letter and '[...]' for some a limited set
of characters.1.5
EXEMPLOS
To create a new directory use the command mkdir and the
directory name as its argument. You can create more than one folder
in the same command.
EXEMPLOS
Use rmdir, but be aware that the directory must be empty.
You can remove more than one in the same command line.
EXEMPLOS
You can also remove a directory and all its contents quickly by using rm -f, but this is very dangerous, since you can potentially erase large amount of data without the possibility of recovery. Only try this one if you are absolutely sure of what you want to do.
EXEMPLOS
The current directory is the one you operate by default -- it is your ``working directory''. For instance, when you execute ls without arguments, it will list the files in the current directory. You can verify which one is it with the command pwd (print working directory).
To select another working directory use the command cd
(change directory). Just pass the new folder as an argument.
The command rm permanently removes a file -- use with care!
You can specify sets of files exactly in the same way you do with
the ls command.
Use the mv command. Pass the list of files and/or folders you want to move in the command line. The last argument must be the destination folder.
You can specify sets of files and folders as you do in the ls command.
Use the mv command (the same used to move files). The first argument is the name of the file or folder and the second must be the new name.
You can copy files using the cp command. The last argument is
the destination. You can copy a set of files to a new directory
or make a new copy of a single file.
EXEMPLOS
If you use the '-r' option you can make a recursive copy. This means you can copy a directory and all its subdirectories to a new location.
The simplest way to find a file is using the locate command, but it is not always implemented. It is fast and uses a database to get the information. This database is updated periodically and may not be up to date when you execute the program.
The safer, but much slower method, is using the program find. It actually searches all directories for the name you provide.
Since find can do a lot more than just look for files, its syntax is a bit complicated, but the basics are easy to master. Here we will show how to use it to find a file by its name. To do that, just follow this template:
The rest of this section will talk about text files
To view the contents of text files there are a few options. cat just copy the file to the output. If the file is short this a quick and good way.
more shows the file one page at a time. You can browse the pages back and forth and even search for patterns.
less is just another version of more, a bit more sophisticated. It is not always present, and in some implementations both programs are the same.
grep will take any string as its first argument and print
all the lines which contains that string in the files given by the
following arguments.
EXEMPLOS
The string may be a ``regular expression'', which is a compact way to describe a set of strings -- see the grep man page for details.
The program wc (word count) prints three numbers: the number of
(complete) lines, words and characters for each of the files given
in the arguments. If more than one file is given, an extra line
with the total counts is appended.
EXEMPLOS
ls -l will give the total size of the files, among other information, like ownership and last modification date.
sort will print the lines sorted in lexicographic order, if
you use '-n' they will be sorted by numerically.
EXEMPLOS
The comparison starts at the beginning of each line. To sort by
another part of the line, use -k position as an argument.
position indicate the word in the line you want to use. 1 is
first, 2 is second, and so on. Words are separated by whitespace.
This option is particularly useful if you want to sort a table by
one of its columns. To use another separator instead of whitespace,
specify it with the '-t' option.
EXEMPLOS
The best way to compare two large and similar text files is to print only the differences between them. This is exactly what the diff command does. It receives two files in the command line and prints the missing, added and changed lines, if the second file is seen as a modification of the first.
Among the several output formats, the most interesting are the detailed (which is the default), the unified (option -u), and the ``side-by-side'' (option -y).
EXEMPLOS
There is a large number of text editor available in Unix. They range from simple line editing tools like ed to very sophisticated programs like emacs. The most popular among Unix users are vi and emacs, but a good start would be nedit.
nedit is quite powerful but still easy to operate editor. All operations can be done by using menus and the interface is quite intuitive.
emacs is a very powerful and flexible editor and has the advantage of being present almost everywhere, but it takes a longer time to really master it. It is worth to experiment the basics and check if you like.
A process is a program being executed. A program is a piece of software resting on some disk and which you can run. When you ``start'' the program, it is copied to the main memory for execution.
You may have more than one instance of the same program running at the same time, that is, more than one process associated to the same code.
Just like ls lists the files, ps will list the processes of the current user, but a more interesting tool is the top: it displays all active processes in a table which is updated every few seconds (the refresh rate can be adjusted with the option -d.
EXEMPLOS
If the process has a text interface, you can normally terminate it
by pressing Control-C at point where the program asks for
data.
In a graphic environment, there usually is a button located at the
title bar which terminates the process. Clicking the right button of
the mouse also presents a menu with a termination option.
In any situation, you can use the kill command on a
terminal. Just type kill followed by the number of the
process which must be terminated. kill -9 will
force the process to terminate.
EXEMPLOS
When you start a process from within a terminal, it ``occupies'' the
terminal and control all the input and output there -- we say that
it is executing in foreground.
To get access to the terminal again, you can signal the process to
``sleep'' by typing Control-Z. You can then issue a
command to make the process resume its operation. There are two
possibilities: fg puts the process in foreground again, but
bg resumes the process without giving the terminal control
back to it, allowing you to issue other commands at the same time.
Another, much more direct, way, is to add an & right after
each command you want to run in background. You can start several
processes at the same time this way.
EXEMPLOS
Information is available in the Internet in several different ways.
It may be a web page, a video or audio stream, a program you can
execute remotely or simply a set of files which can be accessed
using some protocol.
The protocol is just a set of rules a program must follow in order
to get the information. The http protocol, for instance,
dictates the steps a browser must follow to receive a valid web
page. Fortunately, you do not need to know how a protocol
works (this is done by the program you are using), but you should
know under which protocol the information you need is made
available.
An URL (Universal Resource Locator) is a way to completely
specify the requested information. It has the following structure:
://address/contents
http://www.google.com/ A web page.
ftp://ftp.us.debian.org/welcome.msg A file in a
ftp server.
file:///etc/protocols A file on your local machine.
The best and safer way to establish a connection is by using the
ssh command. It may not be available everywhere but is
becoming more and more common.
To use it, just type:
@machine
EXEMPLOS
If you are willing to retrieve files from an account you have on a remote machine, the scp program is the safer choice. Its usage is very similar to that of cp, the difference being that you must precede the source or destination with the name of the remote machine, followed by a colon (:), like this
@machine:this that
If, on the other hand, you are willing to fetch files from a server, use the wget command instead. You must know the URL of the files you want to retrieve, then just type at the prompt: