touch: Making Files
Empty files and timestamps.
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.

- 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.
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.
| key | value |
|---|---|
| File exists | update its date |
| File is missing | create it, empty |
| Contents | never changed |
| Most common use | make 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.
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