In this class, you'll need some familiarity with the Unix shell. Those of you that took CS33 are probably somewhat familiar with it after spending several weeks writing one, but not everyone has done that, and the CS33 wasn't intended to teach how to use the shell efficiently as a user. Here are a few commands which you will probably find useful.
A first useful note is that each shell prompt will begin with a dollar sign, like so:
This is the shell's way of telling you it is waiting for more input.
Movement and file listing
Two of the most common commands are
ls. The former, which stands for change
directory, is the command you use to enter other
directories. Think of
ls as short for LiSt. It will
display the contents of the current directory when used without
arguments, or the contents of any directories that you supply to it on
the command line.
$ cd /course/cs0320 $ ls admin/ asgn/ data/ handin/ ta/ webdev/ archive/ bin/ docs/ lib/ tabin/ www@ $ ls bin ant@ old/ qtcreator@ cs032_handin* priv_handin* $ cd bin
The "punctuation" at the end of a file name tells you that a file is a directory (/), an executable program (*), or a symbolic link (@).
Commonly used flags with
lists all the files in the current directory including dot-files
(which are usually "hidden" in the sense that
show them), and
-l, which lists things in long format, so
you can see their permissions, owner, group, size, and date of last
Sometimes, you want to move files around, copy them to different
places, or get rid of them. You'll use
cp (copy), and
rm (remove), respectively.
mv will either rename a file, if it is given a file for
the first argument and another filename which is not a directory for
the second, or move files described by all arguments except the last
into the directory given by the last argument.
copy the first argument to the second, or all arguments but the last
into the directory specified by the last.
rm will remove
all files given as arguments.
$ ls file1 foo/ $ mv file1 file2 $ ls file2 foo/ $ cp file2 foo $ ls file2 foo/ $ ls foo file2 $ rm file2 $ ls foo/ $ rm foo rm: cannot remove `foo': Is a directory $ mv foo bar $ ls bar/ $ rm -r bar $ ls
As you can see, the
rm command requires the
(for recursive) flag in order to remove directories, but the
mv command will simply move the entire directory
somewhere else without need of a flag. Usually, when you delete files
rm they can't be recovered. However, on the
department filesystem, you may be able to fetch it from the
backups. If you mistakenly delete something, talk to a Sun Lab
consultant to see if you can get it back.
File permissions may seem complicated, but they are all in all not too difficult
to understand. For checking permissions, you are probably going to make heavy
ls -l, which can display permissions:
$ ls -l total 16 -rwxrwxr-x 1 aisha aisha 46 Jan 18 16:48 file1 -rw-rw---- 1 aisha cs0320ta 63 Jan 18 16:48 file2
In long form, the first column is the bit string of permissions, which can be
split into the owner's permissions, the group's permissions, and world
permissions. In the first file,
aisha is the owner, and
aisha is also the group. The owner permissions are
rwx, which means Read, Write, and eXecute,
respectively. The same applies for anyone in the
group (which only contains the eponymous user). However, anyone else can only
read or execute the file.
In the second file, the user and group only have read and write permissions, and everyone else has no permissions.
chmod (change mode) allows you to change a
file's permissions if you are the owner of that file. For example:
$ chmod ug+x file2 $ ls -l total 16 -rwxrwxr-x 1 aisha aisha 46 Jan 18 16:48 file1* -rwxrwx--- 1 aisha cs0320ta 63 Jan 18 16:52 file2*
chmod invocation specified
added the eXecute permission for User and Group. You could remove it
again for the group, with
g-x, for example.
There are more complicated use cases, where you can give specific permissions to specific groups, or make one set of users' permissions the same as another.
Two other commands may be useful to you for managing permissions.
chgrp changes the group of a file, and
changes the owner.
If you are ever confused about a command's syntax or use cases, you can look
it up in the manual pages (usually referred to as man pages). They
can be accessed with the
man command. Just type
man and then the name of the command you would like to know
more about. (For former CS33 students, many syscalls can be found in the man
pages as well).
If you want to do something but don't know the command to use to do it, then
you can use
apropos to search for a command based on some
keywords. By default, it will look for commands whose short descriptions in
the man pages contain any of the words you supply as an argument, but if you
give it the
-a flag, it will only return commands that have
all of the words.
More information about the shell can be found here