
/ (root)
|
---------------------
| | |
/bin /usr /tmp
|
|
-------------------
| | |
/public /misc /staff
| |
------------ -------------------
| | | | | |
/software /doc /john /mary /bill /carl
who | wc -l
This command will tell you how many users are currently logged into
the system. The standard output from the who command is a list of
all the users currently logged into the system. This output is piped
into the wc command as its standard input. Used with the -l option
this command counts the numbers of lines in the standard input and
displays the result on its standard output - your terminal.
& ; ( ) | ? \ ' " ` [ ] { } < > $ - ! /
NOVEMBER November november
libc.a - archive, library file
program.c - C language source file
alpha2.f - Fortran source file
xwd2ps.o - Object/executable code
mygames.Z - Compressed file
.cshrc .login .mailrc .mwmrc
/ - the root directory (slash)
. - current directory (period)
.. - parent directory (double period)
~ - your home directory (tilde)
/usr/local/doc/training/sample.f
training/sample.f
../bin
~/projects/report.001
cd ../quattro - relative pathname
cd /usr/home/quattro - absolute pathname
ls - show contents of working directory
ls file - list file, if it exists in working directory
ls dir - show contents of the directory dir
ls -a - shows all your files, including hidden ones
ls -al - give detailed listing of contents
ls -F - mark directories with "/" and executable
files with "*"
ls *.doc - show all files with suffix ".doc"
more sample.f
pg sample.f
less sample.f
head sample.f - display first 10 lines (default)
head -5 sample.f - display first 5 lines
head -25 sample.f - display first 25 lines
less sample.f - display last 10 lines (default)
less -5 sample.f - display last 5 lines
less -5c sample.f - display last 5 characters
less -25 sample.f - display last 25 lines
cat myprog.c - diplays entire file
cat -b myprog.c - shows line numbers
cat file1 file2 > file3 - adds file1 and file2 to make
file3
cp sample.f sample2.f - copies sample.f to sample2.f
cp -R dir1 dir2 - copies contents of directory
dir1 to dir2
cp -i file.1 file.new - prompts if file.new will be
overwritten
cp *.txt chapt1 - copies all files with .txt
suffix to directory chapt1
cp /usr/doc/README ~ - copies file to your home
directory
cp ~betty/index . - copies the file "index" from
user betty's home directory
to current directory
mv sample.f sample2.f - moves sample.f to sample2.f
mv dir1 newdir/dir2 - moves contents of directory
dir1 to newdir/dir2
mv -i file.1 file.new - prompts if file.new will be
overwritten
mv *.txt chapt1 - moves all files with .txt
suffix to directory chapt1
rm sample.f - deletes sample.f
rm chap?.txt - deletes all files with chap as the
first four characters of their name
and with .txt as the last four
characters of their name
rm -i * - deletes all files in current directory
but asks first for each file
rm -r /olddir - recursively removes all files in the
directory olddir, including the
directory itself
Begin the Filesystem
exercises - Part 1.
file filename
For example:
file * - reports all files in current
directory and their types. The
output might appear as shown below:
about.html: ascii text
bin: directory
staff.directory: English text
bggen: executable or object module not stripped
bmbinc: commands text
machines.sp1: [nt]roff, tbl, or eqn input text
man2html: executable or object module not stripped
man2html.c: ascii text
find pathname -name filename -print
The pathname defines the directory to start from. Each subdirectory of this
directory will be searched.
The -print option must be used to display results.
You can define the filename using wildcards. If these are used, the filename must be placed in 'quotes'.
find . -name mtg_jan92 -print - looks for the file
mtg_jan92 in current
directory
find ~/ -name README -print - looks for files called
README throughout your
home directory
find . -name '*.fm' -print - looks for all files with
.fm suffix in current
directory
find /usr/local -name gnu -type d -print
- looks for a directory
called gnu within the
/usr/local directory
diff file1 file2 - compares file1 to file2
diff -iw file1 file2 - compares two files ignoring
letter case and spaces
diff dir1 dir2 - compares two directories
showing files which are
unique to each and also,
line by line differences
between any files in common.
For example, if file1 and file2 are:
John erpl08@ed John erpl08@ed
Joe CZT@cern.ch Joe CZT@cern.ch
Kim ks@x.co Jean JRS@pollux.ucs.co
Keith keith@festival Jim jim@frolix8
Kim ks@x.co
Keith keith@festival
Using the diff command: diff file1 file2
Yields the output:
2a3,4
> Jean JRS@pollux.ucs.co
> Jim jim@frolix8
Which means that to make these files match you need to add (a)
lines 3 and 4 (3,4) of file2 (>) after line 2 in file1.
Lines that are different are shown with a | symbol. Lines unique to file1 are identified by a < symbol; lines unique to file2 with a > symbol. Identical lines appear next to each other. The option -w 80 is used to set the width of the output from the command to 80 characters. The default is 130 characters.
sdiff -w 80 file1 file2
Mike erpl08@ed | John erpl08@ed
Joe CZT@cern.ch Joe CZT@cern.ch
> Jean JRS@pollux.ucs.co
> Jim jim@frolix8
Kim ks@x.co Kim ks@x.co
Sam s.wally@aston <
Keith keith@festival Keith keith@festival
ln source linkname
Making a link to a file or directory does not create another copy of it.
It simply makes a connection between the source and the linkname. Allows
a single file to be "pointed to" by other filenames without having to
duplicate the file.
ln results.1 last.run - links filename "last.run" to
the real file results.1 in
the current directory.
ln notes ../Notes.jan - links filename "notes" in
current directory to real file
Notes.jan in parent directory.
sort options filename
By default, lines in "filename" are sorted and displayed to the screen.
If the "filename" parameter specifies more than one file, the sort command
concatenates the files and sorts them as one file.
An output file can be specified with the -o flag.
Files can be sorted by "fields" - single or multiple.
The sort command supports many options. See the man page for details.
sort addresses - sorts the file
addresses and displays
output on screen
sort -o sorted addresses - sorts the file
addresses and writes
output to the file
called sorted.
sort -u -o mail_labels addresses - removes all duplicate
lines from the file
addresses and writes
the output in the
file mail_labels.
sort +2 -4 addresses - sorts the file by
its third and fourth
fields. Note that
+2 means to skip first
two fields and -4
means to stop after
the fourth field.
Continue the Filesystem
exercises - Part 2.
pwd
mkdir /u/training/data
mkdir data2
cd /usr/local - change to /usr/local
cd doc/training - change to doc/training in current
directory
cd .. - change to parent directory
cd ~/data - change to data directory in
home directory
cd ~joe - change to user joe's home directory
cd - change to home directory
rmdir project1
To recursively remove nested directories, use the rm command with the
-r option:
rm -r dirctory_name
Continue the Filesystem
exercises - Part 3.
awk -search for and process patterns in a file,
cat -display, or join, files
cd -change working directory
chgrp -change the group that is associated with a file
chmod -change the access mode of a file
chown -change the owner of a file
comm -compare sorted files
cp -copy files
df -display the amount of available disk space
diff -display the differences between two files
du -display information on disk usage
file -display file classification
find -find files
fsck -check and repair a file system
grep -search for a pattern in files
head -display the first few lines of a file
ln -create a link to a file
lp -print files (System V)
lpr -print files (Berkeley)
ls -list information about files
mkdir -create a directory
more -display a file one screen at a time (System V)
mv -move and/or rename a file
od -dump a file
pg -display a file one screen at a time (Berkeley)
pr -paginate a file
pwd -print the working directory
rm -remove (delete) files
rmdir -remove (delete) a directory
sed -stream editor (non-interactive)
sort -sort and/or merge files
spell -check a file for spelling errors
tail -display the last few lines of a file
tar -store or retrieve files from an archive file
umask -set file creation permissions
uniq -display the lines in a file that are unique
wc -counts lines, words and characters in a file
whatis -list man page entries for a command
whereis -show where executable is located in path
which -locate an executable program using "path"
r - read
w - write
x - execute = running a program
u - user = yourself
g - group = can be people in the same project
o - other = everyone on the system
owner read (r)
owner write (w)
owner execute (x)
group read (r)
group write (w)
group execute (x)
public read (r)
public write (w)
public execute (x)
which are displayed as: -rwxrwxrwx
Example outputs from the ls -l command:
-rw------- 2 smith staff 3287 Apr 8 12:10 file1
- User has read and write permission. Group and
others have no permissions.
-rw-r--r-- 2 smith staff 13297 Apr 8 12:11 file2
- User has read and write permission. Group and
others can only read the file.
-rwxr-xr-x 2 smith staff 4133 Apr 8 12:10 myprog
- User has read, write and execute permission.
Group and others can read and execute the file.
drwxr-x--- 2 smith staff 1024 Jun 17 10:00 SCCS
- This is a directory. The user has read, write and
execute permission. Group has read and execute
permission on the directory. Nobody else can
access it.
chmod permission_triads filename
[who][action][permissions]
where:
who action permissions
u = user + = add r = read
g = group - = remove w = write
o = other x = execute
a = all
Examples:
chmod a+r sample.f
- Adds read permission for all users to the file
sample.f.
chmod o-r sample.f
- Removes read permission for others to the file
sample.f.
chmod og+rx prog*
- Adds read and execute permissions for group and
others to all files which contain "prog" as the
first four characters of their name.
chmod +w *
- Adds write permission for user to all files in
current directory.
r w x
4 2 1
These values are added together for any one user category:
0 = no permissions
1 = execute only
2 = write only
3 = write and execute (1+2)
4 = read only
5 = read and execute (4+1)
6 = read and write (4+2)
7 = read and write and execute (4+2+1)
So access permissions can be expressed as three digits. For example:
user group others
chmod 640 file1 rw- r-- ---
chmod 754 file1 rwx r-x r--
chmod 664 file1 rw- rw- r--
The umask command accepts only octal specifications. Note that these are different than those used by the chmod command, and in fact, represent which permissions to "mask out", or remove.
Octal number Access permissions given
0 rwx read, write and
execute
1 rw- read and write
2 r-x read and execute
3 r-- read only
4 -wx write and execute
5 -w- write only
6 --x execute only
7 --- no permissions
Example umask commands:
umask 077
- Subtracts 077 from the system defaults for files
(666) and directories (777). Results in default
access permissions for your files of 600
(rw-------) and for directories of 700
(rwx------).
umask 002
- Subtracts 002 from the sytem defaults to give a
default access permission for your files of 664
(rw-rw-r--) and for your directories of 775
(rwxrwxr-x).
umask 022
- Subtracts 022 from the system defaults to give a
default access permission for your files of 644
(rw-r--r--) and for your directories of 755
(rwxr-xr-x).
/(root) - The top level directory referred to as root.
Contains all files in the file system.
/bin - Executable files for standard UNIX
utilities
/dev - Files that represent input/output devices
/etc - Miscellaneous and system administrative
files such as the password file and system
start up files.
/lib - UNIX program libraries
/tmp - Temporary space that can be used by
programs or users.
/usr/bin - More UNIX utilities. By convention /bin
contains standard utilities and /usr/bin
contains less common utilities.
/usr/bin/X11 - X windows binaries
/usr/lib - More UNIX libraries
/usr/lib/X11 - X windows libraries
/usr/local - Programs installed by local site
/usr/ucb - Berkeley utilities
/u - User home directories
/var - Variable sized files - can grow and
shrink dynamically, such a users mail
spool and print spool files.
This concludes the tutorial. Return to the Table of Contents