Thursday, September 22, 2016

du command examples in linux ?

du (Disk Usage) Commands to Find Disk Usage of Files and Directories

The Linux “du” (Disk Usage) is a standard Unix/Linux command, used to check the information of disk usage of files and directories on a machine. The du command has many parameter options that can be used to get the results in many formats. The du command also displays the files and directory sizes in a recursively manner.

1. To find out the disk usage summary of a /home/minazul directory tree and each of its sub directories. Enter the command as:
[root@linuxforfreshers.com]# du  /home/minazul
40      /home/minazul/downloads
4       /home/minazul/.mozilla/plugins
4       /home/minazul/.mozilla/extensions
12      /home/minazul/.mozilla
12      /home/minazul/.ssh
689112  /home/minazul/Ubuntu-12.10
689360  /home/minazul

The output of the above command displays the number of disk blocks in the /home/minazul directory along with its sub-directories.


2. Using “-h” option with “du” command provides results in “Human Readable Format“. Means you can see sizes in Bytes, Kilobytes, Megabytes, Gigabytes etc.
[root@linuxforfreshers.com]# du -h /home/minazul
40K     /home/minazul/downloads
4.0K    /home/minazul/.mozilla/plugins
4.0K    /home/minazul/.mozilla/extensions
12K     /home/minazul/.mozilla
12K     /home/minazul/.ssh
673M    /home/minazul/Ubuntu-12.10
674M    /home/minazul


3. To get the summary of a grand total disk usage size of an directory use the option “-s” as follows.
[root@linuxforfreshers.com]# du -sh /home/minazul
674M    /home/minazul


4. Using “-a” flag with “du” command displays the disk usage of all the files and directories.
[root@linuxforfreshers.com]# du -a /home/minazul
4       /home/minazul/.bash_logout
12      /home/minazul/downloads/uploadprogress-1.0.3.1.tgz
24      /home/minazul/downloads/Phpfiles-org.tar.bz2
40      /home/minazul/downloads
12      /home/minazul/uploadprogress-1.0.3.1.tgz
4       /home/minazul/.mozilla/plugins
4       /home/minazul/.mozilla/extensions
12      /home/minazul/.mozilla
4       /home/minazul/.bashrc
689108  /home/minazul/Ubuntu-12.10/ubuntu-12.10-server-i386.iso
689112  /home/minazul/Ubuntu-12.10
689360  /home/minazul


5. Using “-a” flag along with “-h” displays disk usage of all files and folders in human readeable format. The below output is more easy to understand as it shows the files in Kilobytes, Megabytes etc.
[root@linuxforfreshers.com]# du -ah /home/minazul
4.0K    /home/minazul/.bash_logout
12K     /home/minazul/downloads/uploadprogress-1.0.3.1.tgz
24K     /home/minazul/downloads/Phpfiles-org.tar.bz2
40K     /home/minazul/downloads
12K     /home/minazul/uploadprogress-1.0.3.1.tgz
4.0K    /home/minazul/.mozilla/plugins
4.0K    /home/minazul/.mozilla/extensions
12K     /home/minazul/.mozilla
4.0K    /home/minazul/.bashrc
673M    /home/minazul/Ubuntu-12.10/ubuntu-12.10-server-i386.iso
673M    /home/minazul/Ubuntu-12.10
674M    /home/minazul


6. Find out the disk usage of a directory tree with its subtress in Kilobyte blcoks. Use the “-k” (displays size in 1024 bytes units).
[root@linuxforfreshers.com]# du -k /home/minazul
40      /home/minazul/downloads
4       /home/minazul/.mozilla/plugins
4       /home/minazul/.mozilla/extensions
12      /home/minazul/.mozilla
12      /home/minazul/.ssh
689112  /home/minazul/Ubuntu-12.10
689360  /home/minazul


7. To get the summary of disk usage of directory tree along with its subtrees in Megabytes (MB) only. Use the option “-mh” as follows. The “-m” flag counts the blocks in MB units and “-h” stands for human readable format.
[root@linuxforfreshers.com]# du -mh /home/minazul
40K     /home/minazul/downloads
4.0K    /home/minazul/.mozilla/plugins
4.0K    /home/minazul/.mozilla/extensions
12K     /home/minazul/.mozilla
12K     /home/minazul/.ssh
673M    /home/minazul/Ubuntu-12.10
674M    /home/minazul


8. The “-c” flag provides a grand total usage disk space at the last line. If your directory taken 674MB space, then the last last two line of the output would be.
[root@linuxforfreshers.com]# du -ch /home/minazul
40K     /home/minazul/downloads
4.0K    /home/minazul/.mozilla/plugins
4.0K    /home/minazul/.mozilla/extensions
12K     /home/minazul/.mozilla
12K     /home/minazul/.ssh
673M    /home/minazul/Ubuntu-12.10
674M    /home/minazul
674M    total


9. The below command calculates and displays the disk usage of all files and directories, but excludes the files that matches given pattern. The below command excludes the “.txt” files while calculating the total size of diretory. So, this way you can exclude any file formats by using flag “-–exclude“. See the output there is no txt files entry.
[root@linuxforfreshers.com]# du -ah --exclude="*.txt" /home/minazul
4.0K    /home/minazul/.bash_logout
12K     /home/minazul/downloads/uploadprogress-1.0.3.1.tgz
24K     /home/minazul/downloads/Phpfiles-org.tar.bz2
40K     /home/minazul/downloads
12K     /home/minazul/uploadprogress-1.0.3.1.tgz
4.0K    /home/minazul/.bash_history
4.0K    /home/minazul/.bash_profile
4.0K    /home/minazul/.mozilla/plugins
4.0K    /home/minazul/.mozilla/extensions
12K     /home/minazul/.mozilla
4.0K    /home/minazul/.bashrc
24K     /home/minazul/Phpfiles-org.tar.bz2
4.0K    /home/minazul/geoipupdate.sh
4.0K    /home/minazul/.zshrc
120K    /home/minazul/goaccess-0.4.2.tar.gz.1
673M    /home/minazul/Ubuntu-12.10/ubuntu-12.10-server-i386.iso
673M    /home/minazul/Ubuntu-12.10
674M    /home/minazul


10. Display the disk usage based on modification of time, use the flag “–time” as shown below.
[root@linuxforfreshers.com]# du -ha --time /home/minazul
4.0K    2015-10-12 22:32        /home/minazul/.bash_logout
12K     2015-01-19 18:48        /home/minazul/downloads/uploadprogress-1.0.3.1.tgz
24K     2015-01-19 18:48        /home/minazul/downloads/Phpfiles-org.tar.bz2
40K     2015-01-19 18:48        /home/minazul/downloads
12K     2015-01-19 18:32        /home/minazul/uploadprogress-1.0.3.1.tgz
4.0K    2012-10-13 00:11        /home/minazul/.bash_history
4.0K    2012-10-12 22:32        /home/minazul/.bash_profile
0       2013-01-19 18:32        /home/minazul/xyz.txt
0       2013-01-19 18:32        /home/minazul/abc.txt
4.0K    2012-10-12 22:32        /home/minazul/.mozilla/plugins
4.0K    2012-10-12 22:32        /home/minazul/.mozilla/extensions
12K     2012-10-12 22:32        /home/minazul/.mozilla
4.0K    2012-10-12 22:32        /home/minazul/.bashrc
24K     2013-01-19 18:32        /home/minazul/Phpfiles-org.tar.bz2
4.0K    2013-01-19 18:32        /home/minazul/geoipupdate.sh
4.0K    2012-10-12 22:32        /home/minazul/.zshrc
120K    2013-01-19 18:32        /home/minazul/goaccess-0.4.2.tar.gz.1
673M    2013-01-19 18:51        /home/minazul/Ubuntu-12.10/ubuntu-12.10-server-i386.iso
673M    2013-01-19 18:51        /home/minazul/Ubuntu-12.10

674M    2013-01-19 18:52        /home/minazul

Thursday, September 15, 2016

how to make bootable pen drive using dd command in linux?

Making bootable ISO for all OS using dd command

Usually, We create bootable USB drives and install Linux and other operating systems. Of course there are many GUI applications to make bootable ISO are available for both Linux and Windows platforms such as,

Unetbootin ;
Win32diskimager ;
Linux live usb ;
USB image writer ;
WinUSB ;
USB startup creator ;
And many.
But there is an easy command line way too. There is no need for above applications. We can make bootable ISO, for any operating system, by using dd tool in Linux. Most Linux distributions has preinstalled dd tool. We can also use dd in Windows but need to download and install it from internet.
dd is very powerful tool. dd stands for Data Duplicator which is make copy using block by block from one device into another device. So we can also use dd tool for data backup and restore from one device into another device.

Steps to make a bootable USB

First format your pen drive. In order to format our pen drive we need to unmount the device from the operating system. Unmount is nothing but an removing device from directory tree. Which prevents device from data loss.

umount /dev/sdb*
Note: sdb is my pen drive. That is assigned by Linux operating system automatically while inserting pen drive into our system. You can identify it by typing following command.
After unmounting, we need to format our pen drive

mkfs.vfat /dev/sdb –I
The above command will format the pen drive and make it as  FAT filesystem.

After that use dd command:

dd if=~/home/srini/iso/kali.iso of=/dev/sdb bs=1M
Here,

if stands for input file. It is used to specify the location of the ISO file.
Of stands for output file. It specifies where to write the ISO file. In our case, it’s /dev/sdb

where bs is block size the optimum block size is hardware dependent the perfect size will depend on your system bus, hard drive controller, the particular drive itself.


It takes some time to copy one disk to another disk. Usually dd tool does not show progressing status. But we can use a simple trick to monitor it.

To monitor dd progress, run:

pgrep –l ‘^dd$’