Basic Unix Commands: Cat - List A File

Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

BASIC UNIX COMMANDS

You must first logon to a UNIX machine. The method(s) to do this vary, so check with the facility you are at
on how to logon.

Once logged on, these commands are essential to learn. More information about them (and other commands)
can be obtained by entering man command (short for manual). For example, to obtain a manual about the
command cat, you would type man cat.

cat - List a file

USAGE: cat [ -n ] file...


OPTIONS: -n display line numbers.
EXAMPLES: cat myprog.c
cat -n myprog.c

cd - Change directory

USAGE: cd [ directory ]
EXAMPLES: cd
cd mysource
NOTE: The command cd with no arguments will take you to your home directory ( i.e.
the directory you start in when you first login to the system ).
The command cd .. will take you to the directory above the one you are in.

cp - Copy a file

USAGE: cp file1 file2


cp file1 ...directory
EXAMPLE: cp myprog.c myprog.1.save
NOTE: Suppose your instructor tells you to get a copy of the file firstprog.p that is in the
directory /u/mathcs/fs/wilma. The complete command to copy this file to the directory
you are in is:
cp /u/mathcs/fs/wilma/firstprog.p firstprog.p
It is important to note that the forward slash "/" is used to specify path names.

logout - Exit unix

USAGE: logout
NOTE: Where you are returned to when you logout is depending on the method used to login
to the unix system. If you try to logout and you get an error message
“there are stopped jobs”, then type a fg command to go back to that job, then
you can properly exit the session and logout.

lpr - Send a job to the printer

USAGE: lpr [-J -C] filename


EXAMPLE: lpr -J name -C WALAB_xx filename
name is 1-8 character ID
xx is a bin number
NOTE: The pr command formats and prints the contents of a file.
[ \\hermes\user\WALAB\LABDOCS\User Guides\BEG_UNIX.DOC] STUDENT TECHNOLOGY SERVICE CENTER 12/03/98 Page 1 of 3
BASIC UNIX COMMANDS

ls - List the contents of the current directory

USAGE: ls [ file1... ]
EXAMPLES: ls
ls *.exe (this lists only files that end with the extension .exe)
ls pkzip.* (this lists only files that begin with pkzip and has any extension)
mkdir - Create a new directory

USAGE: mkdir directory...


EXAMPLE: mkdir junkdir

more - List a long file

USAGE: more file ...


EXAMPLES: more myprog.c
more a.c b.c c.c
NOTE: You can also use this with other unix commands that involves listing data.
EXAMPLES: finger |more
cat file |more

mv - Rename or move a file

USAGE: mv file1 file2


mv file1 ... directory
EXAMPLE: mv a.out myfirst

passwd - Change login passwd

USAGE: passwd
NOTE: As you type in the passwords, the characters are not displayed on the screen.

pwd - Display the current directory

USAGE: pwd
NOTE: pwd tells you which directory you are in.

rm - Remove file(s)

USAGE: rm file...
EXAMPLE: rm myfirst.old

rmdir - Remove an empty directory

USAGE: rmdir directory ...


EXAMPLE: rmdir junkdir
NOTE: In order to remove a directory that contains files, you must first remove the files with
rm and then remove the directory with rmdir.

[ \\hermes\user\WALAB\LABDOCS\User Guides\BEG_UNIX.DOC] STUDENT TECHNOLOGY SERVICE CENTER 12/03/98 Page 2 of 3


BASIC UNIX COMMANDS

finger - display information about local and remote users.

USAGE: finger

NOTE: If you use this command followed by a user’s login name, it will give some information
about that’s user’s account; directory route, last time he or she logged in, etc.

USAGE: finger user...


EXAMPLE: finger stsc

who - Identifies who is currently logged on the unix machine, but displays less information than
with the “finger” command.

USAGE: who

spell - It checks your documents for spelling errors using an online dictionary.

USAGE: spell file


EXAMPLE: spell commands.txt

pine - Starts up the “pine” mailing menu.

USAGE: pine
NOTE: This program allows you to organize your e-mail, plus has other unique features that
the Regular mailing system doesn’t provide. You can also pick up a user guide for
“pine” as well.

[ \\hermes\user\WALAB\LABDOCS\User Guides\BEG_UNIX.DOC] STUDENT TECHNOLOGY SERVICE CENTER 12/03/98 Page 3 of 3

You might also like