UNIX Primer
Getting help in UNIX
The man command is useful to get more information about any command
in UNIX. For instance, to find out more about the cp command,
you would type
man cp
The apropos command can help you find commands related to some
keyword. For instance
apropos copy
would list all UNIX commands related to copying (including cp).
File and Directory Manipulation
Listing your files
ls |
lists all files in your directory (like dir) |
ls -l |
show all attributes (such as size, date created, and permissions) |
ls -a |
list all files (including those that begin with . ) |
Copying and deleting files
cp file1 file2 |
copies file1 into file2 |
rm file |
deletes file |
Directories and subdirectories
Like DOS, your Unix files may be organized into directories and subdirectories
for the purpose of good organization. The syntax is roughly the same as
in DOS (note, however, that UNIX uses the forward slash / instead
of the backslash for subdirectories).
Creating and deleting directories
mkdir directory |
creates a new subdirectory called directory |
rmdir directory |
deletes that directory (but only if all files in it have been deleted). |
Changing the current directory
Like DOS, you can navigate through your directories using the cd
command.
cd directory |
takes you to directory (if it is a subdirectory of the current
one) |
cd .. |
takes you back up to the directory of which your current directory
is a subdirectory |
cd |
returns you to your root directory. |
Copying and directories
You can also copy and move files from one directory to another using
cp. For example:
cp file directory |
will make a copy of file in directory directory (as long
as directory is a subdirectory of your current location). |
cp directory1/file directory2 |
will copy of file from directory1 into directory directory2. |
cp ../file1 file2 |
Will copy file1 from the directory below the current one, into |
Setting Permissions for Files and Directories
One of the important things to understand about a multiuser system like
UNIX is that all files are stored on the same machine, and that you could
(theoretically) reach anyone else's directory and files by doing cd
.. enough. This makes it important to control the permissions
for your files.
This is done in UNIX with the chmod command. It has the basic
syntax:
chmod who op ability
where who is some combination of:
u |
The owner of the file (that is, you). |
g |
The group you belong to (not relevant now, but will be later
when you work on group projects). |
o |
All others. |
where op is either:
+ |
Add this ability to these people. |
- |
Remove this ability to these people. |
where ability is some combination of:
r |
These people can read this file. |
w |
These people can write to this file. |
x |
These people can execute this file (or cd into it,
if it is a directory). |
For example:
chmod o-r fred
means that others can no longer read the file fred.
chmod o+x barney
means that others can now enter the directory barney.