Chapter 3

Back Up Next

horizontal rule

Home
Chapter 1
Chapter 2
Chapter 3
The Shell
Parameters and Variables
The Bourne Again Shell
Grep and AWK
Control Structures
Shell Program examples
TC Shell
Programming tools
Networking and the Internet

 

Commands and Utilities

cp –

The UNIX command to copy a file or directory is cp. The basic cp command syntax is cp source destination.

EXAMPLE: The command

$cp ~/.profile ~/pcopy

makes a copy of your .profile file, and stores it in a file called "pcopy" in your home directory.

mv -

The UNIX mv command moves files and directories. You can move a file to a different location in the filesystem, or change the name by moving the file within the current location.

EXAMPLE: The command

$mv ~/pcopy ~/qcopy

takes the pcopy file you created in the cp exercise, and renames it "qcopy".

lpr

The lpr command tells the system that one or more files are to be printed on the default printer. If the printer is busy with another user's file, an entry will be made in the printer queue and the file will be printed after other lpr requests have been satisfied. The command line

format is:

$lpr file-spec-list

$lpr –Pmailroom filename ( it prints file filename to printer names mailroom)

$lpq (print jobs that are in queue)

$lpr job# (lets you remove a job# that is in que queue)

grep -

The grep program can be used to search a file for lines containing a certain string:

 

$ grep string filename

$ grep -i string filename (case insensitive match)

 

or not containing a certain string:

$ grep -v string filename

 

head –

It displays the first ten lines of a file

 

$head filename

$head –1 filename (it will display the first line only)

 

tail –

It displays the last ten lines of a file

 

$tail filename

$tail –1 filename (it will display the last line only)

 

 

sort –

It displays the contents of a file in order by lines

 

$sort filename

 

uniq –

It displays a file a file, skipping adjacent duplicate lines.

Ie. There is a file called test with the contents:

boy took bat home
boy took bat home
girl took bat home
dog brought hat home
dog brought hat home
dog brought hat home

 

The command

$uniq test would display

boy took bat home
girl took bat home
dog brought hat home

 

diff-

This utility compares two files and displays a list of the differences between them.

IE. File m and its contents

aaaaa
bbbbb
ccccc

 

File n and its contents

aaaaa
ccccc

 

$diff m n

output:

2d1

< bbbbb

2d1 = indicates that you need to delete the second line from file 1 m (bbbbb) to make the same as file 2 (n)

 

file –

It displays the information about a file

$file letter_e.z

 

letter_e.z: gzip compressed data

 

echo –

This utility copies anything you put on the command line after echo

$echo Hi

Hi

 

$echo $TERM

vt100

 

date –

It displays the current date and time

gzip –

utility that compresses file

$gzip filename

it creates a file filename.gz

 

$gzip –v filename (gzip reports how much it was able to reduce.

gunzip and zcat -

$gunzip filename.gz

it restores the file to its original format

 

$zcat ginlename.gz

it displays the contents of the file without decompressing it.

 

compress & uncompress–

it compresses a file

$compress filename

resulting in a file filename.Z

 

$uncompress filename.Z

it uncompresses the file created with compress

 

tar – (tape archive)

Used to create singles files that when unpacked places files in different directories/subdirectories

An archiving program designed to store and extract files from an archive file known as a tarfile.

To combine multiple files and/or directories into a single file:

tar -cvf file.tar inputfile1 inputfile2

-c, --create a new archive

-v, --verbosely list files processed

-f, --file [HOSTNAME:]F use archive file or device F (default /dev/rmt0) (saying that we to join files not create a tape archive)

To separate an archive created by tar into separate files:

tar -xvf file.tar

bulletLots of info about tar

Finding Utilities and other Files

which –

Helps you locate commands by giving the full pathname to the file for the command.

Takes a series of program names, and prints out the full pathname of the program that the shell would call to execute it

i.e. which info

whereis –

locates source/binary and manuals sections for specified files.

 

apropos –

apropos searches a set of database files containing short descriptions of system commands for keywords and displays the result on the standard output. It includes the name of the command, the manual where is can be foind and a brief description.

Obtaining user and system information

who-, who am i

show who is logged on

[wmorales@rc33uxas01 wmorales]$ who

(user id) (terminal

designation) (name of remote computer)

dmichels pts/0 Jan 26 09:40(198.106.33.162)
psheehan pts/2 Jan 26 10:06(fw1.tek.com)
wmorales pts/1 Jan 26 10:22(198.106.33.204)
tyoung pts/3 Jan 26 10:32(198.106.33.175)

finger –

The finger displays information about the system users.

[wmorales@rc33uxas01 wmorales]$ finger

Login Name Tty Idle Login Time Office Office Phone

qnguyen /0 Jan 26 13:34 (198.106.33.161)
wmorales /2 Jan 26 13:19 (192.220.32.72)

[wmorales@rc33uxas01 wmorales]$

finger-l

Login: psheehan Name:

Directory: /home/stu//psheehan Shell: /bin/bash

On since Wed Jan 26 10:06 (PST) on pts/2 from fw1.tek.com

36 minutes 5 seconds idle

No mail.

No Plan.

Login: wmorales Name:

Directory: /home/fac/wmorales Shell: /bin/bash

 

-l Produces a multi-line format displaying all of the information de scribed for the -s option as well as the user's home directory, home phone number, login shell, mail status, and the contents of the files ``.plan'' and ``.project'' and ``.forward'' from the user's home directory.

Finger may be used to look up users on a remote machine. finger foo@machine.com

Try fingering these addresses:

bulletquake@geophys.washington.edu

 

w-

displays information about the users currently on the machine, and their processes. The header shows, in this order, the current time, how long the system has been running, how many users are currently logged on, and the system load averages for the past 1, 5, and 15 minutes.

The JCPU time is the time used by all processes attached to the tty.

The PCPU time is the time used by the current process, named in the "what" field.

 

10:46am up 19 days, 4:55, 4 users, load average: 0.01, 0.00, 0.00

USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT

dmichels pts/0 198.106.33.162 9:40am 2:16 0.09s 0.04s -bash
psheehan pts/2 fw1.tek.com 10:06am 39:19 0.12s 0.05s -bash
wmorales pts/1 198.106.33.204 10:22am 0.00s 0.11s 0.02s w
tyoung pts/3 198.106.33.175 10:32am 8:26 0.09s 0.02s -bash

[wmorales@rc33uxas01 wmorales]$

 

 

Communication with other users

write -

Write allows you to communicate with other users, by copying lines from your terminal to theirs.

When you run the write command, the user you are writing to gets a message of the form:

Message from yourname@yourhost on yourtty at hh:mm

Type:

write username

What is up?

CTRL-D (end of file)

Turn it off by using $mesg n turn it on again using mesg y

talk-

Talk is a visual communication program which copies lines from your terminal to that of another user.

Type:

talk username tty (if logged in more then once)

user sees:

When first called, talk sends the message

Message from TalkDaemon@his_machine...

talk: connection requested by your_name@your_machine.

talk: respond with: talk your_name@your_machine

 

Email Pine Elm Mail mailx

 

 

horizontal rule

Back to CS140U Homepage
This page was last modified September 26, 2004
wmorales@pcc.edu