Ubuntu create empty file from command line
Linux command touch
can be used to change file timestamps. If that FILE argument doesn’t exist ,then touch will create a empty file for you.
Create an empty file using command touch
touch filename
For example:
j@ubuntu2004:~/tmp$ touch file01
j@ubuntu2004:~/tmp$ cat file01
j@ubuntu2004:~/tmp$ ls -l file01
-rw-rw-r-- 1 j j 0 Aug 2 09:13 file01
j@ubuntu2004:~/tmp$
You can see above command create an empty fie file01
.
Ubuntu create empty file with specified size using truncate
Linux command truncate
can shrink or extend the size of a file to the specified size. Similar to command touch
, a FILE argument that does not exist is created. Thus we can use it to create an empty file with specified size.
truncate -s size filename
For example ,below create a 100M empty file with filename 100mfile
j@ubuntu2004:~/tmp$ truncate -s 100M 100mfile
j@ubuntu2004:~/tmp$ ls -lh 100mfile
-rw-rw-r-- 1 j j 100M Aug 2 09:42 100mfile
j@ubuntu2004:~/tmp$
-s
: set or adjust the file size by SIZE bytes, supports K,M,G,T,P,E
Create empty file with specified size using command dd
Alternatively you also can use linux command dd
to create empty file with specified size.
j@ubuntu2004:~/tmp$ dd if=/dev/zero of=10mfile bs=1M seek=10 count=0
0+0 records in
0+0 records out
0 bytes copied, 0.000347216 s, 0.0 kB/s
j@ubuntu2004:~/tmp$ ls -lh 10mfile
-rw-rw-r-- 1 j j 10M Aug 2 09:44 10mfile
j@ubuntu2004:~/tmp$