Use it for everyday file work, or before bulk operations where a mistake is costly.
File & Directory Management
File and directory management covers creating, copying, moving, renaming, deleting and finding files: ls, cp, mv, rm, mkdir, find, du, rsync.
1. Preview: ls <pattern> or find … -print.
2. Copy with metadata: cp -a / rsync -aHAX.
3. Dry run large operations (rsync -n).
4. Delete only after the preview matches.
5. Check result: ls -la, du -sh.
target selected and previewed → operation runs with the right options → result checked
For File & Directory Management, continue with the first unproven Topic check: Confirm current directory, mount namespace and the exact absolute/resolved target before a mutating command. If that boundary is healthy, advance to the adjacent check: Inspect object type, inode/device, links, owner/group, mode, timestamps, size/allocation and relevant ACL/xattr data before preservation-sensitive work. Preserve the same host/time/identity scope and rerun the original workload before accepting recovery.
Continue only after interpreting the current observation.Context & applicabilityCommon mistakes · platform/version boundaries
Operational reference
Fast context before you go deeper.
lsPrimary Commands
Configuration and operational commands for this Topic.
lsVerifyList directory entries and inspect names, types and basic metadata.
Use when: Primary lookup intent: inspect. Use ls when the lookup goal is to list directory entries and inspect names, types and basic metadata. Tie the result to the same host, namespace, user identity and time window as the symptom.
Quick note: Output review: healthy and suspicious cues are command-specific interpretation boundaries, not fixed literal output samples. Intent class: inspect. Safety class: read_only. Intent describes the primary lookup role; safety remains command-family capability and can be higher than a read-only invocation. ls is documented as an operational lookup primitive under File & Directory Management. The canonical leaf intentionally represents the command family; options remain distribution/tool-version specific.
cdReferenceChange the current shell working directory used to resolve relative paths.
Use when: Primary lookup intent: inspect. Use cd when the lookup goal is to change the current shell working directory used to resolve relative paths. Tie the result to the same host, namespace, user identity and time window as the symptom.
Quick note: Output review: healthy and suspicious cues are command-specific interpretation boundaries, not fixed literal output samples. Intent class: inspect. Safety class: read_only. Intent describes the primary lookup role; safety remains command-family capability and can be higher than a read-only invocation. cd is documented as an operational lookup primitive under File & Directory Management. The canonical leaf intentionally represents the command family; options remain distribution/tool-version specific.
pwdReferencePrint the shell current working directory as an absolute path.
Use when: Primary lookup intent: verify. Use pwd when the lookup goal is to print the shell current working directory as an absolute path. Tie the result to the same host, namespace, user identity and time window as the symptom.
Quick note: Output review: healthy and suspicious cues are command-specific interpretation boundaries, not fixed literal output samples. Intent class: verify. Safety class: read_only. Intent describes the primary lookup role; safety remains command-family capability and can be higher than a read-only invocation. pwd is documented as an operational lookup primitive under File & Directory Management. The canonical leaf intentionally represents the command family; options remain distribution/tool-version specific.
mkdirReferenceCreate one or more directories with requested parent and permission behavior.
Use when: Primary lookup intent: configure. Use mkdir when the lookup goal is to create one or more directories with requested parent and permission behavior. Tie the result to the same host, namespace, user identity and time window as the symptom.
Quick note: Output review: healthy and suspicious cues are command-specific interpretation boundaries, not fixed literal output samples. Intent class: configure. Safety class: low_impact. Intent describes the primary lookup role; safety remains command-family capability and can be higher than a read-only invocation. mkdir is documented as an operational lookup primitive under File & Directory Management. The canonical leaf intentionally represents the command family; options remain distribution/tool-version specific.
rmdirReferenceRemove empty directories without deleting populated directory trees.
Use when: Primary lookup intent: configure. Use rmdir when the lookup goal is to remove empty directories without deleting populated directory trees. Tie the result to the same host, namespace, user identity and time window as the symptom.
Quick note: Post-change verification for rmdir: Verify path metadata and rerun the workload that creates/uses the directory. Output review: healthy and suspicious cues are command-specific interpretation boundaries, not fixed literal output samples. Intent class: configure. Safety class: changes_state. Intent describes the primary lookup role; safety remains command-family capability and can be higher than a read-only invocation. rmdir is documented as an operational lookup primitive under File & Directory Management. The canonical leaf intentionally represents the command family; options remain distribution/tool-version specific.
touchReferenceCreate an empty file when absent or update file timestamps when present.
Use when: Primary lookup intent: configure. Use touch when the lookup goal is to create an empty file when absent or update file timestamps when present. Tie the result to the same host, namespace, user identity and time window as the symptom.
Quick note: Output review: healthy and suspicious cues are command-specific interpretation boundaries, not fixed literal output samples. Intent class: configure. Safety class: low_impact. Intent describes the primary lookup role; safety remains command-family capability and can be higher than a read-only invocation. touch is documented as an operational lookup primitive under File & Directory Management. The canonical leaf intentionally represents the command family; options remain distribution/tool-version specific.
cpReferenceCopy files or directory trees while controlling recursion, metadata and overwrite behavior.
Use when: Primary lookup intent: configure. Use cp when the lookup goal is to copy files or directory trees while controlling recursion, metadata and overwrite behavior. Tie the result to the same host, namespace, user identity and time window as the symptom.
Quick note: Post-change verification for cp: Compare source/destination content and metadata independently, then retest the consuming workload. Output review: healthy and suspicious cues are command-specific interpretation boundaries, not fixed literal output samples. Intent class: configure. Safety class: changes_state. Intent describes the primary lookup role; safety remains command-family capability and can be higher than a read-only invocation. cp is documented as an operational lookup primitive under File & Directory Management. The canonical leaf intentionally represents the command family; options remain distribution/tool-version specific.
mvReferenceMove or rename filesystem objects, including replacement behavior at the destination.
Use when: Primary lookup intent: configure. Use mv when the lookup goal is to move or rename filesystem objects, including replacement behavior at the destination. Tie the result to the same host, namespace, user identity and time window as the symptom.
Quick note: Post-change verification for mv: Verify final path identity/content/metadata and retest the original consumer. Output review: healthy and suspicious cues are command-specific interpretation boundaries, not fixed literal output samples. Intent class: configure. Safety class: changes_state. Intent describes the primary lookup role; safety remains command-family capability and can be higher than a read-only invocation. mv is documented as an operational lookup primitive under File & Directory Management. The canonical leaf intentionally represents the command family; options remain distribution/tool-version specific.
rmReferenceRemove files or directory trees according to the selected recursion and force options.
Use when: Primary lookup intent: destructive. Use rm when the lookup goal is to remove files or directory trees according to the selected recursion and force options. Tie the result to the same host, namespace, user identity and time window as the symptom.
Quick note: Post-change verification for rm: Verify restored path identity/content/metadata and rerun the original workload. Output review: healthy and suspicious cues are command-specific interpretation boundaries, not fixed literal output samples. Intent class: destructive. Safety class: destructive. Intent describes the primary lookup role; safety remains command-family capability and can be higher than a read-only invocation. rm is documented as an operational lookup primitive under File & Directory Management. The canonical leaf intentionally represents the command family; options remain distribution/tool-version specific.
findReferenceWalk filesystem paths and select entries by name, type, metadata or predicates.
Use when: Primary lookup intent: inspect. Use find when the lookup goal is to walk filesystem paths and select entries by name, type, metadata or predicates. Tie the result to the same host, namespace, user identity and time window as the symptom.
Quick note: Post-change verification for find: Re-run a non-mutating match preview and verify content/metadata plus the original consumer. Output review: healthy and suspicious cues are command-specific interpretation boundaries, not fixed literal output samples. Intent class: inspect. Safety class: changes_state. Intent describes the primary lookup role; safety remains command-family capability and can be higher than a read-only invocation. find is documented as an operational lookup primitive under File & Directory Management. The canonical leaf intentionally represents the command family; options remain distribution/tool-version specific.
locateReferenceSearch the filename database for paths without traversing the live filesystem.
Use when: Primary lookup intent: inspect. Use locate when the lookup goal is to search the filename database for paths without traversing the live filesystem. Tie the result to the same host, namespace, user identity and time window as the symptom.
Quick note: Output review: healthy and suspicious cues are command-specific interpretation boundaries, not fixed literal output samples. Intent class: inspect. Safety class: read_only. Intent describes the primary lookup role; safety remains command-family capability and can be higher than a read-only invocation. locate is documented as an operational lookup primitive under File & Directory Management. The canonical leaf intentionally represents the command family; options remain distribution/tool-version specific.
statReferenceShow detailed inode-backed metadata, timestamps, ownership, size and filesystem identity.
Use when: Primary lookup intent: verify. Use stat when the lookup goal is to show detailed inode-backed metadata, timestamps, ownership, size and filesystem identity. Tie the result to the same host, namespace, user identity and time window as the symptom.
Quick note: Output review: healthy and suspicious cues are command-specific interpretation boundaries, not fixed literal output samples. Intent class: verify. Safety class: read_only. Intent describes the primary lookup role; safety remains command-family capability and can be higher than a read-only invocation. stat is documented as an operational lookup primitive under File & Directory Management. The canonical leaf intentionally represents the command family; options remain distribution/tool-version specific.
fileReferenceClassify file content or format using signatures rather than the filename extension.
Use when: Primary lookup intent: verify. Use file when the lookup goal is to classify file content or format using signatures rather than the filename extension. Tie the result to the same host, namespace, user identity and time window as the symptom.
Quick note: Output review: healthy and suspicious cues are command-specific interpretation boundaries, not fixed literal output samples. Intent class: verify. Safety class: read_only. Intent describes the primary lookup role; safety remains command-family capability and can be higher than a read-only invocation. file is documented as an operational lookup primitive under File & Directory Management. The canonical leaf intentionally represents the command family; options remain distribution/tool-version specific.
treeReferenceRender a recursive directory hierarchy for a selected filesystem path.
Use when: Primary lookup intent: inspect. Use tree when the lookup goal is to render a recursive directory hierarchy for a selected filesystem path. Tie the result to the same host, namespace, user identity and time window as the symptom.
Quick note: Output review: healthy and suspicious cues are command-specific interpretation boundaries, not fixed literal output samples. Intent class: inspect. Safety class: read_only. Intent describes the primary lookup role; safety remains command-family capability and can be higher than a read-only invocation. tree is documented as an operational lookup primitive under File & Directory Management. The canonical leaf intentionally represents the command family; options remain distribution/tool-version specific.
Verification & Troubleshooting
Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.
Use the operational verification above to establish the expected state.
Capture the concrete output, symptom, packet, log or counter before changing anything.
Step 1 Operational evidence path Verify boundary
caller cwd + mount namespace → pathname resolution/symlinks → dentry/inode + object type → ownership/mode/ACL/xattr + filesystem boundary → requested file operation → resulting namespace/metadata/allocation → consumer read/write/use verification
Healthy evidence: exact target resolution, metadata and post-operation namespace state match intent, and the original consumer can read/write/execute the object as expected.
Step 2 Commands Verify boundary
ls -lah
cp -a src/ dst/
mv old new
rm -i file
find /var/log -name '*.gz' -mtime +30
Step 3 Verification and output interpretation Verify boundary
Verification path. Reproduce with the same shell binary and mode, then inspect expansion and command resolution before changing data. Use tracing carefully to observe commands after expansion without exposing secrets. Validate exit status at the correct pipeline stage, check file descriptors/redirections, and test representative input including whitespace, glob characters and empty values. For text tools, record locale and regex dialect. Verify the external effect of the script, not merely that parsing completed.
Existing fast checks for this Topic. - Confirm current directory, mount namespace and the exact absolute/resolved target before a mutating command.
- Inspect object type, inode/device, links, owner/group, mode, timestamps, size/allocation and relevant ACL/xattr data before preservation-sensitive work.
- For copy/move/delete operations, verify filesystem boundaries and whether the application has open descriptors or expects atomic rename behavior.
- Read back the resulting path/inode/metadata and repeat the original application or administrative operation.
Verification chain. caller cwd + mount namespace → pathname resolution/symlinks → dentry/inode + object type → ownership/mode/ACL/xattr + filesystem boundary → requested file operation → resulting namespace/metadata/allocation → consumer read/write/use verification
Step 4 Failure modes and next checks Narrow the fault
Suspicious evidence: a relative path, symlink, mount crossing or wildcard expands differently than assumed; metadata is silently lost; or a destructive command succeeds against the wrong resolved object.
File-management verification ends at the consumer-visible object, not at an exit code: show the intended pathname resolves to the intended inode/type with required metadata and that the original consumer operation succeeds.
Next check: Continue from the first step that has not been verified: capture the exact shell-delivered argv/streams or resolved object, verify the effective target state, change only the demonstrated cause, then repeat the original consumer/script/workload and adjacent regression checks.
Step 5 Common mistakes Narrow the fault
rm -rfwith an unset variable (rm -rf $dir/).- Copying without
-a, losing permissions and timestamps.
Evidence · 1 on this Topic
Expected observations and documentation recipes are reference material. Record actual output, device identity, scope and time before claiming a verified result.
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.
ls -la <dir>— contents with hidden filesfind <dir> -name '<pattern>' -mtime +30— files by name and agedu -sh <dir>/*— size per entryrsync -aHAX --dry-run <src> <dst>— preview a copy that keeps metadata
ReferenceWhat it is1 section · depth on demand
Core model
Treat every pathname operation as resolution through the caller's mount namespace and working directory to a concrete dentry/inode. Before destructive changes, confirm the exact resolved target, object type, ownership/mode, filesystem boundary, links and open-file use; after the operation, read back the resulting object and repeat the workload that depended on it.
ReferenceImportant terms & boundaries5 sections · depth on demand
What this shows and what it does not
File-management verification ends at the consumer-visible object, not at an exit code: show the intended pathname resolves to the intended inode/type with required metadata and that the original consumer operation succeeds.
In depth
Finding and acting on files with find
Everyday file management uses ls, cp, mv, rm and mkdir. Finding and processing files across a directory tree is find's job. The find(1) manual page explains the key points:
- find evaluates an expression for each file, from left to right.
- Tests such as
-name,-type,-mtime,-size,-userand-permselect files. - Actions such as
-print,-deleteand-execact on them. - Without an explicit action,
-printis applied to every match. - Expressions are joined by an implicit
-and, which binds more tightly than-or, so parentheses are needed when they're mixed.
Common tests
| Test | Matches |
|---|---|
-name '*.log' / -iname | File name by pattern (quote it!) / case-insensitively |
-path '*/cache/*' | The whole path |
-type f / d / l | Files / directories / symlinks |
-mtime +30 / -mmin -60 | Modified more than 30 days ago / within the last hour |
-size +100M | Larger than 100 MiB |
-user, -group, -nouser | Owner, group, files without a valid owner |
-perm -0002 | World-writable |
-newer file | Modified more recently than file |
-empty | Empty files or directories |
Acting on the results
| Form | Behaviour |
|---|---|
-exec cmd {} \; | One command per file |
-exec cmd {} + | Many files per command, like xargs; faster |
-print0 | xargs -0 cmd | Safe with spaces and newlines in names |
-delete | Deletes matches; implies -depth |
-prune | Doesn't descend into a matching directory |
Pitfalls the manual warns about
| Pitfall | Avoid it by |
|---|---|
-delete placed before the tests deletes everything | Put -delete last; run with -print first |
An unquoted *.log is expanded by the shell | Always quote patterns |
Plain -print piped to xargs breaks on odd names | Use -print0 with xargs -0, or -exec ... + |
-o without parentheses gives unexpected results | \( -name a -o -name b \) |
host$ find /var/log/app -type f -name '*.log' -mtime +30 -print | head -3
/var/log/app/api-2026-10-01.log
/var/log/app/api-2026-10-02.log
host$ find /var/log/app -type f -name '*.log' -mtime +30 -delete
host$ find /srv -xdev -type f -size +1G -exec ls -lh {} + 2>/dev/null | sort -k5 -h | tail -3
host$ find / -xdev \( -path /proc -o -path /sys \) -prune -o -type f -perm -0002 -print 2>/dev/null
host$ find /srv/www -type f \( -name '*.php' -o -name '*.phtml' \) -newer /root/deploy-marker
host$ find /home -xdev -nouser -print0 | xargs -0 -r ls -ld
Preview before deleting
The first command lists exactly what the second will delete: the same expression, with -print instead of -delete. -xdev keeps searches on one file system, so they don't wander into network mounts or /proc.
Documented example, not captured output.
How it works at runtime
File & Directory Management is part of File & Directory Management. File & Directory Management is the operational Linux reference for locating, inspecting, creating, copying, moving and removing filesystem objects while preserving the distinction between path names, inode identity, metadata, mount boundaries and the consumer-visible result.
Runtime state ownership and mechanics. Shell behavior is a parsing and process-construction pipeline: lexical parsing, quoting, expansions, redirections, pipeline setup, command resolution, fork/exec or builtin execution, wait/status collection and signal/job-control handling. Text-processing tools operate on byte or character streams with locale-dependent behavior, and regular expressions differ by tool and mode. A visible command line can therefore differ materially from the argv, file descriptors and environment presented to the executed program.
Topic-specific state model. File & Directory Management is the operational Linux reference for locating, inspecting, creating, copying, moving and removing filesystem objects while preserving the distinction between path names, inode identity, metadata, mount boundaries and the consumer-visible result.
Technical metadata. Host/distribution/kernel, Bash/shell version and invocation mode, login/interactive state, cwd/mount namespace, uid/gid, locale/IFS, shell options, startup files, variable/environment state, source command/script, quoting/expansion, final argv, fd 0/1/2 and redirections, pipeline stages/PIPESTATUS, path/inode/object metadata, exit status/signal, target read-back, original workload result.
Interpretation rule. - A pathname ≠ a stable object identity; rename, mount changes and symlink resolution can point the same text at a different inode.
- cp success ≠ metadata, ACLs, xattrs, sparse layout, hard-link relationships or application semantics were preserved.
- rm removes a directory entry ≠ allocated storage is immediately reclaimed when another link or open file descriptor still references the inode.
- find/locate results ≠ identical truth; find walks current namespaces while locate commonly queries a periodically refreshed database.
Quick reference
File and directory commands worth mastering:
cp -a src/ dst/ # archive: perms, owners, timestamps, links
rsync -aHAX --info=progress2 src/ dst/
mv -n a b # don't overwrite
find /var/log -name '*.log' -mtime +30 -delete
find . -type f -newermt '2026-11-01' -size +100M
tree -L 2 /etc/nginx
stat -c '%y %n' *.conf
touch -d '2 days ago' marker
find actions (-delete, -exec … {} +) are powerful — run without the action first to see what matches. Prefer rsync for large copies (resumable, verifiable).
Limits and how it fails
Primary failure point. File-management verification ends at the consumer-visible object, not at an exit code: show the intended pathname resolves to the intended inode/type with required metadata and that the original consumer operation succeeds.
Model. A command shown in history is not necessarily what the program received after expansion. Pipeline exit status can represent only one command unless shell options change that behavior. Quoting errors, locale differences and glob expansion can look like tool defects. Builtins and external commands can share names. Successful script exit does not show every intended side effect occurred unless the script checks them. Keep shell semantics separate from the subsystem operated on by the command.
ReferenceConfiguration & state1 section · depth on demand
Configuration, persistence and lifecycle
Configuration intent and lifecycle. Separate shell startup configuration from script code and from the external tools a script invokes. Login versus interactive startup files, set options, aliases/functions, locale, PATH and environment inheritance all affect behavior. Scripts should make interpreter, error handling, quoting and input assumptions explicit. Prefer portable constructs only when portability is a requirement; otherwise record the required shell/tool version. Do not assume an interactive alias, function or profile exists in cron, systemd or automation contexts.
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Verification history & basis
When and against what this Topic was checked. Later text edits do not count as a new check.
Authoritative/upstream documentation reviewed for bounded claims in File & Directory Management. Documentation verification only; this is not observed lab or production Evidence.
Basis: https://www.gnu.org/software/coreutils/manual/coreutils.html · confidence 94%What changed and what may be affected
Recent technical edits are separated from ordinary page timestamps. Relationship impact is advisory: it identifies nearby canonical references to review, not automatic breakage.
Terms & aliases
Hover a linked term for a quick definition; click it to open its glossary entry. Aliases are other names that find this Topic in search.
Quick lookup tables
File & Directory Management operational reference
Topic-specific lookup boundaries, proof limits and next-step Evidence for File & Directory Management.
| Lookup boundary | Topic-specific reference | Operational use |
|---|---|---|
| Scope / effective state | File & Directory Management is the operational Linux reference for locating, inspecting, creating, copying, moving and removing filesystem objects while preserving the distinction between path names, inode identity, metadata, mount boundaries and the consumer-visible result. | Establish exactly what this Topic owns before crossing into another subsystem. |
| Fast verification | Pin host/distribution + shell/version/mode → identify cwd/mount namespace + input/path/stream → preserve quoting/expansion and final argv → map fd/pipeline/process boundaries → inspect object/variable/status/signal state → make one minimal reversible change → read back effective state → repeat original consumer/script/workload test. | Use the shortest evidence path first; a fast check is a boundary test, not blanket proof. |
| Verification chain | caller cwd + mount namespace → pathname resolution/symlinks → dentry/inode + object type → ownership/mode/ACL/xattr + filesystem boundary → requested file operation → resulting namespace/metadata/allocation → consumer read/write/use verification | Trace requested/configured state through effective state to the observed workload result. |
| Failure boundary | File-management verification ends at the consumer-visible object, not at an exit code: prove the intended pathname resolves to the intended inode/type with required metadata and that the original consumer operation succeeds. | Stop broad troubleshooting at the first boundary that is not supported by evidence. |
| Positive evidence | Correlated Linux file/text/shell evidence can establish this proof path: caller cwd + mount namespace → pathname resolution/symlinks → dentry/inode + object type → ownership/mode/ACL/xattr + filesystem boundary → requested file operation → resulting namespace/metadata/allocation → consumer read/write/use verification | Use this observation only for the specific claim it actually supports. |
| Evidence limit | It does not independently prove behavior outside the captured host, shell/session, cwd/namespace, input, process, filesystem, locale, time or workload scope. File-management verification ends at the consumer-visible object, not at an exit code: prove the intended pathname resolves to the intended inode/type with required metadata and that the original consumer operation succeeds. | Do not promote a local success signal into end-to-end or adjacent-dependency proof. |
| Next troubleshooting check | Continue from the first unproven boundary: capture the exact shell-delivered argv/streams or resolved object, verify the effective target state, change only the demonstrated cause, then repeat the original consumer/script/workload and adjacent regression checks. | Continue to the next unresolved boundary while preserving the original test condition. |
File & Directory Management · operational reference
Compact Linux state, persistence, verification and boundary reference for fast lookup.
| Reference boundary | File & Directory Management |
|---|---|
| Topic path | File & Directory Management |
| Runtime state | File & Directory Management is the operational Linux reference for locating, inspecting, creating, copying, moving and removing filesystem objects while preserving the distinction between path names, inode identity, metadata, mount boundaries and the consumer-visible result. |
| Fast checks | - Confirm current directory, mount namespace and the exact absolute/resolved target before a mutating command. - Inspect object type, inode/device, links, owner/group, mode, timestamps, size/allocation and relevant ACL/xattr data before preservation-sensitive work. - For copy/move/delete operations, verify filesystem boundaries and whether the application has open descriptors or expects atomic rename behavior. - Read back the resulting path/inode/metadata and repeat the original application or administrative operation. |
| Verification chain | caller cwd + mount namespace → pathname resolution/symlinks → dentry/inode + object type → ownership/mode/ACL/xattr + filesystem boundary → requested file operation → resulting namespace/metadata/allocation → consumer read/write/use verification Boundary chain: local authoritative state → adjacent dependency → effective/programmed state → original workload/request → return/regression → explicit Evidence boundary. Boundary chain: local authoritative state → adjacent dependency → effective/programmed state → original workload/request → return path or regression → explicit Evidence boundary. |
| Failure boundary | File-management verification ends at the consumer-visible object, not at an exit code: prove the intended pathname resolves to the intended inode/type with required metadata and that the original consumer operation succeeds. Boundary chain: process/context → userspace configuration → kernel subsystem/resource → device/network/filesystem dependency → effective state → original workload. |
| Persistence rule | Prove which configuration source owns the state, then prove that the running consumer loaded or generated the intended state. |