A Secure and Reliable Document Management System is Essential.docx
Linux Shell Scripting Presantion
1.
2. Que. Describe the following disc space management
a. df
b. du
df :- In this guide, we are going to learn to use df command. The df command, stands for Disk Free, reports
file system disk space usage. It displays the amount of disk space available on the file system in a Linux system.
The df command is not to be confused with du command. Both serves different purposes. The df command
reports how much disk space we have (i.e free space) whereas the du command reports how much disk space
is being consumed by the files and folders. Hope I made myself clear. Let us go ahead and see some more tools
for checking disk space utilization in Linux. However, Linux has a strong built in utility called ‘df‘. The ‘df‘ command
stand for “disk filesystem“, it is used to get full summary of available and used disk space usage of file system on
Linux system.
Using ‘-h‘ parameter with (df -h) will shows the file system disk space statistics in “human readable” format,
means it gives the details in bytes, mega bytes and gigabyte. This article explain a way to get the full
information of Linux disk space usage with the help of ‘df‘ command with their practical examples. So, you
could better understand the usage of df command in Linux.
Syntax :-
SGN.
3. 1. Check File System Disk Space Usage
On the internet you will find plenty of
tools for checking disk space utilization in
Linux. However, Linux has a strong built in
utility called ‘df‘. The ‘df‘ command stand
for “disk filesystem“, it is used to get full
summary of available and used disk space
usage of file system on Linux system.
Using ‘-h‘ parameter with (df -h) will shows
the file system disk space statistics in
“human readable” format, means it gives
the details in bytes, mega bytes and
gigabyte.
The “df” command displays the
information of device name, total blocks,
total disk space, used disk space, available
disk space and mount points on a file
system.
[root@tecmint ~]# df
Filesystem 1K-blocks
Used Available Use% Mounted on
/dev/cciss/c0d0p2 78361192
23185840 51130588 32% /
/dev/cciss/c0d0p5 24797380
22273432 1243972 95% /home
/dev/cciss/c0d0p3 29753588
25503792 2713984 91% /data
/dev/cciss/c0d0p1 295561
21531 258770 8% /boot
tmpfs 257476
0 257476 0% /dev/shm
SGN.
4. Display Information of all File
System Disk Space Usage
The same as above, but it
also displays information of
dummy file systems along
all the file system disk usage
and their memory utilization.
[root@tecmint ~]# df -a
Filesystem 1K-blocks Used Available
Use% Mounted on
/dev/cciss/c0d0p2 78361192 23186116
51130312 32% /
proc 0 0 0 - /proc
sysfs 0 0 0 - /sys
devpts 0 0 0 -
/dev/pts
/dev/cciss/c0d0p5 24797380 22273432
1243972 95% /home
/dev/cciss/c0d0p3 29753588 25503792
2713984 91% /data
/dev/cciss/c0d0p1 295561 21531
258770 8% /boot
tmpfs 257476 0 257476
0% /dev/shm
none 0 0 0 -
/proc/sys/fs/binfmt_misc
sunrpc 0 0 0 -
/var/lib/nfs/rpc_pipefs
SGN.
5. Show Disk Space Usage in Human
Readable Format
Have you noticed that above
commands displays information in
bytes, which is not readable yet all,
because we are in a habit of reading
the sizes in megabytes, gigabytes etc.
it makes very easy to understand
and remember.
The df command provides an
option to display sizes in Human
Readable formats by using ‘-h’
the results in human readable format
(e.g., 1K 2M 3G))
tecmint ~]# df -h
Filesystem Size
Used Avail Use% Mounted on
/dev/cciss/c0d0p2 75G
23G 49G 32% /
/dev/cciss/c0d0p5 24G
22G 1.2G 95% /home
/dev/cciss/c0d0p3 29G
25G 2.6G 91% /data
/dev/cciss/c0d0p1 289M
22M 253M 8% /boot
tmpfs 252M
0 252M 0% /dev/shm
SGN.
6. Display Information of
/home File System
To see the information
of only,
device /home file
system in human
format use the following
command.
[root@tecmint ~]# df -hT /home
Filesystem Type Size Used
Avail Use% Mounted on
/dev/cciss/c0d0p5ext3 24G 22G
1.2G 95% /home
SGN.
7. Display Information
of File System in
Bytes.
To display all file system
information and usage
in 1024- byte blocks, use
option ‘-k‘ (e.g. – block-
size=1K) as follows.
[root@tecmint ~]# df -k
Filesystem 1K-blocks
Used Available Use% Mounted on
/dev/cciss/c0d0p2 78361192
23187212 51129216 32% /
/dev/cciss/c0d0p5 24797380
22273432 1243972 95% /home
/dev/cciss/c0d0p3 29753588
25503792 2713984 91% /data
/dev/cciss/c0d0p1 295561
21531 258770 8% /boot
tmpfs 257476
0 257476 0% /dev/shm
SGN.
8. Display Information of
File System in MB
To display information
of all file system
usage in MB (Mega Byte)
use the option as ‘-m‘.
[root@tecmint ~]# df -m
Filesystem 1M-blocks
Used Available Use% Mounted on
/dev/cciss/c0d0p2 76525
22644 49931 32% /
/dev/cciss/c0d0p5 24217
21752 1215 95% /home
/dev/cciss/c0d0p3 29057
24907 2651 91% /data
/dev/cciss/c0d0p1 289
22 253 8% /boot
tmpfs 252
0 252 0% /dev/shm
SGN.
9. Display Information of
File System in GB
To display
information of all
file system statistics
in GB (Gigabyte) use
the option as ‘df -h‘.
[root@tecmint ~]# df -h
Filesystem Size Used
Avail Use% Mounted on
/dev/cciss/c0d0p2 75G 23G
49G 32% /
/dev/cciss/c0d0p5 24G 22G
1.2G 95% /home
/dev/cciss/c0d0p3 29G 25G
2.6G 91% /data
/dev/cciss/c0d0p1 289M 22M
253M 8% /boot
tmpfs 252M 0
252M 0% /dev/shm
SGN.
10. Display Information of df
Command.
Using ‘–help‘ switch will
display a list of
available option that
are used
with df command.
SGN.
11. [root@tecmint ~]# df --help
Usage: df [OPTION]... [FILE]...
Show information about the file system on which each FILE resides,
or all file systems by default.
Mandatory arguments to long options are mandatory for short options too.
-a, --all include dummy file systems
-B, --block-size=SIZE use SIZE-byte blocks
-h, --human-readable print sizes in human readable format (e.g., 1K 234M 2G)
-H, --si likewise, but use powers of 1000 not 1024
-i, --inodes list inode information instead of block usage
-k like --block-size=1K
-l, --local limit listing to local file systems
--no-sync do not invoke sync before getting usage info (default)
-P, --portability use the POSIX output format
--sync invoke sync before getting usage info
-t, --type=TYPE limit listing to file systems of type TYPE
-T, --print-type print file system type
-x, --exclude-type=TYPE limit listing to file systems not of type TYPE
-v (ignored)
--help display this help and exit
--version output version information and exit
SIZE may be (or may be an integer optionally followed by) one of following:
kB 1000, K 1024, MB 1000*1000, M 1024*1024, and so on for G, T, P, E, Z, Y.
Report bugs to <bug-coreutils@gnu.org>.
SGN.
12. b. du:- du command, short for disk usage, is used to estimate
file space usage.
The du command can be used to track the files and directories
which are consuming excessive amount of space on hard disk
drive.
SYNTAX:- du [OPTION]... [FILE]...
du [OPTION]... --files0-from=F
SGN.
14. OPTIONS:
-0, –null : end each output line with NULL
-a, –all : write count of all files, not just directories
–apparent-size : print apparent sizes, rather than disk usage.
-B, –block-size=SIZE : scale sizes to SIZE before printing on console
-c, –total : produce grand total
-d, –max-depth=N : print total for directory only if it is N or fewer levels
below command line argument
-h, –human-readable : print sizes in human readable format
-S, -separate-dirs : for directories, don’t include size of subdirectories
-s, –summarize : display only total for each directory
–time : show time of of last modification of any file or directory.
–exclude=PATTERN : exclude files that match PATTERN
SGN.
15. Command usage examples with options :
If we want to print sizes in human readable format(Kb, Mb, Gb), use -h
option:
du -h /home/sameer/test
Output:
44K /home/sameer/test/data
2.0M /home/sameer/test/system design
24K /home/sameer/test/table/sample_table/tree
28K /home/sameer/test/table/sample_table
32K /home/sameer/test/table
98M /home/sameer/test
SGN.
16. Use -a option for printing all files including
directories.
du -a -h /home/sameer/test
Output:
This is partial output of above command.
4.0K /home/sameer/test/blah1-new
4.0K /home/sameer/test/fbtest.py
8.0K /home/sameer/test/data/4.txt
4.0K /home/sameer/test/data/7.txt
4.0K /home/sameer/test/data/1.txt
4.0K /home/sameer/test/data/3.txt
4.0K /home/sameer/test/data/6.txt
4.0K /home/sameer/test/data/2.txt
4.0K /home/sameer/test/data/8.txt
8.0K /home/sameer/test/data/5.txt
44K /home/sameer/test/data
4.0K /home/sameer/test/notifier.py
SGN.
17. Use -c option to print total size
du -c -h /home/sameer/test
Output:
44K /home/sameer/test/data
2.0M /home/sameer/test/system design
24K/home/sameer/test/table/sample_table/tree
28K /home/sameer/test/table/sample_table
32K /home/sameer/test/table
98M /home/sameer/test
98M total
SGN.
18. To print sizes till particular level, use -d option with level no.
du -d 1 /home/sameer/test
Output:
44 /home/sameer/test/data
2012 /home/sameer/test/system design
32 /home/sameer/test/table
100104 /home/sameer/test
SGN.
19. Now try with level 2, you will get some extra directories
du -d 2 /home/sameer/test
Output:
44 /home/sameer/test/data
2012 /home/sameer/test/system design
28 /home/sameer/test/table/sample_table
32 /home/sameer/test/table
100104 /home/sameer/test
SGN.
20. Get summary of file system using -s option
du -s /home/sameer/test
Output :-
100104 /home/sameer/test
SGN.
21. Get the timestamp of last modified using
--time option
du --time -h /home/sameer/test
Output:-
44K 2018-01-14 22:22 /home/sameer/test/data
2.0M 2017-12-24 23:06 /home/sameer/test/system design
24K 2017-12-30 10:20 /home/sameer/test/table/sample_table/tree
28K 2017-12-30 10:20 /home/sameer/test/table/sample_table
32K 2017-12-30 10:20 /home/sameer/test/table
98M 2018-02-02 17:32 /home/sameer/test
SGN.
23. i. who
who command is used to find out the following
information :
1. Time of last system boot
2. Current run level of the system
3. List of logged in users and more
Description :
The who command is used to get information about
currently logged in user on to system.
Syntax : $who [options] [filename]
SGN.
24. Examples :
1. The who command displays the following
information for each user currently logged in to the
system if no option is provided :
1.Login name of the users
2.Terminal line numbers
3.Login time of the users in to system
4.Remote host name of the user
SGN.
25. Displays the username, line, and
time of all currently logged-in
sessions. For example:
SGN.
26. ii. who am i
whoami command is used both in UNIX
OPERATING SYSTEM and as well as in WINDOWS
OPERATING SYSTEM .
It is basically the concatenation of the
strings “who”,”am”,”i” as whoami.
It displays the username of the current user when this
command is invoked.
It is similar as running the id command with the
options -un.
SGN.
28. We've already discussed a command called who. It basically
provides information about all users who are currently
logged in. However, what if you are only interested in the
user who is currently logged in? Well, for this, you can use
the whoami command.
SGN.
29. iii. Finger
On the Linux operating system, you can simply check
the information of any user from remote or local command
line interface. That is ‘finger’ command.
This article will focus on usage of ‘finger’ command and its
options with demonstration command run on Ubuntu
Linux.
Syntax:
SGN.
30. iv. mesg
The mesg command allows you control write access to
your terminal by other users.
The write command allows other users to send a message to
your terminal session; the mesg command is used to toggle these
messages on or off.
Syntax :
mesg [n|y]
SGN.
31. -n
Prevents the display of terminal messages from other
users. This option is like using a "do not disturb" sign.
Syntax:
mesg n
-y
Allows messages to be displayed on your screen.
Syntax:
mesg y
If no option is given, mesg displays the current
access state of your terminal.
SGN.
32. mesg examples :
mesg y
Allow other users to send you messages.
mesg n
Disallow other users from being able to send
you messages.
mesg
Display the current write status of your terminal.
SGN.
33. v. Wall
Chat with other logged-in users.
Description:
Talk is a visual communication program which copies lines
from your terminal to that of another user, much like an instant
messenger service. When first called, talk contacts
the talk daemon on the other user's machine, which sends
the message below.
SGN.
34. wall -- send a message to everybody’s terminal.
Syntax:
wall [-n] [ message ]
Wall sends a message to everybody logged in with their mesg(1)
permission set to yes. The message can be given as an argument
to wall, or it can be sent to wall’s standard input. When using the
standard input from a terminal, the message should be terminated
with the EOF key (usually Control-D).The length of the message is
limited to 22 lines. For every invocation of wall a notification will be
written to syslog, with facility LOG_USER and level LOG_INFO.
SGN.
35. wall –n
Suppresses the normal banner printed by wall, changing it to
"Remote broadcast message". This option is only available for
root if wall is installed set-group-id, and is used by rpc.walld(8).
SGN.
36. vi. Talk :
Chat with other logged-in users
Description
Talk is a visual communication program which copies lines
from your terminal to that of another user, much like an instant
messenger service. When first called, talk contacts
the talk daemon on the other user’s machine, which sends the
message below.
Syntax
talk person [ttyname]
SGN.
37. Message from TalkDaemon@his_machine...
talk: connection requested by
your_name@your_machine.
talk: respond with: talk your_name@your_machine
to that user. At this point, he then replies by
typing
talk your_name@your_machine
SGN.
38. It doesn't matter from which machine the recipient replies,
as long as his login name is the same. Once communication is
established, the two parties may type simultaneously; their
output will appear in separate windows. Typing control-L (^L)
will cause the screen to be reprinted. The erase, kill line,
and word erase characters (normally ^H, ^U, and ^W,
respectively) will behave normally. To exit, just type the
interrupt character (normally ^C); talk then moves the
cursor to the bottom of the screen and restores
the terminal to its previous state
SGN.
39. talk supports scrollback; use esc-p and esc-n to scroll your
window, and ctrl-p and ctrl-n to scroll the other window.
If you do not want to receive talk requests, you may block
using the mesgcommand. By default, talk requests are normally not
blocked. Certain commands, in particular nroff, pine, and pr,
block messages temporarily to preserve their own output.
SGN.
40. person
If you want to talk to someone on your machine,
then person is just the person's login name. If you
want to talk to a user on another host,
then person is of the form 'user@host'.
ttyname
If you want to talk to a user who is logged in more
than once, the ttyname argument may be used to
indicate the appropriate terminal name, where
ttyname is of the form 'ttyXX' or 'pts/X'.
SGN.