Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why would one create an empty file?

I saw the command: touch while watching a video about the Terminal

It was something like:

user$ touch testfile
user$ ls
Documents Photos Music testfile

So I couldn't answer to myself:

Why one would want to create an empty file?

If you can, please make a short list of a few applicabilities of it!

like image 230
dot.Py Avatar asked May 09 '26 09:05

dot.Py


2 Answers

I'll give a practical example of when I just used empty files in Ubuntu a few days ago. I was creating a program in C that could symlink files, directories, and entire directories of files. After I finished all my coding, I made a simple shell .sh script that created a "mock" directory structure. Including empty files and directories so I could test my program symlinking these "fake" files.

This makes it easy to:

  1. Start the test over easily if something isn't working.
  2. Play around with files of no importance (don't want to risk losing actual data).
like image 147
amza Avatar answered May 11 '26 04:05

amza


  • To represent a collection of information with no instances.
  • When the mere presence or absence of the file is all that matters
like image 26
Scott Hunter Avatar answered May 11 '26 03:05

Scott Hunter