Catalog / File System Tools Cheatsheet (Linux)
File System Tools Cheatsheet (Linux)
A comprehensive cheat sheet covering essential Linux file system tools like `ls`, `cp`, `mv`, and `rm`, including options, examples, and best practices for efficient file management.
ls - Listing Files and Directories
Basic Usage
|
Lists files and directories in the current directory. |
|
Lists files and directories in the specified directory. |
|
Lists files in long format, showing permissions, size, modification date, etc. |
|
Lists all files, including hidden files (those starting with |
|
Sorts files by modification time (newest first). |
|
Reverses the order of the listing. |
Combining Options
|
Lists all files (including hidden) in long format. |
|
Lists files in long format, sorted by modification time. |
|
Lists files in long format, sorted by modification time (oldest first). |
|
Lists files in long format, with file sizes in human-readable format (e.g., KB, MB, GB). |
|
List directories - useful with wildcards. |
|
Appends a character to each filename indicating the file type (* for executable, / for directory, @ for symbolic link, = for socket). |
Advanced Usage
|
|
|
|
|
cp - Copying Files and Directories
Basic Copying
|
Copies a file or directory from source to destination. |
|
Copies multiple files to a directory. |
|
Copies a directory recursively (including all files and subdirectories). |
|
Interactive mode. Asks for confirmation before overwriting existing files. |
|
Preserves the original file’s mode, ownership, and timestamps. |
Advanced Copying
|
|
|
|
|
Examples
Copying a file: |
Copying a directory recursively: |
Copying multiple files with confirmation: |
mv - Moving and Renaming Files and Directories
Basic Moving and Renaming
|
Moves or renames a file or directory from source to destination. |
|
Moves multiple files to a directory. |
|
Interactive mode. Asks for confirmation before overwriting existing files. |
Moving Options
|
No clobber. Do not overwrite an existing file. Useful for scripts. |
|
Verbose. Shows files as they are moved. |
|
Move only when the SOURCE file is newer than the destination file or when the destination file is missing. |
Examples
Renaming a file: |
Moving a file to a different directory: |
Moving multiple files to a directory: |
Moving a directory: |
rm - Removing Files and Directories
Basic Removal
|
Removes a file. |
|
Interactive mode. Asks for confirmation before deleting. |
|
Force removal. Ignores nonexistent files and suppresses prompts. |
Removing Directories
|
Removes an empty directory. |
|
Removes a directory and its contents recursively. |
|
Force removal of a directory and its contents recursively. Use with caution! |
Examples
Removing a file: |
Removing a directory recursively: |
Force removing a directory and its contents: |
Removing multiple files: |
Important Notes
Caution: |
Best Practice: Use |