How to fill complete hard disk in Linux or echo a statement endlessly ?
Today we will look at a new command called “yes” on Unix or Linux system.
This command echos the mentioned statement in the file endlessly until it is killed/interrupted using Ctrl+C.
In case no statement is mentioned then it echos “y” to the file.
1. How to use yes command ?
### Echo y endlessly to a file. [root@nglinux ~]# yes > testfile.txt1 ^C ### See the contents of the file. [root@nglinux ~]# tail testfile.txt1 y y y
2. Echo some statement to a file endlessly.
[root@nglinux ~]# yes "this is endless statement" > newfile2 ^C [root@nglinux ~]# tail newfile2 this is endless statement this is endless statement this is endless statement
3. Fill up your hard disk with yes command.
This command run endlessly till your hard disk gets filled and eats up your complete space.
Lets see an example:-
### Check current disk usage. [root@nglinux ~]# df -h . Filesystem Size Used Avail Use% Mounted on /dev/sda1 20G 9.5G 9.2G 51% / ### run yes command endlessly [root@nglinux ~]# yes > bigfile.txt & ### Check the disk space, its completely filled. [root@nglinux ~]# df -h . Filesystem Size Used Avail Use% Mounted on /dev/sda1 20G 20G 0 100% /
4. Clean the file and make some space quickly.
### Check file size. [root@nglinux ~]# du -sh bigfile.txt 11G bigfile.txt [root@nglinux ~]# ### Empty the file quickly by echoing some arbitrary text to file. [root@nglinux ~]# echo "0" > bigfile.txt ### Now check the usage, its reduced. [root@nglinux ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/sda1 20G 9.5G 9.2G 51% /
Seems interesting command “YES”. Now you can use this and make fun with your friends.