Skip to main content
In this guide, you’ll master essential Linux file operations—listing, creating, copying, moving, and deleting files and directories—to streamline your workflow on any Unix-like system.

Table of Contents

  1. Key Concepts
  2. Listing Files and Directories
  3. Filesystem Structure
  4. Creating Files and Directories
  5. Copying Files and Directories
  6. Moving and Renaming
  7. Deleting Files and Directories
  8. Summary of Commands
  9. References

Key Concepts

Before you begin, make sure you understand:
  • The Linux filesystem tree and hierarchy
  • The difference between absolute paths and relative paths
  • How to navigate directories with cd and identify your location with pwd
Absolute paths start at the root directory / while relative paths are based on your current working directory.

Listing Files and Directories

Use the ls command to display directory contents:
Show hidden files (those starting with a dot) with -a:
For a detailed (long) listing including permissions, ownership, size, and timestamp, add -l:
Combine options to save time:

Filesystem Structure

Linux organizes files in an inverted tree structure:
  • Root directory: /
  • Standard subdirectories: /home, /var, /etc, /usr, etc.
  • Each folder can contain files and more subdirectories

Absolute Paths

Absolute paths always begin at /.
Example:

Relative Paths

Relative paths depend on your current directory. Check it with:
Change directories using cd:
The image shows a directory structure with a command line interface on the left. The directory tree includes folders like "home," "var," and "root," with a file named "Invoice.pdf" under "aaron/Documents."
From /home/aaron, these relative paths resolve to:
  • documents/invoice.pdf/home/aaron/documents/invoice.pdf
  • invoice.pdf/home/aaron/invoice.pdf
  • ../invoice.pdf/home/invoice.pdf
  • ../../invoice.pdf/invoice.pdf
Additional cd shortcuts:

Creating Files and Directories

  • Create an empty file:
  • Create a new directory:

Copying Files and Directories

Use cp [source] [destination]:
  • Copy a file into a directory:
  • Copy and rename:
  • Copy a directory recursively:
    Ensure backup_of_receipts does not already contain a receipts subdirectory.

Moving and Renaming

Use mv [source] [destination] to move or rename:
mv works seamlessly on both files and directories.

Deleting Files and Directories

rm -r permanently deletes directories and their contents. Use with caution to avoid data loss.
  • Remove a file:
  • Remove a directory recursively:
Always include -r when deleting directories.

Summary of Commands

References

Watch Video