← Linux and the Command Line
Lesson 6 of 51 · 10 XP
touch and mkdir — creating files and folders
Theory and problem statement
Machine translation, not yet reviewed by a native speaker.
touch file.txt # create an empty file (or update the modification date of an existing one)
touch a.txt b.txt c.txt # several at once
mkdir docs # create a folder
mkdir -p src/utils/net # -p: create all the intermediate folders, no error if they already exist
mkdir -v logs # -v: report what was created
Curly braces are a powerful shell trick: the shell expands them into a list by itself.
mkdir -p project/{src,docs,tests} # three folders with one command
touch report_{1,2,3}.txt # report_1.txt report_2.txt report_3.txt
The braces are expanded by the shell itself, before the command runs. This works in bash, zsh and the BusyBox sh, but not in every sh: for example, dash, the system shell of Debian, doesn't have them. In portable scripts, write the names out explicitly.
To see the whole tree — find . | sort or tree.
Task. Create a project structure: the folders game/src and game/assets, and in them the files game/src/main.c and game/assets/logo.png. The check line at the end (don't change it) prints the tree.
Sign up for free to solve this task right in your browser: code editor, running, test checks and hints.