Requirement :Create dummy/fake file of desired size using Linux terminal
There might be some test requirement to mimic the prod setup, in my case I have to write a script to validate files before downloading, instead of making request to prod site I just created a local setup and placed similar dummy files to replicate the prod environment.Let's know the one linux one liner using tool fallocate to create dummy file of desired size.
- Fallocate is the Linux terminal utility.
There might be some test requirement to mimic the prod setup, in my case I have to write a script to validate files before downloading, instead of making request to prod site I just created a local setup and placed similar dummy files to replicate the prod environment.
Let's know the one linux one liner using tool fallocate to create dummy file of desired size.
- Fallocate is the Linux terminal utility.
One Liner # fallocate -l <size_of_file> <desired_name_of_file>
# fallocate -l <size_of_file> <desired_name_of_file>
- Fallocate is the Linux terminal utility.
- Fallocate is the Linux terminal utility.
Syntax Template
# fallocate -l 15M myfile.img
# fallocate -l 15M myfile.img
- <size_of_file >
- in GB and MB : M for MB and G for GB
- example : 15M for 15 MB and 5G for 5GB
- <desired_name_of_file>
- It can be anything with our without extension : myfile.tar or myfile.img or myfile or anything
- <size_of_file >
- in GB and MB : M for MB and G for GB
- example : 15M for 15 MB and 5G for 5GB
- <desired_name_of_file>
- It can be anything with our without extension : myfile.tar or myfile.img or myfile or anything
Using Linux for loop and Seq to generate a series of file.Example : - Below one liner can be used to generate 100 files of 15mb each with suffix changes as file count number.
- Below one liner can be used to generate 100 files of 15mb each with suffix changes as file count number.
Syntax Template
# for val in `seq 100`; do fallocate -l 15M demo060621000$val.tar; done;
# for val in `seq 100`; do fallocate -l 15M demo060621000$val.tar; done;
Output : File starts with name demo0606210001.tar and ends with demo0606210099.tar
Syntax Output
# ls -ltr
-rw-r--r-- 1 root root 15728640 Jun 6 23:25 demo0606210001.tar
-rw-r--r-- 1 root root 15728640 Jun 6 23:25 demo0606210002.tar
-rw-r--r-- 1 root root 15728640 Jun 6 23:25 demo0606210003.tar
-rw-r--r-- 1 root root 15728640 Jun 6 23:25 demo0606210004.tar
-rw-r--r-- 1 root root 15728640 Jun 6 23:25 demo0606210005.tar
-rw-r--r-- 1 root root 15728640 Jun 6 23:25 demo0606210006.tar
-rw-r--r-- 1 root root 15728640 Jun 6 23:25 demo0606210007.tar
-rw-r--r-- 1 root root 15728640 Jun 6 23:25 demo0606210008.tar
-rw-r--r-- 1 root root 15728640 Jun 6 23:25 demo0606210009.tar
-rw-r--r-- 1 root root 15728640 Jun 6 23:25 demo06062100010.tar
-rw-r--r-- 1 root root 15728640 Jun 6 23:25 demo06062100011.tar
-rw-r--r-- 1 root root 15728640 Jun 6 23:25 demo06062100012.tar
-rw-r--r-- 1 root root 15728640 Jun 6 23:25 demo06062100013.tar
-rw-r--r-- 1 root root 15728640 Jun 6 23:25 demo06062100014.tar
-rw-r--r-- 1 root root 15728640 Jun 6 23:25 demo06062100015.tar
-rw-r--r-- 1 root root 15728640 Jun 6 23:25 demo06062100016.tar
-rw-r--r-- 1 root root 15728640 Jun 6 23:25 demo06062100017.tar
-rw-r--r-- 1 root root 15728640 Jun 6 23:25 demo06062100018.tar
-rw-r--r-- 1 root root 15728640 Jun 6 23:25 demo06062100019.tar
-rw-r--r-- 1 root root 15728640 Jun 6 23:25 demo06062100020.tar
-rw-r--r-- 1 root root 15728640 Jun 6 23:25 demo06062100021.tar
-rw-r--r-- 1 root root 15728640 Jun 6 23:25 demo06062100022.tar
-rw-r--r-- 1 root root 15728640 Jun 6 23:25 demo06062100023.tar
# ls -ltr
-rw-r--r-- 1 root root 15728640 Jun 6 23:25 demo0606210001.tar
-rw-r--r-- 1 root root 15728640 Jun 6 23:25 demo0606210002.tar
-rw-r--r-- 1 root root 15728640 Jun 6 23:25 demo0606210003.tar
-rw-r--r-- 1 root root 15728640 Jun 6 23:25 demo0606210004.tar
-rw-r--r-- 1 root root 15728640 Jun 6 23:25 demo0606210005.tar
-rw-r--r-- 1 root root 15728640 Jun 6 23:25 demo0606210006.tar
-rw-r--r-- 1 root root 15728640 Jun 6 23:25 demo0606210007.tar
-rw-r--r-- 1 root root 15728640 Jun 6 23:25 demo0606210008.tar
-rw-r--r-- 1 root root 15728640 Jun 6 23:25 demo0606210009.tar
-rw-r--r-- 1 root root 15728640 Jun 6 23:25 demo06062100010.tar
-rw-r--r-- 1 root root 15728640 Jun 6 23:25 demo06062100011.tar
-rw-r--r-- 1 root root 15728640 Jun 6 23:25 demo06062100012.tar
-rw-r--r-- 1 root root 15728640 Jun 6 23:25 demo06062100013.tar
-rw-r--r-- 1 root root 15728640 Jun 6 23:25 demo06062100014.tar
-rw-r--r-- 1 root root 15728640 Jun 6 23:25 demo06062100015.tar
-rw-r--r-- 1 root root 15728640 Jun 6 23:25 demo06062100016.tar
-rw-r--r-- 1 root root 15728640 Jun 6 23:25 demo06062100017.tar
-rw-r--r-- 1 root root 15728640 Jun 6 23:25 demo06062100018.tar
-rw-r--r-- 1 root root 15728640 Jun 6 23:25 demo06062100019.tar
-rw-r--r-- 1 root root 15728640 Jun 6 23:25 demo06062100020.tar
-rw-r--r-- 1 root root 15728640 Jun 6 23:25 demo06062100021.tar
-rw-r--r-- 1 root root 15728640 Jun 6 23:25 demo06062100022.tar
-rw-r--r-- 1 root root 15728640 Jun 6 23:25 demo06062100023.tar