Chapter 3: File and Directory Management in WSL Ubuntu
In the previous chapter, you learned how to navigate through the Linux file system using WSL Ubuntu. Now it’s time to manage what’s inside those directories — files and folders.
This chapter covers how to create, rename, move, copy, and delete files and directories using the command line. These are everyday tasks that every Linux user must master.
📁 Files and Directories in Linux
Everything in Linux is treated as a file — whether it’s a text file, folder, device, or even a process. Here’s what you need to know:
- Files hold data, scripts, configs, etc.
- Directories (folders) hold other files or directories.
🛠️ Creating Files and Directories
📌 touch – Create a File
Creates an empty file or updates the timestamp of an existing one.
touch myfile.txt
📌 mkdir – Create a Directory
Creates a new folder.
mkdir myfolder
To create nested directories:
mkdir -p projects/html/css
✏️ Renaming and Moving
📌 mv – Move or Rename
To rename a file:
mv oldname.txt newname.txt
To move a file to another directory:
mv myfile.txt /home/username/Documents
You can also move and rename at the same time:
mv myfile.txt /home/username/Docs/renamed.txt
📄 Copying Files and Directories
📌 cp – Copy Files
cp file1.txt copy_of_file1.txt
Copy to another folder:
cp file1.txt /home/username/Desktop/
📌 cp -r – Copy Directories
The -r option means “recursive” — required when copying folders.
cp -r myfolder/ backup_myfolder/
🗑️ Deleting Files and Folders
📌 rm – Remove Files
rm unwanted.txt
📌 rm -r – Remove Directories
Use recursive deletion for folders and their contents:
rm -r old_folder
⚠️ Caution!
Be very careful with rm -r. There is no recycle bin in Linux. Once deleted, it’s gone.
📋 Listing Files
We covered this in Chapter 2, but here’s a recap with more options:
ls -l # Long listing
ls -a # Show hidden files
ls -lh # Human-readable sizes
ls -R # List contents of directories recursively
🧪 Practical Exercises
Open your Ubuntu terminal and try the following:
# Step 1: Create a folder and files
mkdir tutorials
cd tutorials
touch file1.txt file2.txt
# Step 2: Create subfolders
mkdir -p html/css/js
# Step 3: Copy and rename
cp file1.txt html/
mv file2.txt renamed.txt
# Step 4: Delete a file and folder
rm renamed.txt
rm -r js
🔎 Bonus Tips
- Use
tabto autocomplete file and folder names - Use
rm -ito ask for confirmation before deleting - To view file content:
cat filename.txt
✅ Summary
touch,mkdir– Create files and foldersmv– Move or renamecp– Copy files and foldersrm– Remove with caution- Practice in your terminal to reinforce learning
▶️ Coming Up Next
Chapter 4 – File Viewing & Text Editors in Linux
You’ll learn how to view, search, and edit files with tools like cat, less, nano, and vim.
