You are on page 1of 6

Lab05: miscellaneous commands

Objectives
to learn processing,compression,comparison and coding commands.
1. sleep, uptime,w ,top and watch
2. ifconfig, netstate, nslookup and ping
3. md5sum ,mcrypt and mdecrypt
4. zip ,unzip,compress and uncompress
5. diff
6. comm
7. lsof,sed

1. sleep, uptime, w and watch commands


Command: sleep
Purpose: System sleeps for a given time
SYNTAX: sleep NUMBER
Examples:
sleep 5
sleep 10 && echo “ 10 seconds delay”

Command: uptime
Purpose: How long the system has been running since the last bootSYNTAX: sleep NUMBER
SYNTAX: uptime
Examples:
uptime

Command: w
Purpose: Displays the current process running in each shell for al logged-in users.
SYNTAX: w [ -s]
Examples:
w
w -s
Command: top
Purpose: Displays the current state of the system.
SYNTAX: top [ -cqSs]
Examples:
top
top -s

Command: watch
Purpose: Executes a given command at a regular interval.
SYNTAX: watch [ -ndv]
Examples:
watch –n 10 date
watch –v

2. ifconfig, netstate, nslookup and ping


Command: ifconfig
Purpose: To view the current configuration for all active interfaces.
SYNTAX: ifconfig
Examples:
ifconfig

Command: netstat
Purpose: To display information about all the TCP/IP sockets .
SYNTAX: netstat
Examples:
netstat -a

Command: nslookup
Purpose: To lookup the numerical address .
SYNTAX: nslookup
Examples:
nslookup www.bimcs.edu.pk

Command: ping
Purpose: To determine external internet service.
SYNTAX: ping
Examples:
ping www.bims.edu.pk

3. md5sum ,mcrypt and mdecrypt

Command: md5sum
Purpose: Didplays or checks an MD5 checksum on the specified filename.
SYNTAX: md5sum [ -bct]
Examples:
md5sum a1.txt
md5sum –t fun.sh

Command: mcrypt
Purpose: Encrypt the specified filenamel.
SYNTAX: mcrypt [ -auz]

Examples:
mcrypt –u a1.txt
mcrypt –z secret.doc

Command: mdecrypt
Purpose: mdecrypts a filename.
SYNTAX: mdecrypt
Examples:
mdecrypt secret.doc.enc

4. zip ,unzip,compress and uncompress


Command: zip
Purpose: combines the files and reduces the size.
SYNTAX: zip foldername *
Examples:
zip documents *
zip –u documents *

Command: unzip
Purpose: decompresses the archives.
SYNTAX: unzip zipped-filename
Examples:
unzip documents “*.doc”

Command: compress
Purpose: compresses the specified filename.
SYNTAX: compress [-vf] filename
Examples:
compress -v bigfile.exe

Command: uncompress
Purpose: decompresses the specified filename.
SYNTAX: uncompress [-vf] filename
Examples:
uncompress myfile.txt.Z

5. diff & comm. commands


Command: diff
Purpose: diff is short for different or difference and describes a program's ability to show the
difference between two or more files. (used to compare two files line by line )

SYNTAX: diff [-uc] filename1 filename2

Examples:
diff file1.txt file2.txt

Command: comm
Purpose: Compare sorted files FILE1 and FILE2 line-by-line
SYNTAX: comm file1 file2
Examples:
comm file1.txt file2.txt

With no options, comm produces three-column output. Column one contains lines unique to
FILE1, column two contains lines unique to FILE2, and column three contains lines common to
both files. Each of these columns can be suppressed individually with options.
OPTIONS:
-1 Suppress column 1(lines unique to file 1)
-2 Suppress column 2(lines unique to file 2)
-3 Suppress column 3(lines that appear in both files)

6. lsof and sed commands

Command: lsof
Purpose: to take list of open files.

SYNTAX: lsof [-cupi]

Examples:
lsof
lsof +D/var/log
lsof -u abcd
Command: sed
Purpose: Stream editor will print the desired line

SYNTAX: sed [-n] filename

Examples: sed –n ‘1p’ f1.txt # prints first line


sed –n ‘$p’ f1.txt # prints last line
sed –n ‘5,9p’ f1.txt # prints 5-9 line
Exercises

Exercises

1. Compress and uncompress a text file


2. What will be the result of the given commands.
- Sleep
- top -sS
-watch
3. Select some websites and find out the ip address of each website
4. Find out the version of IPSec protocol of Bahria University’s server.
5. Explore yourself the command “smbstatus” and then describe the command.
6. Compute checksum of a given file
7. Decompress all the files with the *.doc suffix in the specified archive ( say
Documents.zip)
8. Encrypt and decrypt an image file.
9. Compare two files and write the output in result.txt file
10. Compare the 2 files and print “Files are identical” if Files are same and if not make them
identical.

Revision Exercises

1. Write a function to get a list of all files from a desired directory .


2. Check if the input user name is the legitimate user or not.
3. Display the list of all directories and sub directories of the system.
4. Display list of all files that are created in last 20 hours.
5. Save the history of last 30 days in a text file.