Welcome to the Computer Science
Basic UNIX Commands Page
This document contains information about some of the basic unix commands that
you will probably need to know to successfully use our Unix workstations. Commands
are placed in quote marks("). These marks are NOT typed when using the
command. They are placed there so that you can more easily locate them.
***NOTE that both your username AND password are case sensitive.***
After you login, assuming you are coming in via ssh, you will see a message scroll down you screen. This is the Message Of The Day (or MOTD). It contains announcements and important news about changes on the system. Even if you don't have much need for the remote access systems (wirth, berry, knuth), you should get in the habit of checking them at least once a week for this information alone. We are planning forum, wiki, and other communication methods such as jabber, but we aren't fully ready yet.
The first thing you should know how to do is change your password. Information about changing passwords can be found here
The second thing you should know how to do is log out. If you are working under a windowing system such as kde, you use the big K like the windows start menu and select logout. If you are logged in via ssh, you can type exit, logout, or just hold down control and type a d character.
The shell you are using is bash. It has MANY useful features.
For example, ^u (*NOTE* ^ means push and hold the control key, then
press the key that follows the ^ and release both keys.) deletes the
current command-line, ^b moves the cursor back one character, ^p displays
previous commands, completes a filename, ETC. For more information
about bash, type "man bash" and hit the return/enter key.
"ls" - This is the command we use to list files in a directory. There are
many options you can use with the "ls" command. For example "ls -a"
will list ALL of the files in a directory(files and directories whose
name begin with a period are considered hidden files). "ls -al" will
list all files in long format(Your list will may have different files.):
[hopper:~] [11:00am] -> ls -al
total 984
drwxr-x--x 10 sun000 grade 1536 Jul 1 15:00 ./
drwxr-sr-x 210 root grade 512 May 1 10:46 ../
-rwx---r-- 1 sun000 student 1858 Nov 1 1997 .cshrc*
-rw-r--r-- 1 sun000 student 1869 Nov 1 1997 .emacs
-rwx------ 1 sun000 student 918 Nov 12 1997 .login*
-rwx------ 1 sun000 student 942 Nov 21 1997 .logout*
-rw-r--r-- 1 sun000 student 39 Nov 13 1997 .plan
-rw-r--r-- 1 sun000 student 39 May 3 1997 .project
drwxr-s--- 4 sun000 grade 512 Mar 14 1997 class/
-rwxr-xr-x 1 sun000 student 2352 May 9 1997 fun*
The '-rw-r--r--' show the permissions for a file and the type of file.
The first character '-' means that it is a normal file, a 'd' in that
position means it is a directory, and a 'l' means it is a link to
another file. The next nine positions give the permissions on the
file. The first three characters(often 'rw') are the permissions for
the owner of the file, the characters four through six are the group
permissions, and the final three characters are the world
permissions. World permissions means anybody with an account on that
system. An 'r' means read access, or on a directory that a user can
list the files in the directory. A 'w' means write access(which
includes that right to delete a file), on a directory it means the
right to create files in that directory. An 'x' on a file mean execute
permission, and on a directory it mean the ability to change into
that directory. Sometimes you will see an 's' in the group
permissions on a directory this is call set GID. Set GID means that
all files and directories created under that directory will belong to
the group of the parent directory rather than your default group.
This is used on our system to aid professors in grading student
projects.
The next column is a number representing how many physical links to the
directory or file exist on the filesystem. Your home directory, '.', will
usually contain 4 links to it: a link from
/home/vonneumann/student/yourhomedir pointing to your directory, the
pointer '.' which resides within your directory, and the '..' pointers
from within your 'Mail' and 'bin' directories. Files generally have 1
link to them due to the fact that directories cannot link
to files specifically. Notice that the directory up one level, '..',
contains a large number of links (210) due to the number of
home-directories that reference it as '..'.
The next 4 columns are: the name of the owner, the name of the group,
the size of the file, and the last time the file or directory was
modified.
The final column contains the name of the file or directory. *NOTE*
files with execute access appear with an '*' at the end of the
filename. This character is NOT part of the filename, but is there to
show you that it is an executeable file. Directories are shown with
a '/' at the end of their names, again this is NOT part of the actual
name, but there to show you it is a directory.
"chmod"- This is the command used to change the permissions on a
file or directory. You can use octal numbers to represent the
permissions, or you can use letters and symbols. "chmod 740 test"
would set the permissions on test to '-rwxr-----'. "chmod g=rw test"
will set group access to read and write for test.
Table of letters and symbols:
a all (group, user and other)
g group
o other (world access permissions)
u user (the owner of the file)
+ add permission
- take away permission
= set permission
r read access
w write access
x execute access
"cd"- This is the command we use to change directories. "cd /" will
take you to the root directory. "cd /usr" will take you to a
directory named 'usr' that is located in the root directory.
"cd class" will take you into a directory named class from your
current directory. "cd .." will take you to the parent directory.
Typing "cd" will take you to your home directory. Some shells, like
the tcsh, support another way to get to other directories. So,
"cd ~" is another way to get to your home directory. "cd ~sun001"
will take you to sun001's home directory. "cd ~/class" will take you
to a directory named class that is located under your home directory.
"pwd" - this is a simple command that prints out the path to your current
directory.
"mkdir" and "rmdir" - these commands are used to create and remove
directories. "mkdir class" will create a directory called class in
your current directory. "rmdir class" will delete the directory
named class. "rmdir" only works on directories that contain no files
or directories.
"cp" - this is the command for making a copy of a file.
"cp /usr/local/seminar.c ." this command would copy a file located
in '/usr/local' named 'seminar.c' to your current directory.
"cp /usr/local/seminar.c ./my.c" performs ALMOST the same action, but
instead of the resulting file being named 'seminar.c' it will be named
'my.c'. Unlike the DOS copy command, "cp" always requires
atleast 2 arguments.
"mv" - this is the move AND rename command. "mv my.c first.c" would
rename a file named 'my.c' to 'first.c'. Assuming that 'class' is a
directory, "mv my.c class" would move 'my.c' into that directory.
You can do both at the same time so, "mv my.c class/first.c" would
move 'my.c' into 'class' and rename it to 'first.c'.
"rm" - This is the command used to delete files. "rm my.c" would delete
the file 'my.c'. "rm my*" would delete every file whose name started
with 'my'. Assuming 'class' is a directory, "rm -r class" would
delete ALL files and directories under 'class' and 'class' itself.
"cat", "more", "page", "head", and "tail" - are all command used to view
the contents of files. "cat" displays the entire file on the screen,
and if the file does not fit on one screen the top portion is scrolled
off of the screen. "page" and "more" both display the contents of a
file one screen full at a time. "head" is used to display the first
few lines of a file, and "tail" is used to display the last few lines of
a file. "head -15 my.c" displays the first 15 lines of 'my.c'.
"tail -25 my.c" displays the last 25 lines of 'my.c'. "more first.c"
displays 'first.c' one screen full at a time. "cat first.c" would
display all of 'first.c'.
"grep" - Command used to find an expression in a file. "grep fun my.c"
prints every line that contains the word 'fun'. You will see the
importance of this command a little later in this file.
"man", "man -k", "apropos" - commands used to locate manual pages on unix
commands. "man ls" will display the manual pages for the command
"ls". "man -k files" and "apropos files" search the manual pages for
any command that has the word files in its description, and displays
the header line for each match it finds. These commands can be used
to locate and learn a lot more about various unix commands and utilities.
"who", "w", "whoami" - These are commands used to find out whose on the
system and what they are doing. "who" lists all the users currently
logged in. "w" lists all users that are currently doing and what they
are currently doing. "whoami" returns the username of the person
currently logged in.
"ps" - command used to list processes currently on the machine. Typing
"ps" without any options lists all processes in your current process
group. "ps -ef" lists all of the processes on the machine. Combining
the "ps" and "grep" command can give you a list of all of the processes
you have running. The command looks like "ps -ef |grep sun000". The
`|` symbol(called a pipe) takes the results of the first command (in
this case "ps -ef") and uses it as input to the second command (in
this case "grep sun000"). (**Note you would type your sun ID instead
of sun000) Lets take a look at an example:
[hopper:~] [10:05am] -> ps -ef | grep sun000
sun000 28684 28671 0 10:05:10 pts/1 0:00 more .cshrc
sun000 28682 28671 0 10:05:00 pts/1 0:00 vi
sun000 28695 28689 1 10:05:49 pts/2 0:00 grep sun000
sun000 28671 28669 0 10:04:49 pts/1 0:01 -tcsh
The first column contains the user ID of the owner of that process.
The second column contains the PID (Process IDentification number).
The third column contains the PPID (Parent Process Identification
number). The other column of importance is the last column, which
contains the name of the process.
"kill" - the command used to send signals to processes. The most important
signal users send is the kill signal. Looking back at the ps example,
to kill the processes named 'vi' and 'more .cshrc' the user would type
"kill -9 28684 28682". The '-9' represents the signal number and the
'28684' and '28682' are the PIDs for those 2 processes.
"kill -9 28684" would kill the process named 'more .cshrc'.
"quota" - this command is used to check disk space usage. Student
accounts are limited on how much disk space they can use. The "quota"
command displays information about your disk usage. Heres an example:
[vonneumann:~] [10:02am] -> quota
Disk quotas for sun000 (uid 180):
Filesystem usage quota limit timeleft files quota limit timeleft
/home/vonneumann
57 3000 3500 25 0 0
Looking at this output, it shows to values a quota of 3000 and a limit
of 3500. The 3000 quota is sometimes called a soft limit. You can
exceed your soft limit for a period of time(normally 7 days). You
will receive a warning everytime you login that you are over your soft
limit. If you do not remove files and drop below your soft limit in
the time period, or you reach the second value, the limit, the system
will stop allowing you to create files or allocate more storage for
existing files. The 3500 limit is often called a hard limit because
you can not go over that limit. To avoid filling your quota you
should delete all un-needed files. Compiled programs usually take up a
lot of space. You should keep source code, but delete the compiled
program to save space.
|