Linux (Chapter 3)
Linux (Chapter 3)
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.
uname COMMAND
The command ‘uname‘ displays the information about the system.
Syntax:
uname [OPTION]
Output:
Output:
Output:
Output:
Output:
Output:
Output:
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
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.
$ cat /proc/meminfo
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.
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.
There are basically seven reasons why you might lose data. These are:
1. Disks fail
• 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.
• Floppies are very cheap, fairly reliable, not very fast, very
available, but not very usable for large amounts of data.
Types of Backup
• Might not include system files which are from the install CD.
• Nightly backup only needs to include files changed since the last
full backup.
tar COMMAND
The Linux ‘tar’ stands for tape archive, is used to create an Archive and
extract the archive files.
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
/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
/home/public_html/videos/
/home/public_html/videos/
/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
OR
/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
/home/MyImages/ReesewitherspoonCIA101202.jpg
/home/MyImages/yanaguptabaresf231110.jpg
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.
/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
/home/php/object.html
/home/php/video.php
or
or
or
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
Output :
-rwxrwxrwx root/root 191 2017-09-17 02:20 os2.c
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.
Syntax :
gzip [Options] [filenames]
Example:
$ gzip mydoc.txt
$ gzip -k mydoc.txt
The above command would end up with a file called “mydoc.txt.gz” and
“mydoc.txt”.
$ gzip -L filename.gz
OUTPUT :
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
$ 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.
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
complain. This generally means that the standard uncompress does not
check its input, and happily generates garbage output.
EXAMPLES
$ gunzip myfilename.gz
output:
$ls
myfilename.gz
$ gunzip myfilename.gz
$ls
myfilename
$ gunzip -f myfilename.gz
output:
$ls
myfilename.gz
$ gunzip myfilename.gz
$ls
myfilename
$ gunzip -k myfile.gz
output:
$ls
myfilename.gz
$ gunzip -k myfilename.gz
$ls
myfilename myfilename.gz
$ gunzip -l myfile.gz
output:
$ gunzip -l myfilename.gz
compressed uncompressed ratio uncompressed_name
31 0 0.0% myfilename
$ gunzip -r /tmp
output:
$ls/tmp/
myfilename1.gz myfilename.gz
$ gunzip -r /tmp/
$ls/tmp/
myfilename myfilename1
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.
The lp COMMAND
This command is used to print files. The lp command submits files for
printing or alters a pending job.
Examples
1. Prints the file myfile.txt:
#lp myfile.txt
3. Print a text file with 12 characters per inch, 8 lines per inch, and a
1 inch left margin:
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.