This note covers common patterns for creating, copying, moving, renaming, organizing, and deleting files from the shell.
Create one directory:
mkdir reportsCreate nested directories:
mkdir -p project/{src,docs,tests}
mkdir -p project/logs/archiveCreate a directory with a specific mode:
mkdir -m 700 privateUseful options:
-pcreates missing parent directories and does not fail if the directory already exists.-m MODEsets the directory permission mode at creation time.-vprints each directory created.
Copy one file to a new file:
cp report.txt report.backup.txtCopy files into a directory:
cp *.txt text-files/Copy a directory tree:
cp -r site site.backupPreserve basic metadata:
cp -p original.txt preserved-copy.txtPrompt before overwriting:
cp -i draft.txt final.txtRename a file:
mv draft.txt final.txtMove a file into a directory:
mv final.txt reports/Move several files:
mv *.log logs/Prompt before overwriting:
mv -i new.conf app.confRemove one file:
rm old-report.txtPrompt before removal:
rm -i old-report.txtRemove an empty directory:
rmdir empty-dirRemove a directory tree only when you have verified the target:
pwd
ls -la old-build
rm -r old-buildAvoid using rm -rf as a default habit. It is useful in automation only when the target path is explicitly controlled and verified.
One compact pattern:
mkdir -p project/{bin,docs,logs,src,tests}
touch project/README.mdThen inspect:
find project -maxdepth 2 -type d | sortThe useful lesson is the sequence: create structure, create minimal marker files, then inspect the result.