Create the directory in advance, before moving files, so they have somewhere to land.
mkdir creates a directory. Its parent must already exist: mkdir reports/2026 fails if there is no reports. With -p the command creates the whole chain and quietly skips directories that already exist. You can give several names: each directory appears.
touch creates an empty file when no file has that name. When the file exists, touch only sets its modification time to now. A file with text in it comes from the > redirection of the paths lesson.
notes.txt holds three lines of notes. You run touch notes.txt and then cat notes.txt. What do you see?
-
For an existing file,
touchchanges only the modification time. Comparels -l notes.txtbefore and after: the size is the same. -
A directory cannot hold two files with the same name:
ls -lshows one notes.txt. -
An existing file is the ordinary case for
touch: it silently updates the time. Runtouch notes.txttwice in a row — there is no message.
touch leaves an existing file's contents alone and only sets its modification time to now. Check ls -l notes.txt before and after: the time changes, the size does not.
Key points
-
mkdir -pcreates the missing directories of a chain and does not complain about existing ones. -
touchcreates an empty file, and for an existing file changes only the modification time.