touch: Create Files
Folders need files inside them. The quickest way to create a new, empty file is the touch command.
touch notes.txt
Again, success is silent. Confirm with ls:
ls
notes.txt
The file exists but is completely empty (0 bytes) until you put something in it.
Several files at once
Like mkdir, touch accepts multiple names:
touch log1.txt log2.txt log3.txt
Creating a file inside a folder
If the folder already exists, you can touch a file straight into it:
touch reports/summary.txt
(The folder must exist first: touch does not create folders.)
Why is it called "touch"?
If the file already exists, touch does not erase it. It just updates the file's
"last modified" time. That is its original purpose. For a beginner, think of it
simply as "create an empty file".
Mission: Prepare Mission Files
The station commander needs new files for today's briefing, plus a fresh place to keep the daily logs. Your home directory already has a reports folder ready.
- Create two empty files
mission.txtandcrew.txtin your home directory with a single command. - Make a new folder
logsinsidereports. - Create two empty log files inside it:
reports/logs/day1.logandreports/logs/day2.log. - Verify the log folder as a tree.
Expected result
The listing shows mission.txt and crew.txt, and the tree of reports shows day1.log and day2.log inside reports/logs.