Creating Files
Creating Files and Directories
Let's learn to create files and directories from the command line. The main commands are
touch (create empty files), mkdir (create directories), and echo (write text to files).touch — Create Empty Files
bash
# Create a single file
touch myfile.txt
# Create multiple files at once
touch file1.txt file2.txt file3.txt
# Verify they were created
lsmkdir — Make Directories
bash
# Create a directory
mkdir projects
# Create nested directories with -p
mkdir -p projects/web/src
# Verify
ls projectsecho — Write Text
bash
# Print text to terminal
echo "Hello, Linux!"
# Write text to a file (creates or overwrites)
echo "Hello" > greeting.txt
# Append text to a file
echo "World" >> greeting.txt
# View the file
cat greeting.txtTip:Use > to write (overwrites existing content) and >> to append (adds to the end). Be careful with > — it will erase the file's contents!
Terminalbash
Welcome to the Linux Terminal Simulator!
Type commands below. Use 'help' to see available commands.
Try: