So far, we’ve learned how to create and edit files. Now it’s time to get hands-on with managing them.
In Linux, everything is a file—even directories. This post covers essential file-related commands that help you understand, navigate, and manage your files like a pro.
whatis
: Your Built-In Cheat Sheet
Want a quick description of a command? Use:
whatis ls
whatis cp
whatis mkdir
Simple and straight to the point.
tree
: Visualize Your File Structure
The tree
command shows your directory structure in a clean, readable format:
tree # Shows everything
tree -L 2 # Limits depth to 2 levels
tree -a # Includes hidden files
tree -d # Only directories
Perfect for getting a quick overview.
mkdir
: Make New Folders
Create directories with ease:
mkdir photos # Basic folder
mkdir -p photos/2023/vacation # Makes all parent folders
mkdir photos videos music # Create multiple folders at once
touch
: Create or Modify Files
The touch
command is more powerful than it seems. You can use it to:
touch newfile.txt # Create a new file
touch -a file.txt # Update access time
touch -m file.txt # Update modification time
touch -t 202312251200 file.txt # Set a specific timestamp (YYYYMMDDHHMM)
touch -r ref.txt target.txt # Copy timestamp from another file
It’s especially useful in scripting and cybersecurity.
cp
: Copy Files and Folders
Copying in Linux is flexible and simple:
cp file1.txt file2.txt # Copy a file
cp -r folder1 folder2 # Copy a directory
cp -i *.txt backup/ # Prompt before overwrite
cp -p source.txt dest.txt # Preserve metadata
rm
: Delete with Caution
Be careful—rm
deletes files permanently:
rm file.txt # Remove a file
rm -r directory # Remove a directory and its contents
rm -i *.pdf # Confirm each deletion
rm -f unwanted.txt # Force delete, no confirmation
Always double-check before using -f
!
file
: Know What You’re Dealing With
Not sure what kind of file you’re looking at? Use:
file image.jpg # Basic info
file -i document.txt # Show MIME type
file * # Check all files in current directory
That’s a Wrap
These commands are the foundation of working with files in Linux. Practice them, mix and match options, and you’ll soon move through the terminal like a pro.