2023 Boost - Week 5#
📺 https://youtu.be/ZcEIJFbHRn4
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?
mkdir NAME
-
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
Danger
Be very careful when moving and renaming since you can easily clobber an existing file or directory. Don't bother with activating
noclobber
because 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.
Danger
When moving muliple SOURCEs make sure that DIR is a directory and not a file.
Note
Note that
mv
sometimes 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?
rm FILE
Tip
When working with destructive commands that operate on many files try
ls
first 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?
rmdir DIR
Note
Prefer
rmdir
over alternatives to force yourself to be sure of each individual thing that is being deleted within that directory (sincermdir
will not remove directories containing). -
How do I remove a directory and everything under it recursively?
rm -rf DIR
Danger
Even though this command does not work on significant system directories (like
/
) it is very recursively destructive and should almost never be used. Usermdir
instead. -
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
Note
This creates new files with new creation dates/times and ownership if copying from another user. Use other
cp
argument options when preserving them is important.