Need to sort through files or folders in Linux? The terminal provides powerful one-liners to manipulate directories without GUI tools. These commands work in any Linux terminal (Ubuntu, Fedora, Arch, etc.), and let you create, move, delete, and organize files with speed and precision—no mouse required.

What You'll Need

  • A Linux terminal (run via Ctrl+Alt+T in most desktop environments)
  • Basic familiarity with command-line syntax (optional but helpful)
  • Root or sufficient permissions for advanced operations (e.g., `sudo` for system-wide actions)
  • An example directory structure (e.g., ~/Downloads or /home/user/project)

Step-by-Step

  1. Navigate to a directory Use `cd` to change directories. Replace `` with an actual folder: cd ~/Documents To return to the home directory, use: cd ~ or cd Example: Navigate to a project folder: cd ~/my-project
  2. List directory contents Use `ls` to see files/folders. Add `-l` for long listings (permissions, size): ls -l Add `-a` to show hidden files (e.g., `.bashrc`): ls -la
  3. Create a new directory Use `mkdir` to make folders. For nested folders, separate paths with slashes: mkdir new-folder mkdir parent/child-folder For root permissions, use `sudo`: sudo mkdir /srv/web Warning: This requires root access and can overwrite existing files.
  4. Move or rename files/folders Use `mv` to rename or move. For cross-directory moves, omit the destination: mv old-name.txt ~/archive To rename: mv old-name.txt new-name.txt If that did not work: Check if the target path exists. If files are locked, use: chflags -R noupdate && mv target (Only works in macOS; replace with `sudo` + `ipcallow` for Linux if needed.)
  5. Delete files or folders Files: Use `rm` with caution. For small files: rm file.txt For force-deleting (no prompts): rm -f file.txt Folders: Use `rm -r` to delete recursively (⚠️ permanent!): rm -r folder-name To delete empty folders only: rmdir folder-name If that did not work: Check permissions with `ls -ld folder-name` and use `sudo` if needed.
  6. Copy files/folders Use `cp`. To copy a file: cp file.txt ~/backup To copy recursively (folders too): cp -r folder-name ~/backup Notes: Avoid overwriting existing files; use `-i` for interactive confirmation: cp -i file.txt ~/backup
  7. Create and use symbolic links Use `ln -s` to make shortcuts. Example: ln -s ~/old-link ~/new-link Why use this? Link files across partitions or share a file via a single path. Delete the link (not the original) with: rm ~/new-link
  8. Change working directory Use `pwd` to verify current location: pwd Combine with `ls -l` to see relative paths: ls -l --relative
  9. View/move files by extension Filter files with `grep` or `find`: ls *.txt (lists all .txt files) find . -name "*.pdf" (finds PDFs recursively) Example: List all .jpg images in a folder: ls *.jpg
  10. Compress files/folders Use `tar` to create archives (e.g., for backup): tar -cvf archive.tar folder-name For ZIP-style archives (Linux 12+): zip archive.zip folder-name Warning: Compressed files take up more space than originals.
  11. Check disk space Use `df` to see mounted drives: df -h du -sh folder-name (estimates folder size)

Common Mistakes

  • Forgetting to use absolute paths Example: `mv ~/old /new` fails if `/new` doesn’t exist. Always specify full paths: mv ~/old ~/new
  • Deleting folders recursively without confirmation Use `rm -i` for interactive prompts or `rmdir` only for empty folders.
  • Overwriting files with `cp` Add `-i` to confirm overwrite: cp -i file.txt ~/backup
  • Using `rm -r` on non-empty folders Always verify with `ls` before running `rm -r`.

Tips

  • Use tab completion Press Tab to autocomplete paths (e.g., `mkdir my-p` → `my-project`).
  • Pipes (`|`) for complex commands Example: List files > filter > sort: ls | grep .txt | sort
  • Search for commands with `which` Check if a command is installed: which ls
  • Aliases for common tasks Create shortcuts in `~/.bashrc`: alias ll='ls -l' (Reload with `source ~/.bashrc`.)
  • Redirection for logging Save output to a file: ls -l > mylist.txt

Troubleshooting

  • Command not found Check if the command is installed: which ls Update your system: sudo apt update && sudo apt upgrade (Debian/Ubuntu) sudo dnf upgrade (Fedora/RHEL)
  • Permission denied Use `sudo` (for root access) or check folder permissions: ls -ld folder-name Fix permissions with: chmod +x file.txt
  • `rm` or `mv` hangs Restart the terminal or check for locked files (e.g., in use by another process): lsof | grep filename
  • Symbolic links broken Verify with: ls -l ~/link-name Repair with: ln -sf ~/link-name (Replace `` with the correct source.)
  • Disk full (`df` shows 100%) Free up space: du -sh * | sort -n (lists largest folders) Delete unnecessary files: rm -r /tmp/* (⚠️ caution: deletes temporary files.)

Frequently Asked Questions

How do I create hidden folders in Linux?

Use `mkdir` with a dot prefix: mkdir .hidden-folder These folders won’t appear in `ls` by default but will be accessible in the terminal.

Can I move folders across partitions using terminal?

Yes! Use `mv` with absolute paths: mv /mnt/external/folder ~/Documents Warning: Ensure the target partition has enough space and is writable.

What’s the difference between `cp` and `cp -r`?

`cp` copies single files; `cp -r` copies entire directories (recursively). Example: cp file.txt ~/backup vs. cp -r folder-name ~/backup

How do I permanently delete a file?

Use `rm` without `-i` or `-f` flags: rm file.txt rm -rf folder-name (⚠️ only for empty folders or trusted locations.)

Why won’t `ln -s` create a link?

Check permissions and ensure the source file exists: ls -l ~/source-file If permissions are wrong, use `sudo` or fix with: chmod +x ~/source-file

Can I undo `rm`?

Not directly, but use `trash-cli` (install with `sudo apt install trash-cli`) or `sudo apt install files` (for GUI trash recovery). For critical files, back them up first.