Module 37 min
Working with Files
cp, mv, rm, mkdir, find
Creating, copying, moving, and deleting files and directories is daily work. The commands are short and consistent.
bash
mkdir runs # make a directory
mkdir -p a/b/c # make nested directories in one go
cp config.json config.bak # copy a file
cp -r src src_backup # copy a directory and its contents (-r)
mv old.v new.v # rename or move a file
rm temp.log # delete a file
rm -r old_run # delete a directory and everything in itFinding files
On a real project you will lose track of files constantly. find searches a directory tree by name or other criteria.
bash
find . -name "*.rpt" # all .rpt files below here
find . -name "spm*.v" # files starting with spm, ending .v
find runs -name "*.log" -mtime -1 # .log files changed in last dayWatch out
there is no recycle bin. rm deletes permanently and rm -r deletes whole trees with no undo. Double-check the path before you press Enter, and never run rm -rf on a path you are not certain of. This is the most dangerous command in this path.
Pro tip
get into the habit of ls before rm: list what matches first, confirm it is what you mean, then delete. A careful engineer checks before destroying.