0% found this document useful (0 votes)
10 views35 pages

Linux (Chapter 3)

Uploaded by

jadhashrikant
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views35 pages

Linux (Chapter 3)

Uploaded by

jadhashrikant
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 35

LINUX OPERATING SYSTEM

GATHERING
IMPORTANT SYSTEM
INFORMATION
hostname COMMAND
 hostname command in Linux is used to obtain the DNS(Domain Name
System) name and set the system’s hostname or NIS(Network
Information System) domain name.
 A hostname is a name that is given to a computer and is attached to the
network. Its main purpose is to uniquely identify over a network.
Syntax :
hostname -[option] [file]
 Example: We obtain the system hostname by just typing hostname
without any attributes.

ASST. PROF. ZEENAT SULTANA


LINUX OPERATING SYSTEM

Options and Examples:


1. -a : his option is used to get the alias name of the host system(if
any). It will return an empty line if no alias name is set. This option
enumerates all configured addresses on all network interfaces.
Syntax:
hostname -a

uname COMMAND
 The command ‘uname‘ displays the information about the system.
Syntax:
uname [OPTION]

Options and Examples


1. -a option: It prints all the system information in the following
order: Kernel name, network node hostname, kernel release

ASST. PROF. ZEENAT SULTANA


LINUX OPERATING SYSTEM

date, kernel version, machine hardware name, hardware


platform, operating system.
Syntax:
$uname -a

Output:

2. -s option: It prints the kernel name.


Syntax:
$uname -s

Output:

3. -n option: It prints the hostname of the network node(current


computer).
Syntax:
$uname -n

ASST. PROF. ZEENAT SULTANA


LINUX OPERATING SYSTEM

Output:

4. -r option: It prints the kernel release date.


Syntax:
$uname -r
Output:

5. -v option: It prints the version of the current kernel.


Syntax:
$uname -v

Output:

ASST. PROF. ZEENAT SULTANA


LINUX OPERATING SYSTEM

6. -m option: It prints the machine hardware name.


Syntax:
$uname -m

Output:

7. -p option: It prints the type of the processor.


Syntax:
$uname -p

Output:

8. -i option: It prints the platform of the hardware.


Syntax:
$uname -i

Output:

ASST. PROF. ZEENAT SULTANA


LINUX OPERATING SYSTEM

9. -o option: It prints the name of the operating system.


Syntax :
$uname -o

Output:

cat /proc/cpuinfo
 The file /proc/cpuinfo displays what type of processor your system is
running including the number of CPUs present. Here is an example
output from cat /proc/cpuinfo of a system.

# cat /proc/cpuinfo
processor :0
vendor_id : GenuineIntel
cpu family :6
model : 45
model name : Intel(R) Xeon(R) CPU E5-2660 0 @ 2.20GHz
stepping :6
microcode : 1561
cpu MHz : 600.000
ASST. PROF. ZEENAT SULTANA
LINUX OPERATING SYSTEM

cache size : 20480 KB


physical id :0
siblings : 16
core id :0
cpu cores :8
apicid :0
initial apicid : 0
fpu : yes
fpu_exception : yes
cpuid level : 13
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov
pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb
rdtscp lm constant_tsc arch_perfmon pebs bts rep_good xtopology nonstop_tsc
aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 cx16
xtpr pdcm pcid dca sse4_1 sse4_2 x2apic popcnt tsc_deadline_timer aes xsave
avx lahf_lm ida arat epb pln pts dtherm tpr_shadow vnmi flexpriority ept vpid
xsaveopt
bogomips : 4399.93
clflush size : 64
cache_alignment : 64
address sizes : 46 bits physical, 48 bits virtual
power management:

ASST. PROF. ZEENAT SULTANA


LINUX OPERATING SYSTEM

 Below is the various items you would see in the output and their
respective explanations.
 processor – Provides each processor with an identifying number.
If you have one processor it will display a 0. If you have more than
one processor it will display all processor information separately
counting the processors using zero notation.
 cpu family – Authoritatively tells you the type of processor you
have in the system. If your computer is an Intel-based system,
simply place the number in front of “86” to determine the value.
This is helpful to determine the type of architecture of an older
system and is helpful in determining which compiled RPM
package would best suit that system.
 model name – Gives you the common name of the processor,
including the project name.
 cpu MHz – Shows the processor’s precise speed, in megahertz, to
the thousandth decimal point.
 cache size – Tells you the amount of level 2 memory cache
available to the processor.
 flags – Defines a number of different processor attributes, such as
the presence of a floating-point unit (FPU) and the ability to
process MMX instructions.

ASST. PROF. ZEENAT SULTANA


LINUX OPERATING SYSTEM

$ cat /proc/meminfo

 Print details about the memory or RAM as follows:


 Print the total memory (RAM) available...

ASST. PROF. ZEENAT SULTANA


LINUX OPERATING SYSTEM

BACKUP AND
RESTORE FILES
 Backup and restore capabilities are key to ensuring data recoverability
for any operating system.
 Why should you bother making backups? Because computers fail: hard
drives fail, making it impossible to get your data from them; systems
and software crash, sometimes corrupting or deleting your important
documents.
 With a backup, you’re mostly protected: only the very latest changes, if
any, are lost when you restore a backed-up file.
 One of the great things about Linux is the number of tools included in
the distribution to help you manage your system.

BACKUP AND RESTORE FILES

 Your data is valuable. It will cost you time and effort to re-create it, and
that costs money or at least personal grief and tears; sometimes it can’t
even be re-created, e.g., if it is the results of some experiments.
 Since it is an investment, you should protect it and take steps to avoid
losing it.

ASST. PROF. ZEENAT SULTANA


LINUX OPERATING SYSTEM

Reasons for Backup

 There are basically seven reasons why you might lose data. These are:

1. Disks fail

2. Bugs in software can cause corruption

3. Configuration mistakes by administrator

4. Accidental deletion or overwriting (e.g., with rm, mv or cp)

5. Malicious deletion or virus attack

6. Theft of machines with hard drives in

7. Fire, or other natural disasters which can destroy hardware

 Backups are a way to protect the investment in data. By having several


copies of the data, it does not matter as much if one is destroyed (the
cost is only that of the restoration of the lost data from the backup).
 It is important to do backups properly.

Selecting the Backup Media

 The most important decision regarding backups is the choice of backup


medium. You need to consider cost, reliability, speed, availability, and
usability.

• Cost is important, since you should preferably have several


times more backup storage than what you need for the data. A
cheap medium is usually a must.

ASST. PROF. ZEENAT SULTANA


LINUX OPERATING SYSTEM

• Reliability is extremely important. A backup medium must be


able to hold data without corruption for years. The way you use
the medium affects it reliability as a backup medium. A hard disk
is typically very reliable, but as a backup medium it is not very
reliable, if it is in the same computer as the disk you are backing
up.

• Speed is usually not very important, if backups can be done


without interaction. It doesn’t matter if a backup takes two hours,
as long as it needs no supervision. On the other hand, if the
backup can’t be done when the computer would otherwise be idle,
then speed is an issue.

• Availability is obviously necessary since you can’t use a backup


medium if it doesn’t exist. Less obvious is the need for the
medium to be available even in the future, and on computers
other than your own. Otherwise, you may not be able to restore
your backups after a disaster.

• Usability is a large factor in how often backups are made. The


easier it is to make backups, the better. A backup medium mustn’t
be hard or boring to use.

1. Traditionally, backups have been made onto tapes and floppies.

• You can store lots of data on reasonably cheap tapes. Tapes are
cheap to somewhat expensive, fairly reliable, fairly fast, quite
available, and, depending on the size of the tape, quite
comfortable.

ASST. PROF. ZEENAT SULTANA


LINUX OPERATING SYSTEM

• Floppies are very cheap, fairly reliable, not very fast, very
available, but not very usable for large amounts of data.

2. Copying to a different hard disk.

• There is a risk of losing the backup along with the original

• Better if on a remote computer

3. CD writers can be used to store backups on CDs.

• Convenient for long-term storage

• Handy to remove to remote locations

Types of Backup

 There are following three types of backup in Linux:

1. Full Backup – Includes everything of importance:

• Might not include system files which are from the install CD.

• Can include a lot of files, many of which hardly ever change.

2. Differential Backup – Only includes changes since last full backup:

• Nightly backup only needs to include files changed since the last
full backup.

• Recovery requires the full backup on which it was based.

3. Incremental Backup – Only includes changes since last backup:

• Nightly backup only includes files changed in the last 24 hours.

ASST. PROF. ZEENAT SULTANA


LINUX OPERATING SYSTEM

• Recovery requires the last full backup and a complete sequence


of incremental backups after that.

Backup Strategy: Simple Backups

 A simple backup scheme is to back up everything once, then back up


everything that has been modified since the previous backup.
 The first backup is called a full backup, the subsequent ones are
incremental backups.
 A full backup is often more laborious than incremental ones, since there
is more data to write to the tape and a full backup might not fit onto one
tape (or floppy).
 Restoring from incremental backups can be many times more work than
from a full one.
 Restoration can be optimized so that you always back up everything
since the previous full backup; this way, backups are a bit more work,
but there should never be a need to restore more than a full backup and
an incremental backup.

ASST. PROF. ZEENAT SULTANA


LINUX OPERATING SYSTEM

tar COMMAND
 The Linux ‘tar’ stands for tape archive, is used to create an Archive and
extract the archive files.

 tar command in Linux is one of the important command which provides


archiving functionality in Linux. We can use Linux tar command to
create compressed or uncompressed Archive files and also maintain and
modify them.

Syntax:
tar [options] [archive-file] [file or directory to be archived]

 Options:
-c : Creates Archive
-x : Extract the archive
-f : creates archive with given filename
-t : displays or lists files in archived file
-u : archives and adds to an existing archive file
-v : Displays Verbose Information
-A : Concatenates the archive files
-z : zip, tells tar command that creates tar file using gzip
-j : filter archive tar file using tbzip
-r : update or add file or directory in already existed .tar file

 What is an Archive file?


An Archive file is a file that is composed of one or more files along with
metadata. Archive files are used to collect multiple data files together

ASST. PROF. ZEENAT SULTANA


LINUX OPERATING SYSTEM

into a single file for easier portability and storage, or simply to


compress files to use less storage space.

Options and Examples:

1. Creating an uncompressed tar Archive using option -cvf : This


command creates a tar file called file.tar which is the Archive of all .c
files in current directory.

# tar -cvf tecmint-14-09-12.tar /home/tecmint/

/home/tecmint/
/home/tecmint/cleanfiles.sh
/home/tecmint/openvpn-2.1.4.tar.gz
/home/tecmint/tecmint-14-09-12.tar
/home/tecmint/phpmyadmin-2.11.11.3-1.el5.rf.noarch.rpm
/home/tecmint/rpmforge-release-0.5.2-2.el5.rf.i386.rpm

2. Extracting files from Archive using option -xvf : This command


extracts files from Archives.

# tar -xvf public_html-14-09-12.tar –C

/home/public_html/videos/

/home/public_html/videos/

ASST. PROF. ZEENAT SULTANA


LINUX OPERATING SYSTEM

/home/public_html/videos/views.php

/home/public_html/videos/index.php

/home/public_html/videos/logout.php

/home/public_html/videos/all_categories.php

/home/public_html/videos/feeds.xml

3. gzip compression on the tar Archive, using option -z : This


command creates a tar file called file.tar.gz which is the Archive of .c
files.

# tar cvzf MyImages-14-09-12.tar.gz /home/MyImages

OR

# tar cvzf MyImages-14-09-12.tgz /home/MyImages

/home/MyImages/

/home/MyImages/Sara-Khan-and-model-Priyanka-
Shah.jpg

/home/MyImages/RobertKristenviolent101201.jpg

/home/MyImages/Justintimerlake101125.jpg

/home/MyImages/Mileyphoto101203.jpg

/home/MyImages/JenniferRobert101130.jpg

/home/MyImages/katrinabarbiedoll231110.jpg

/home/MyImages/the-japanese-wife-press-conference.jpg

ASST. PROF. ZEENAT SULTANA


LINUX OPERATING SYSTEM

/home/MyImages/ReesewitherspoonCIA101202.jpg

/home/MyImages/yanaguptabaresf231110.jpg

4. Extracting a gzip tar Archive *.tar.gz using option -xvzf : This


command extracts files from tar archived file.tar.gz files.
#tar xvzf file.tar.gz

5. Creating compressed tar archive file in Linux using option -j: This
command compresses and creates archive file less than the size of the
gzip. Both compress and decompress takes more time then gzip.

# tar cvfj Phpfiles-org.tar.bz2 /home/php


OR
# tar cvfj Phpfiles-org.tar.tbz /home/php
OR
# tar cvfj Phpfiles-org.tar.tb2 /home/php

/home/php/
/home/php/iframe_ew.php
/home/php/videos_all.php
/home/php/rss.php
/home/php/index.php
/home/php/vendor.php
/home/php/video_title.php
/home/php/report.php

ASST. PROF. ZEENAT SULTANA


LINUX OPERATING SYSTEM

/home/php/object.html
/home/php/video.php

6. Untar single tar file or specified directory in Linux: This command


will Untar a file in the current directory or in a specified directory using
the -C option.

$ tar xvfj file.tar

or

$ tar xvfj file.tar -C path of a file in the directory

7. Untar multiple .tar, .tar.gz, .tar.tbz file in Linux : This command


will extract or untar multiple files from the tar, tar.gz and tar.bz2
archive file. For example the above command will extract “fileA” “fileB”
from the archive files.

$ tar xvf file.tar "fileA" "fileB"

or

$ tar zxvf file1.tar.gz "fileA" "fileB"

or

$ tar jxvf file2.tar.tbz "fileA" "fileB"

ASST. PROF. ZEENAT SULTANA


LINUX OPERATING SYSTEM

8. Update existing tar file in Linux


$ tar rvf file.tar *.c

9. list the contents and specify the tar file using option -tf : This
command will list the entire list of archived file. We can also list for
specific content in a tar file

$ tar tf file.tar

Output :
example.cpp

10. Applying pipe to through ‘grep command’ to find what we are


looking for : This command will list only for the mentioned text or
image in grep from archived file.

$ tar tvf file.tar | grep "text to find"


or
$ tar tvf file.tar | grep "filename.file extension"

11. Viewing the Archive using option -tvf

$ tar tvf file.tar

Output :
-rwxrwxrwx root/root 191 2017-09-17 02:20 os2.c

ASST. PROF. ZEENAT SULTANA


LINUX OPERATING SYSTEM

-rwxrwxrwx root/root 218 2017-09-17 02:20 os3.c

-rwxrwxrwx root/root 493 2017-09-17 02:20 os4.c

 What are wildcards in Linux


 Alternatively referred to as a ‘wild character’ or ‘wildcard character’, a
wildcard is a symbol used to replace or represent one or more
characters.
 Wildcards are typically either an asterisk (*), which represents one or
more characters or question mark (?),which represents a single
character.

ASST. PROF. ZEENAT SULTANA


LINUX OPERATING SYSTEM

ASST. PROF. ZEENAT SULTANA


LINUX OPERATING SYSTEM

gzip COMMAND
 gzip command compresses files. Each single file is compressed into a
single file.
 The compressed file consists of a GNU zip header and deflated data.
If given a file as an argument, gzip compresses the file, adds a “.gz”
suffix, and deletes the original file.
 With no arguments, gzip compresses the standard input and writes the
compressed file to standard output.
 Difference between Gzip and zip command in Unix and when to use
which command
 ZIP and GZIP are two very popular methods of compressing files,
in order to save space, or to reduce the amount of time needed to
transmit the files across the network, or internet.
 In general, GZIP is much better compared to ZIP, in terms of
compression, especially when compressing a huge number of files.
 The common practice with GZIP, is to archive all the files into a
single tarball before compression. In ZIP files, the individual files
are compressed and then added to the archive.
 When you want to pull a single file from a ZIP, it is simply
extracted, then decompressed. With GZIP, the whole file needs to
be decompressed before you can extract the file you want from
the archive.
 When pulling a 1MB file from a 10GB archive, it is quite clear that
it would take a lot longer in GZIP, than in ZIP.

ASST. PROF. ZEENAT SULTANA


LINUX OPERATING SYSTEM

 GZIP’s disadvantage in how it operates, is also responsible for


GZIP’s advantage. Since the compression algorithm in GZIP
compresses one large file instead of multiple smaller ones, it can
take advantage of the redundancy in the files to reduce the file
size even further.
 If you archive and compress 10 identical files with ZIP and GZIP,
the ZIP file would be over 10 times bigger than the resulting GZIP
file.

Syntax :
gzip [Options] [filenames]
 Example:
$ gzip mydoc.txt

 This command will create a compressed file of mydoc.txt named as


mydoc.txt.gz and delete the original file.

Options with Examples :


1. -k option :By default when you compress a file using the “gzip”
command you end up with a new file with the extension “.gz”.If you
want to compress the file and keep the original file you have to run the
gzip command with -k option:

$ gzip -k mydoc.txt

The above command would end up with a file called “mydoc.txt.gz” and
“mydoc.txt”.

ASST. PROF. ZEENAT SULTANA


LINUX OPERATING SYSTEM

2. -L option : This option displays the gzip license.

$ gzip -L filename.gz
OUTPUT :

Apple gzip 264.50.1 (based on FreeBSD gzip 20111009)

Copyright (c) 1997, 1998, 2003, 2004, 2006 Matthew R. Green

All rights reserved.

3. -r option : This option can compress every file in a folder and its
subfolders.This option doesn’t create one file called foldername.gz.
Instead, it traverses the directory structure and compresses each file in
that folder structure.

gzip -r testfolder

This will compress all the files present in the testfolder.

4. -[1-9] option : It allows to change the compression level.A file can be


compressed in different ways. For instance, you can go for a smaller
compression which will work faster or you can go for maximum
compression which has the tradeoff of taking longer to run.The speed
and compression level can vary by levels using numbers between 1 and
9.
$ gzip -1 mydoc.txt

ASST. PROF. ZEENAT SULTANA


LINUX OPERATING SYSTEM

This will get maximum compression at the slowest speed

$ gzip -9 mydoc.txt
To get minimum compression at the fastest speed

5. -v option: This option displays the name and percentage reduction for
each file compressed or decompressed.

$ gzip -v mydoc.txt

OUTPUT :
new.txt: 18.2% -- replaced with new.txt.gz

gunzip COMMAND
 gunzip can decompress files created by gzip, zip.

 The detection of the input format is automatic. When using the first two
formats, gunzip checks a 32 bit CRC.

 The standard compress format was not designed to allow consistency


checks.

 However gunzip is sometimes able to detect a bad .Z file.

 If you get an error when uncompressing a .Z file, do not assume that the
.Z file is correct simply because the standard uncompress does not

ASST. PROF. ZEENAT SULTANA


LINUX OPERATING SYSTEM

complain. This generally means that the standard uncompress does not
check its input, and happily generates garbage output.

EXAMPLES

Example-1:To Decompress A File Using The "gunzip" Command:

$ gunzip myfilename.gz

output:

$ls
myfilename.gz

$ gunzip myfilename.gz

$ls
myfilename

Example-2:Force A File To Decompress:

$ gunzip -f myfilename.gz

output:

$ls
myfilename.gz

$ gunzip myfilename.gz

$ls
myfilename

Example-3:To keep both the compressed and decompressed file:

$ gunzip -k myfile.gz

ASST. PROF. ZEENAT SULTANA


LINUX OPERATING SYSTEM

output:

$ls
myfilename.gz

$ gunzip -k myfilename.gz

$ls
myfilename myfilename.gz

Example-4:To display compressed output:

$ gunzip -l myfile.gz

output:

$ gunzip -l myfilename.gz
compressed uncompressed ratio uncompressed_name
31 0 0.0% myfilename

Example-5:Decompressing Lots Of Files Recursively:

$ gunzip -r /tmp

output:

$ls/tmp/
myfilename1.gz myfilename.gz

$ gunzip -r /tmp/

$ls/tmp/
myfilename myfilename1

ASST. PROF. ZEENAT SULTANA


LINUX OPERATING SYSTEM

PRINTING
COMMANDS IN
LINUX
 Linux includes a number of command line tools for administering
printing. These commands are useful on networks, or for
troubleshooting and managing printing on any system.
 Each printer on a Linux system has its own spool or queue in the
/var/spool/lpd directory.
 This spool uses the short name of the printer, which is created when the
printer is first configured.
 When a file is printed, it becomes a job in the spool. Each job is stored in
a spool until it is printed.
 Printing tools generally start with lp (short for “line printer”). You can
use the following tools for managing printing:
1. lp: Prints a file on System V systems.

2. lpq : Checks the status of print jobs.

ASST. PROF. ZEENAT SULTANA


LINUX OPERATING SYSTEM

3. lprm : Removes a print job from a spool.

4. lpstat : Reads the status of a spool.

5. lpc: stop the queue.

The lp COMMAND
 This command is used to print files. The lp command submits files for
printing or alters a pending job.

Syntax: lp -i request-ID [-c] [-m] [-p] [-s] [-w] [-d


destination] [-f form-name] [-H special-handling] [-n
number] [-o options] [-p pagenumbers] [-q priority-
level] [-S character-set| print-wheel] [-t title] [-T
content-type [-r]] [-y mode-list]

 Examples
1. Prints the file myfile.txt:
#lp myfile.txt

2. Print an image across 4 pages:

#lp -d bar -o scaling=200 filename

3. Print a text file with 12 characters per inch, 8 lines per inch, and a
1 inch left margin:

#lp -d bar -o cpi=12 -o lpi=8 -o page-left=72 filename


ASST. PROF. ZEENAT SULTANA
LINUX OPERATING SYSTEM

Options :
 -c : Makes a copy of the file that is being printed.
 -m : Sends e-mail when the printing is done.
 -w : Displays message on screen when printing is done.
 -d : destination The name of the printer that you want your
printing to print on.
 -n number : The number of files to be printed.

ASST. PROF. ZEENAT SULTANA


LINUX OPERATING SYSTEM

 -H : special- Prints the print request according to the value of


special-handling. The handling following handling special-
handling values are acceptable:

hold Do not print the print request until notified. If printing


has already begun, stop it. Other print requests will go
ahead of a request that has been put on hold (held print
request) until the print request is resumed.

resume Resume a held print request. If the print request


had begun to print when held, it will be the next print
request printed, unless it is superseded by an immediate
print request.

immediate Print the print request next. If more than one


print request is assigned, the most recent print request is
printed next. If a print request is currently printing on the
desired printer, a hold request must be issued to allow the
immediate request to print.
The immediate request is only available to LP

ASST. PROF. ZEENAT SULTANA


LINUX OPERATING SYSTEM

Printing a File Using lpr command


 By far, the most simplistic way to print in the Linux operating system is
to send the file to be printed directly to the printing device. One way to
do this is to use the cat command. As the root user, one could do
something like

# cat thesis.txt > /dev/lp

 In this case, /dev/lp is a symbolic link to the actual printing device—be


it a dot- matrix, laser printer, typesetter, or plotter.
 For the purpose of security, only the root user and users in the same
group as the print daemon are able to write directly to the printer. This
is why commands such as lpr, lprm, and lpq have to be used to access
the printer.
 Because of this, users have to use lpr to print a file.
 The lpr command takes care of all the initial work needed to print the
file, and then it hands control over to another program, lpd, the line
printing daemon. The line printing daemon then tells the printer how to
print the file.
 When lpr is executed, it first copies the specified file to a certain
directory (the spool directory) where the file remains until lpd prints it.
 Once lpd is told that there is a file to print, it will spawn a copy of itself.
This copy will print our file while the original copy waits for more
requests. This allows for multiple jobs to be queued at once.
 The syntax of lpr(1) is a very familiar one,

ASST. PROF. ZEENAT SULTANA


LINUX OPERATING SYSTEM

$ lpr [ options ] [ filename ... ] or


$ lpr [ -P destination ] [ -# number ] [ -C class] [ -J job ] [ -T title ] [
-i [ indent ] ] [-1 | -2 | -3 | -4 font ] [ -w cols ] [ -m ] [ -h ] [ -s ] [-
filter_option ] [ file ...]
 If filename is not specified, lpr expects input to come from standard
input (usually the keyboard, or another program’s output). This enables
the user to redirect a command’s output to the print spooler. As such,
$ cat thesis.txt | lpr
or,
$ pr -l60 thesis.txt | lpr
 The lpr command accepts several command-line arguments that allow a
user to control how it works.

Viewing the Print Queue with lpq


 To view the contents of the print queue, use the lpq command. Issued
without arguments, it returns the contents of the default printer’s
queue.
 The returned output of lpq can be useful for many purposes.
$ lpq
lp is ready and printing
Rank Owner Job Files Total Size
active mwf 31 thesis.txt 682048 bytes

ASST. PROF. ZEENAT SULTANA


LINUX OPERATING SYSTEM

Canceling a Print Job Using lprm


 Another useful feature of any printing system is the ability to cancel a
job that has been previously queued. To do this, use lprm.
 $ lprm -The above command cancels all of the print jobs that are owned
by the user who issued the command.
 A single print job can be canceled by first getting the job number as
reported by lpq and then giving that number to lprm. For example,
$ lprm 31
 would cancel job 31 (thesis.txt) on the default printer.

Controlling the lpd Program with lpc


 The lpc program is used to control the printers that lpd serves. You can
enable or disable a printer or its queues, rearrange entries within a
queue, and get a status report on the printers and their queues.
Syntax
lpc [ command [ parameter] ]
 lpc is mostly used in a setup where there are multiple printers hanging
off one machine.
$ lpc
 The above will start the lpc program. By default, this enters you into an
interactive mode, and you can begin issuing commands.
 The other option is to issue an lpc command on the command line.
$ lpc status all

ASST. PROF. ZEENAT SULTANA

You might also like