ls), but they are very powerful
Each UNIX command is actually a separate process (many of them are just C programmes) that is launched by the shell process when you hit
Return. Traditional LINUX commands run entirely within the window in which they were launched, taking their parameters from the command line and sending their output back to the shell window (e.g.
ls). But increasingly programmes are being written to run in separate windows (Graphical User Interfaces, or GUI's), with parameters selected using a mouse. Well-known examples are Netscape and Word.
You will be prompted to enter your old password, then the new password and then the new password again for validation.
This is my home directory. I am the only user (apart from the superuser, also called root) who should be able to create files in or below this directory. By default anyone should be able to read any of them, although this can be easily changed by the owner.
%ls -l (long listing, including time of last modification)
%ls -t (list in order of last modification)
%ls -lt (last two together)
%mkdir newdirectory (
directory with the name "
% mkdir new\ directory
%cd newdirectory (
%pwd will now show that
/home/guest/newdirectory is the current directory. Any files you create now will be created within this directory
The LINUX file-system is arranged like the roots of a tree, beginning with a single root and branching into more and more sub-branches. The topmost directory is called the "root" and is represented by
/. The following command places you in the root directory:
Below the root are important subdirectories:
binaries (executables) making up the LINUX operating system
/varcontain miscellaneous system-related stuff
/homecontains the home directories of all users
/usrcontains user-specific files:
/usr/localcontains locally-installed software (i.e. not part of the general distribution);
/usr/datais where our large data-sets are stored. The Carnegie network is set up so that these directories are accessible from any of the machines (i.e. you don't have to work at the same machine in order to get access to files saved previously.)
(ls -l) some of the top-level directories to see what they contain.
more to look at the contents of
Most LINUX-related files are written in plain text (typewriter characters only, also called ASCII), unlike graphics files which contain binary numbers or MS Word files which contain other codes and metacharacters in addition to ASCII. There are many text editors available; the one we will be using is called nedit. To launch it, type:
Open a new file and enter the text "This is my first file" and save it to your home directory under the name "first_file.txt".
The following command
moves the file first_file.txt from my home directory to the directory newdirectory:
%mv /home/david/first_file.txt /home/david/newdirectory/first_file.txt.
Move your own copy of first_file.txt to your own newdirectory directory. Check that the file has been moved using
%ls -l in the relevant directories.
/home/pugh/first_file.txt is known as the path of the file first_file. Where the context makes the path clear, it may be omitted, as follows:
%mv first_file.txt newdirectory
If the directory exists called newdirectory, then first_file.txt will be moved into it. If not, LINUX will simply change the name of first_file.txt to newdirectory. A safer practice would be to include the slash after the directory name:
%mv first_file.txt newdirectory/
which will cause LINUX to complain if there is not already a directory of that name.
To move a file and change the name at the same time, include the new name in the target path:
%mv /home/pugh/first_file.txt /home/pugh/new_filename.txt
To copy a file to another directory (without deleting the original):
%cp filename target_directory
To change the name of the copy, include the new name in the target path, as before.
%more filename lists the contents of the file filename one page at a time.
Spacebar moves on to the next page while
b moves back one page.
Return moves down one line at a time.
Try moving the file first_file.txt to one of your fellow students' home directories. Try listing the files in their directory and reading the contents of files using
more. What do you conclude?
A useful feature of LINUX is that commands are easily linked together, so that the output from one serves as the input to another. This is achieved using the
| command, which is known as a "pipe". For example,
%ls -l /bin | more
causes the listing of the files in
/bin to be listed page by page, rather than flashing across the screen.
List the contents of your home directory using
ls -l. On the extreme left of the listing you will see a column of characters ending in
rwxrwxrwx. The first triple indicate that the owner of the file has read (r), write (w) and execute (x) permission on the file. The owner of the file is the name appearing in column 3 of the listing. The second three permissions relate to any user in the group whose name appears in column 4, called the group owner of the file. The third triple relate to all users. Dashes ('-') indicate that the the corresponding permission is not available to that user.
The permissions for first_file.txt should allow the owner (you) to read, write or execute the file, members of the group users to read and execute but not write (alter), and the same for all users.
To change the permissions allowed to each category of user, use the command
chmod. Only the owner of a file (and the superuser) may change its permissions.
To remove read permission to first_file.txt for members of the group all:
% chmod a-r first_file.txt
To add write permission for members of the owner group of first_file.txt (in this case users):
% chmod g+w first_file.txt
To set the permissions for members of the owner group to --x:
% chmod g=x first_file.txt
If a file is an executable, it cannot be invoked by a user unless that user has execute permission on the file. If the 'file' is actually a directory, then removing execute permission for a user means that the user cannot make that directory their current directory.
It is also possible (but only for the owner and the superuser) to change the user categories applying to a file, using the command chown. For example:
% chown jason.nmr first_file.txt
will make jason the new owner of the file first_file.txt, and at the same time change the group owner to nmr (see the list of all defined groups in
/etc/groups). Unfortunately once you have given away ownership of your files, the only way to get it back is to ask the user to whom you gave them, or else the superuser.