AI Hints
Home›Linux Tutorial›Making Folders and Files
Linux · Lesson 23 of 120

touch: Making Files

Empty files and timestamps.

⏱ 2 min read▶ Video at 27:33🎓 Free
Watch this lesson in the Linux courseWatch on YouTube ↗Full Linux course

Now for files. The quickest way to create an empty file is the touch command. The name sounds odd, but it makes sense, once you see what it really does.

touch: Making Files
From the video: touch: Making Files
  • Now for files
  • touch makes empty files
  • The name makes sense later

Creating empty files

Touch, followed by a name, creates an empty file. Here we go into projects, and touch two files, an index page, and a style file. LS dash L shows them, each zero bytes in size. They're empty, but they exist.

Terminal
cd projects
touch index.html style.css
ls -l
total 0
-rw-r--r-- 1 sam sam 0 Jan  5 09:00 index.html
-rw-r--r-- 1 sam sam 0 Jan  5 09:00 style.css

Why it is called touch

Touch was really made to update a file's time stamp, as if you'd just touched it. If the file already exists, touch changes its date to now, and leaves the contents alone. If it doesn't exist, touch creates it empty. That second use turned out to be the popular one.

keyvalue
File existsupdate its date
File is missingcreate it, empty
Contentsnever changed
Most common usemake an empty file

Files with spaces

One warning about names. Spaces in a file name cause trouble, because the shell uses spaces to separate arguments. Touch my notes creates two files, my, and notes. Quotes keep the name together. That's why most Linux users avoid spaces, and use dashes or underscores instead.

Terminal
touch my notes
touch "my notes.txt"
ls
 my  'my notes.txt'   notes

Summary

Touch creates empty files, or updates their date. And spaces in names need quotes, so it's easier to avoid them. Next, let's practise building a folder structure.

Key takeaways
  • touch <file>
  • Updates the date too
  • Avoid spaces in names
Next up: Practice: A Project Folder — mkdir and touch together