Basic Unix Commands
Basic Unix Commands
SYNOPSIS
This section describes fundamental concepts and commands for using the UNIX operating system.
INTRODUCTION The most distinguishing characteristic of the UNIX operating system is the file
system structure. The file system structure resembles an inverted tree, with the
user's files as leaves along the bottom and the root at the top. The user's home
directory (the directory you are placed in when you log in) is placed at a specific
point in the structure but the user is not limited to that directory. It is possible to
move around in the tree - up, down, and sideways - into directories belonging to
other users and/or the system. Users can protect their files and directories from the
prying eyes of others by changing access permissions.
Each file and directory has a path name which uniquely identifies it. The path is
described, starting with the root, down through the branches of the tree, to the
directory containing the file. Filenames must be unique within a directory. On
Central UNIX, this tree structure is spread over all of the sites that exist in the
cluster
DIRECTORY cd path<CR>
MANIPULATION The change directory command moves the user from the current working
COMMANDS directory to the directory specified. If path is defined as a simple name such as
docs, then docs is located directly below the current directory and the user is
moved into it. The command cd, by itself on a line, returns the user to the login
directory. Examples of uses of cd are
cd docs<CR> Move down to the directory named docs.
cd ..<CR> Move up to the parent directory of the current
directory.
cd ../data<CR> Move up to the parent directory of the current
directory, then down to the directory named
data.
cd /usr/local/bin<CR> Move to the explicit directory location.
cd ~login_ID<CR> Move to the home directory of the user
specified by login_ID (C Shell only).
ls<CR>
Lists the contents of the current directory. ls has many parameters. You will
probably find the following to be the most useful:
ls -a Lists all files, including invisible files (files
with a leading dot (.)).
ls -l Lists all visible files and some attributes.
ls -F Places a slash ( /) after directory files and an
asterisk (*) after executable files, and places
an at-sign ( @) after symbolic links.
CHANGING FILE Access permissions fall into two categories, base permissions that exist on most
ACCESS PERMISSIONS UNIX systems, and extended permissions, available on most POSIX based systems
such as AIX. This section addresses those forms for setting permissions.
NOTE: Systems using AFS (Andrew File System) and DFS (Distributed File
System) DO NOT use base permissions except for the user level only, group
and other permissions must be set through extended permissions.
1. ACLGET
"aclget " is used to obtain the permissions of a file or directory and can be
used as follows:
aclget -o outfile filename<CR>
Writes the file permissions for " filename " out to the text file
"outfile " where it may be viewed or edited (see " ACLEDIT").
aclget filename > outfile<CR>
Same effect as the previous command.
2. ACLPUT
"aclput " is used to apply a set of base and extended permissions contained
in a text file to a specified file or directory. Some sample uses are as
follows:
aclput filename < infile<CR>
aclput -i infile filename<CR>
Appies the base and extended permissions contained in the text
file "infile " to the file "filename ".
aclget filename1 | aclput filename2<CR>
Applies the base and extended permissions from " filename1 " to
"filename2 ".
3. ACLEDIT
"acledit " is used to edit the base and extended permissions of a specific
file or directory. It requires that the environmental variable EDITOR be set
to a valid text editor on the system. For example
setenv EDITOR /usr/local/bin/pico
for the C and T Shells
EDITOR=/usr/local/bin/pico;export EDITOR
for the Bourne and Korn Shells.
4. ACLMOD
aclmod is a command written at Cal Poly which uses the above commands
combined with an easy-to-use syntax for easier use. The format of the
command is
% aclmod {+|-}{r|w|x} {p|d}:{u|g}:{loginid|groupid} File|Dir
[File|Dir...] ...<CR>
where multiple files and/or directories may be
specified for each permission set and the
whole group may be repeated for additional
permission sets.
The various options and flags are:
+ Add the specified permission to the ACL for
the file(s) and/or subdirectory(s).
- Remove the existing permission from the ACL
for the file(s) and/or subdirectory(s).
r Read mode.
w Write mode.
x Execute (file) or passthrough mode
(directory).
p Permit the user or group.
d Deny the user or group.
u Defines the following ID as a user.
g Defines the following ID as a group.
loginid A login ID the permission is being assigned
for.
groupid The group ID the permission is being
assigned for.
File A file at the current location or including the
relative or absolute path (multiple files and/or
directories may be specified).
Dir A subdirectory at the current location or
including the relative or absolute path
(multiple files and/or directories may be
specified).
For example,
% aclmod +rx p:u:juser mydir -r p:u:jdoe fil1 file2<CR>
would permit the user juser to read and pass
rm filename<CR>
The rm (remove) command is used to delete a file.
sort filename<CR>
Sorts a file in ascending order beginning with the first column of data. The
sort command has many parameters and is very powerful and versatile. You
will need to check the manual for more information.
tail filename<CR>
tail -nn filename<CR>
The first form causes the last 10 lines of the file to be displayed. The second
form displays the last " nn" lines of the file.
lp -tii_boxnn filename<CR>
SITE MANIPULATION Central UNIX allows users to interact with as many sites as there are in the cluster.
COMMANDS The cluster comes equipped with several commands to assist in this. The following
sub-sections describe the commands and uses.
UNIX EDITORS There are many editors on Central UNIX. The following are recommended.
pico filename<CR>
This is a full screen editor which is also used with the " pine " mail program.
See the chapter, "Using PICO" for more information.
vi filename<CR>
This is the full-screen editor. See the chapter, "vi - Full Screen Editor" for more
information.
USER INTERACTION The Unix system allows you to interact with other users. The following commands
COMMANDS facilitate user communication.
pine username<CR>
Allows you to send electronic mail to another user. (See the chapter for "Using
PINE" for more information on this command.)
pine<CR>
Allows the user to read incoming mail messages. For more information, see the
chapter, "Using PINE".
mailx username<CR> HP-UX
mail username<CR>
Allows you to send electronic mail to another user. (See the chapter for "Unix
Mail" for more information on this command. PINE is recommended instead of
mail for new users.)
mailx<CR> HP-UX
mail<CR>
Allows the user to read incoming mail messages. For more information, see the
chapter, "Unix Mail". (PINE is recommended instead of mail for new users.)
ph real_name<CR>
Allows the user to lookup another user's email address based on their real name
(see chapter "Using ph" for more information).
talk username[@site_name]<CR>
Allows users to communicate back and forth using a split screen. It is an
upgraded version of " write". End the conversation with CTRL-C. NOTE: The
site name may be required when using talk to communicate with a user who is
on another site.
users<CR>
Lists the usernames of everyone presently logged onto the cluster by site.
w<CR>
Lists the usernames, activity, and login information of everyone presently
logged onto the current site.
who<CR>
Lists the usernames and login information of everyone presently logged onto
the cluster.
write username[@site_name]<CR>
Allows users to communicate with each other while logged onto the cluster.
End the conversation with CTRL-D. NOTE: The site name may be required
when using write to communicate with a user who is on another site.
.login
You have a default .login file in your account. " cat .login<CR> " will allow
you to view its contents. When you log onto UNIX under the C shell, the
commands in your .login file are executed immediately. This is a good place to
store setenv commands.
.logout
You have a default .logout file in your account. " cat .logout<CR> " will allow
you to view its contents. .logout is executed when you log off a UNIX system
under the C shell.
MANAGING YOUR DISK Every user is issued a disk space quota. You can keep track of the space your are
SPACE using with these commands.
du<CR>
du -k<CR>
Displays the user's disk utilization for the current directory and all the
directories below the current directory. When used in the home directory, du
will give you the total of all the disk space in use by your account. On most
systems the numbers indicate 1K of disk storage (1024 Bytes). The du
command may not be accurate if you are logged into a system other than where
your files are stored. When the -k parameter is used on some systems, it
returns the utilization in 1K byte units instead of blocks.
quota -v<CR>
Displays the disk quotas across all sites in the cluster. The information
provided is for both file space and inodes (numbers of files or links to files). For
each type, the current value is displayed along with the soft and hard limits.
Soft limits may be exceeded temporarily, hard limits may not be exceeded. If
you have exceeded your quota, messages will appear for your home site with
your UID. Messages without your UID for other sites should be ignored.
NOTE: Quotas are displayed in 1K increments (2000 is equivalent to 2
megabytes), the in-use amount on some system are displayed in blocks.
If you find that you have exceeded your quota, and have a real need for
additional disk space, you may obtain a Status Change form for Central UNIX
from the Computer Account Clerk's office. Estimate the amount of space that
you need for your academic projects; have it signed by your advisor (faculty sign
their own forms, supervisors sign staff forms); then return the form to the
Computer Account Clerk's office for processing.