Welcome, command-line adventurer! Whether you’re new to Linux or brushing up on your sysadmin skills, mastering file and directory management is one of the most essential and empowering things you can do. In this guide, we’ll show you how to create, read, and delete files and directories — and you’ll be doing it like a pro in no time.
Grab your terminal and let’s dive in!
📂 Creating Directories
Directories (aka folders) are where your system organizes its files. Creating them is super simple — and actually kind of fun.
Create a Single Directory
Just need one? Easy:
Create Sequentially Named Directories
Want directories named project1, project2, project3? No problem:
Create Nested Directories
Need a folder inside a folder inside a folder? Use the -p option to create an entire path at once:
📄 Creating Files
Files are where the real work happens. Luckily, creating them is just as straightforward.
Create an Single File
The classic:
touch /Luna.py
Create Multiple Files
Why stop at one?
touch /Luna1.py /Luna2.py /Luna3.py
Create a Bunch of Files in Sequence
Brace yourself (pun intended):
touch /Luna{4..8}.py
📝 Reading and Writing with cat
The cat command is one of the handiest tools in your Linux arsenal for quickly viewing or writing file contents.
Create and Write to a New File
Start typing — it’s as simple as this:
cat > /HelloWorld.txt
Type your content, then hit Ctrl + D D when you’re finished.
Append Content to an Existing File
Adding more notes? Use this:
cat >> /HelloWorld.txt
Again, finish with Ctrl + D D.
View File Contents
Want to peek inside a file? Use:
cat /HelloWord.txt or cat > /HelloWorld.txt
🗑️ Deleting Files and Directories
Not everything deserves to live forever in your file system. Here’s how to tidy up.
Delete a Single File
Gone in a flash:
rm -rvf /Luna1.py
Delete Multiple Files
Clear out a bunch at once:
rm -rvf /Luna2.py /Luna3.py /Luna4.py
Delete Files in a Sequence
Again with the curly braces:
rm -rvf /Luna{5..8}.py
💡 Real-World Example
Imagine you’re setting up a new web app. You need a clean folder structure and some starter files. Do it all in one shot:
mkdir -p /var/www/myapp/{public,logs,config}
touch /var/www/myapp/{public/index.html,logs/app.log,config/settings.conf}
Boom — organized and ready for action.
🎉 Final Thoughts
Mastering these basic file and directory commands will make you feel at home in any Linux terminal, whether you’re spinning up cloud servers, building apps, or just exploring. Practice them often, and soon you’ll be navigating your system with the confidence of a seasoned sysadmin.
Stay curious, keep learning — and happy terminal-ing!