Skip to main content
Managing files and directories is a foundational skill for any Linux user or administrator. In this guide, you’ll learn how to list, create, copy, move (or rename), and delete files and directories using core commands like ls, touch, mkdir, cp, mv, and rm.

Listing Files and Directories with ls

The ls (list) command displays directory contents. By default, hidden files (those beginning with .) are not shown.

Common ls Usage

Basic Listing

Including Hidden Files

Detailed, Human-Readable Output

Understanding the Linux File System Tree

Linux files and directories form an inverted tree with / as the root. Every path you use is either absolute (from /) or relative (from your current directory).
  • /
    • /home
      • /home/aaron
        • /home/aaron/Documents
        • /home/aaron/Downloads
    • /var
    • /etc
Absolute paths start with / and always refer to the same location.
Relative paths begin from your current directory (check with pwd).

Absolute Path

Relative Path

To move up one level:
Jump to your home directory:
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."

Creating Files and Directories

  • Create an empty file:
  • Create a directory:
Both commands accept absolute or relative paths:

Copying Files and Directories with cp

Use cp to duplicate files and directories.

Copying a Single File

To copy and rename at the same time:
The image shows a file directory structure with a command line interface on the left. The directory path includes folders named "home," "aaron," and "Receipts," leading to a file named "Receipt.pdf."

Copying Directories Recursively

This duplicates the entire Receipts folder and its contents into BackupOfReceipts. Ensure the destination name does not already exist to avoid nesting.

Moving and Renaming with mv

The mv command handles both moving and renaming:
  • Move a file:
  • Rename a file:
  • Rename or move a directory:
No recursive flag is needed for directories; mv automatically moves contents.

Deleting Files and Directories with rm

Use caution when removing files and directories:
  • Remove a file:
  • Remove a non-empty directory:
The rm -r command permanently deletes directories and their contents. Always double-check the path before pressing Enter!

References

Watch Video