2023 Boost - Week 5#
This week we do "destructive" file system stuff related and take a lot of time to review the most common dangers. Watch this is you want to keep your job once you get it.
How do I create a new directory?
How do I "hide" a file or directory?
Give it a dot (
.) as the first character in name.
How do I move or rename a file or directory?
mv OLD NEW
Be very careful when moving and renaming since you can easily clobber an existing file or directory. Don't bother with activating
noclobberbecause it will get in your way more than help you, just become aware/paranoid about the danger.
How do I move multiple files into a single directory?
mv SOURCE... DIR
SOURCE can be a file, directory (or path to) or a glob.
When moving muliple SOURCEs make sure that DIR is a directory and not a file.
mvsometimes will not work because the source and destination are on different file systems.
How do I list properties of a directory (instead of contents)?
ls -lda DIR
How do I safely avoid typing long or complicated names?
Tap tab (once or twice) for tab completion.
How do I remove a file?
When working with destructive commands that operate on many files try
lsfirst to make sure it only affects the files you want.
How do I create a temporary container (sandbox) just to try dangerous (stupid) things?
podman run -it --rm ghcr.io/rwxrob/ws-skilstak
How do I remove a directory?
rmdirover alternatives to force yourself to be sure of each individual thing that is being deleted within that directory (since
rmdirwill not remove directories containing).
How do I remove a directory and everything under it recursively?
rm -rf DIR
Even though this command does not work on significant system directories (like
/) it is very recursively destructive and should almost never be used. Use
How do I recover a broken or deleted configuration file?
cp /etc/skel/FILE ~
How do I start a new shell and replace the currently running one?
exec bash -l
How do I copy a file?
cp FILE NEWNAME
How do I recusively copy a directory and subdirectories?
cp -r SOURCE.. DIR
This creates new files with new creation dates/times and ownership if copying from another user. Use other
cpargument options when preserving them is important.