Linux File and Directory Management Commands¶
This section covers file and directory management commands that DevOps engineers use daily while working with application code, logs, configuration files, and automation scripts.
mkdir – Create Directory¶
Used to create a new directory.
mkdir logs
mkdir -p – Create Parent Directories¶
Creates parent directories automatically if they do not exist.
mkdir -p app/config/nginx
📌 DevOps Use Case: Creating nested directory structures in one command.
rmdir – Remove Empty Directory¶
Used to delete an empty directory.
rmdir old_logs
⚠️ If the directory is not empty, this command will fail.
rm -rf – Remove Files and Directories Forcefully¶
Deletes files or directories recursively and forcefully.
rm -rf temp/
⚠️ Warning: This command permanently deletes data. Use with extreme caution in production.
touch – Create Empty File¶
Used to create an empty file or update file timestamp.
touch app.log
vi – Edit Files¶
Used to create or edit files using the vi editor.
vi config.yaml
📌 Common vi modes:
- Insert mode (i)
- Save and exit (:wq)
- Exit without saving (:q!)
cat – View File Content¶
Used to print or read the content of a file.
cat file_name
tree – Display Directory Structure¶
Displays directory structure in a tree format.
tree
📌 DevOps Tip: Useful for understanding project folder layout.
cp – Copy Files or Directories¶
Used to copy files or directories.
cp source.txt destination.txt
Copy directories recursively:
cp -r app/ backup_app/
mv – Move or Rename Files¶
Used to move or rename files and directories.
mv old.txt new.txt
Practice Tasks¶
- Create a directory named
project - Inside it, create
logs/app - Create a file named
app.log - Copy
app.logtobackup.log - Rename
backup.logtoapp_backup.log - Delete the
logsdirectory
🧠 Quick Quiz – File Management¶
Which command creates parent directories automatically if they do not exist?
📝 Want More Practice?¶
To strengthen your understanding and prepare for interviews, try the full 20-question practice quiz based on this chapter:
👉 Start File & Directory Management Quiz (20 Questions)
📬 DevopsPilot Weekly — Learn DevOps, Cloud & Gen AI the simple way.
👉 Subscribe here