Pcornel
Linux

File & Directory Management

Cheat sheet · https://pcornel.dk/topic.php?topic=2678

Back to the Topic

Answer

File and directory management covers creating, copying, moving, renaming, deleting and finding files: ls, cp, mv, rm, mkdir, find, du, rsync.

Remember

rm has no recycle bin — check globs with echo/ls first. Use cp -a or rsync -a to keep owners, permissions and timestamps. find … -print before find … -delete. Quote names with spaces.

First checks

  • ls -la <dir> — contents with hidden files
  • find <dir> -name '<pattern>' -mtime +30 — files by name and age
  • du -sh <dir>/* — size per entry
  • rsync -aHAX --dry-run <src> <dst> — preview a copy that keeps metadata

Commands

ls
List directory entries and inspect names, types and basic metadata.
cd
Change the current shell working directory used to resolve relative paths.
pwd
Print the shell current working directory as an absolute path.
mkdir
Create one or more directories with requested parent and permission behavior.
rmdir
Remove empty directories without deleting populated directory trees.
touch
Create an empty file when absent or update file timestamps when present.
cp
Copy files or directory trees while controlling recursion, metadata and overwrite behavior.
mv
Move or rename filesystem objects, including replacement behavior at the destination.
rm
Remove files or directory trees according to the selected recursion and force options.
find
Walk filesystem paths and select entries by name, type, metadata or predicates.
locate
Search the filename database for paths without traversing the live filesystem.
stat
Show detailed inode-backed metadata, timestamps, ownership, size and filesystem identity.
file
Classify file content or format using signatures rather than the filename extension.
tree
Render a recursive directory hierarchy for a selected filesystem path.

Verify in this order

target selected and previewed → operation runs with the right options → result checked

Where it usually breaks

First mismatch in persistent intent → provider/parser/generator → kernel/userspace runtime → dependency/security context → logs/counters → consumer-visible read-back; preserve identity/native diagnostic/pre-state before mutation.

Read-only verification commands unless stated otherwise. Confirm syntax for your platform and release. Full reference: https://pcornel.dk/topic.php?topic=2678

Confirmation

Confirm action

Continue?