Common UNIX Commands
PAGEFLOP
FORWARD
SELECTOR
SELAGAIN
WRONGSEL
YOUR SELECTION IS NOT IN THE 0 - #SELIMIT RANGE Please try again
AANVANG
Copyright CourseWare Technologies Inc., 1985-88
Lesson - 8
COMMON UNIX COMMANDS
MENU
UNIX Commands|Topics to Learn|8-0|8,44
# Topic
--- -------
1 - Command Format
2 - User Information Commands
3 - File Management Utilities
4 - Directory Management Utilities
0 - Return to the Main Menu
TOPIC1
Command Format
P1
UNIX Commands|Command Format|8-1.1|14,50
There are over 300 public commands that are
provided by the system. You may use:
* programs shared by many users
* your own programs
* commands internal to the shell
We shall discuss:
* command format
* user information commands
* file management utilities
* directory management utilities
P2
UNIX Commands|Command Format|8-1.2|15,54
A command line consists of one or more words
separated by spaces or tabs and is terminated by <CR>.
As you know, the UNIX command syntax is:
command [option(s)] argument(s)
* The command is what you are asking UNIX to do.
* The options modify the actions of a command.
* The argument(s) are filenames or other pertinent
text data.
P3
UNIX Commands|Command Format|8-1.3|10,54
Some commands do not require options or arguments.
The command line syntax varies from
one command to another. For example:
command_name <CR>
command_name option <CR>
command_name option argument <CR>
command_name argument <CR>
TOPIC2
User Information Commands
P4
UNIX Commands|User Information Commands|8-2.1|4,56
Users need information about the system; useful
information about files stored in directories, the number
of users logged on to the system, which processes are
running, the amount of space available on the disk, etc.
P5
UNIX Commands|User Information Commands|8-2.2|10,56
Some commands that provide this information include:
who - displays the names of users on the system
along with their terminal identification and
the time they logged in.
file filename - provides information on the type
of file filename, that is whether it is a text
file, an executable program, a program source
file, etc.
TOPIC3
File Management Utilities
P6
UNIX Commands|File Management Utilities|8-3.1|7,50
File management utilities allow you to:
* copy files
* rename files
* remove files
* change file ownership
* change file protection
P7
UNIX Commands|File Management Utilities|8-3.2|12,54
Suppose you have a file you want to edit, but
you want to keep a copy of the old version. The cp
(for copy) command allows you to make a copy of a
file. The syntax for cp is:
cp current_filename new_filename
For example, the command: cp chapt4 chapt4_old
makes a copy of the file chapt4 in the current
directory. The copy is called chapt4_old.
P8
UNIX Commands|File Management Utilities|8-3.3|7,54
Suppose you simply want to change the name of
a file (in the same directory) without making a copy.
The mv (for move) command moves a file from one name
to another, thereby renaming it. The syntax for
mv is:
mv oldname newname
P9
UNIX Commands|File Management Utilities|8-3.4|14,52
You can change the name of a file and put it into
another directory. For example, the command line:
mv chapt3 ../book_3
moves the file chapt3 from the current directory
into the parent directory ( .. ) and renames it
book_3.
mv chapt3 ../chapt3
moves the file chapt3 from the current directory
into the parent directory ( .. ) without
renaming it.
P10
UNIX Commands|File Management Utilities|8-3.5|12,52
The rm (for remove) command will remove
ordinary files from your directory. The syntax
for rm is:
rm filename
For example, the command:
rm chapt1 chapt2 chapt3
silently removes all three files from the current
directory.
P11
UNIX Commands|File Management Utilities|8-3.6|7,52
If you are the owner of a file, you may change
the ownership of the file to another user. The user
that you wish to give the ownership to must have a
valid login name. The command to change ownership is
chown. The syntax for the chown command is:
chown login-name-of-new-owner filename
P12
UNIX Commands|File Management Utilities|8-3.7|9,54
For example, the command to make the user smith
the owner of your file called summary is:
chown smith summary
Note that smith will now own the file, but until
you mv or cp the file, it will remain in your
directory.
P13
UNIX Commands|File Management Utilities|8-3.8|4,54
As you saw earlier, the chmod command allows you
to change the protection of your file. The syntax is:
chmod mode filename
TOPIC4
Directory Management Utilities
P14
UNIX Commands|Directory Management Utilities|8-4.1|7,50
Directory management utilities allow you to:
* create directories
* rename directories
* remove directories
* change directory ownership
* change directory protection
P15
UNIX Commands|Directory Management Utilities|8-4.2|8,54
Suppose you have a rather full directory and
you wish to organize your files by creating a few
new subdirectories. As you saw earlier, the mkdir
command (for mak new directory) allows you to make
a new subdirectory in the current directory. The
The syntax for mkdir is:
mkdir new_directory_name
P16
UNIX Commands|Directory Management Utilities|8-4.3|6,46
For example, the command line:
mkdir references
makes a new directory called references in the
current directory.
MKDIR
UNIX Commands|Directory Management Utilities|8-4.4|14,50
Suppose you simply want to change the name
of a directory. The mv (for move) command moves
a directory just like it does a file. As you
should recall, the syntax for mv is:
mv oldname newname
If, for example, you want to rename a
directory called references you could type:
mv references bibliography
to rename it bibliography.
P18
UNIX Commands|Directory Management Utilities|8-4.5|14,54
The rmdir (for remove directory) command will
remove a directory from your current directory. The
directory to be moved must be empty, or you will get
an error message that says something like "Directory
not empty". The syntax for rmdir is:
rmdir directory_name
For example, the command:
rmdir bibliography figures
silently removes both directories from the current
directory.
P19
UNIX Commands|Directory Management Utilities|8-4.6|9,54
If you are the owner of a directory, you may
change the ownership of that directory to another user.
The user that you wish to give the ownership to must
have a valid login name. The command to change the
ownership of a directory is the same as that for
changing the ownership of a file, that is, chown.
The syntax for the chown command is:
chown login name of new owner directoryname
P20
UNIX Commands|Directory Management Utilities|8-4.7|9,54
For example, the command to make the user smith
the owner of your directory called reviews is:
chown smith reviews
Note that smith will now own the directory, but
until you mv or cp the directory, it will remain in
your current directory.
P21
UNIX Commands|Directory Management Utilities|8-4.8|5,54
The chmod command may be used to change the
protection for a directory the same way it does for
a file. The syntax is:
chmod mode directoryname