Learn / Linux / Getting Started
Lesson 5 of 74

Creating, Copying, Moving & Deleting

The everyday file commands in depth. mkdir and brace expansion, touch and timestamps, cp with its important options, mv for moving and renaming, rm and rmdir, and wildcards, with the safety habits that stop you deleting the wrong thing.

25 min read Report a problem Hands-on lab included 6-question quiz

Six commands you'll use every day

CommandShort forJob
mkdirmake directorycreate folders
touchcreate empty files, or update a file's timestamp
cpcopycopy files and folders
mvmovemove and rename
rmremovedelete files (and folders with -r)
rmdirremove directorydelete empty folders

Two facts shape how you use them:

  1. There is no recycle bin. rm deletes for good. cp and mv overwrite existing files without asking. Nothing here can be undone.
  2. Silence means success. These commands print nothing when they work. Add -v (verbose) to see what they did, and check afterwards with ls.

Creating folders: mkdir

text
mkdir reports                 # one folder, in the current directory
mkdir reports invoices logs   # several at once
mkdir /srv/data               # anywhere, with an absolute path

-p: parents, and no complaints

mkdir only creates the last folder in a path. If a parent is missing, it fails:

text
$ mkdir /root/app/src
mkdir: cannot create directory '/root/app/src': No such file or directory

-p creates every missing parent, and also stays quiet if the folder already exists. That second part makes it safe in scripts that might run twice:

bash
mkdir -pv /root/app/{src,config,logs}
PartMeaning
-pcreate parents as needed, no error if it exists
-vverbose: print each folder created
/root/app/{src,config,logs}brace expansion (explained next): three paths in one
text
mkdir: created directory '/root/app'
mkdir: created directory '/root/app/src'
mkdir: created directory '/root/app/config'
mkdir: created directory '/root/app/logs'

/root/app didn't exist, so -p created it first, then the three folders inside.

Brace expansion: one word becomes many

Before running a command, the shell expands {a,b,c} into several words. echo shows what the shell produces:

bash
echo app-{dev,staging,prod}.conf
text
app-dev.conf app-staging.conf app-prod.conf

One word turned into three. The command never sees the braces, only the result.

It also does ranges: echo log-{1..5}.txt gives log-1.txt log-2.txt ... log-5.txt. That's how people create a whole project skeleton in one line:

text
mkdir -p myapp/{src,tests,docs,config/{dev,prod}}

Creating files and timestamps: touch

touch has two jobs:

  • If the file doesn't exist, it creates it, empty.
  • If it exists, it leaves the contents alone and sets its "last modified" time to now.
bash
touch /root/app/config/app-{dev,staging,prod}.conf
touch -d "2026-01-15 10:00" /root/app/config/app-dev.conf
ls -l /root/app/config
CommandWhat it does
touch .../app-{dev,staging,prod}.confcreates three empty files
touch -d "2026-01-15 10:00" ...sets a specific date instead of now
text
total 0
-rw-r--r-- 1 root root 0 Jan 15  2026 app-dev.conf
-rw-r--r-- 1 root root 0 Nov 24 15:17 app-prod.conf
-rw-r--r-- 1 root root 0 Nov 24 15:17 app-staging.conf

All three are 0 bytes (empty). app-dev.conf now shows January 15 because of -d. Setting timestamps is mostly useful for testing scripts that clean up "files older than 30 days".

Other ways to create a file with content: echo "port=8080" > app.conf writes one line (and replaces anything already in the file), and opening a new file in nano or vim creates it when you save. Redirection (>) gets its own lesson soon.

Try it · Task 1 of 4

Create folders and files

Build the folder structure for the new shop project.

1 · See how it's done Read this, then run the commands in your terminal (or press ▶ Run)

Every project on a server starts as a set of folders: one for the code, one for configuration, one for logs. Creating them by hand, consistently, is the first thing you'll do when setting up a new service. mkdir creates folders and touch creates empty files you'll fill in later.

1. Create a folder

bash
mkdir /root/shop-project
ls -ld /root/shop-project
PartMeaning
mkdirmake a directory
/root/shop-projectits path (here absolute, but relative paths work too)
ls -ldlist the folder itself (-d) in long format (-l), instead of listing what's inside it
text
drwxr-xr-x 2 root root 4096 Nov 24 15:00 /root/shop-project

The d at the start confirms it's a directory. 4096 is the space a directory entry takes on disk, not the size of its contents.

2. Nested folders: the -p option

Try to create a folder two levels deep:

bash
mkdir /root/shop-project/src/utils
text
mkdir: cannot create directory '/root/shop-project/src/utils': No such file or directory

mkdir refuses, because the parent src doesn't exist yet. It only creates the last folder in the path.

bash
mkdir -p /root/shop-project/src/utils
tree /root/shop-project

What -p does: creates every missing parent along the way. It also stays quiet if the folder already exists, which makes it safe to use in scripts that may run twice.

text
/root/shop-project
└── src
    └── utils

3 directories, 0 files

3. Several at once

You can give mkdir and touch several names in one command, separated by spaces:

bash
cd /root/shop-project
mkdir config logs docs
touch README.md src/app.py config/app.conf
tree
CommandWhat it does
mkdir config logs docscreates three folders in the current directory
touch README.md src/app.py config/app.confcreates three empty files. The paths are relative, so src/app.py lands in /root/shop-project/src/.
treewith no path, draws the current directory
text
.
├── README.md
├── config
│   └── app.conf
├── docs
├── logs
└── src
    ├── app.py
    └── utils

6 directories, 3 files

The . at the top means "the current directory", which is /root/shop-project.

touch on a file that already exists doesn't empty it. It only updates its "last modified" time to now. That's its original job, and creating empty files is a handy side effect.

2 · Your task

Build this structure in /root/shop-project (you may already have part of it):

text
/root/shop-project
├── README.md
├── config
│   └── app.conf
├── docs
├── logs
└── src
    ├── app.py
    └── utils

Expected result: tree /root/shop-project shows 6 directories, 3 files.

Hint: the commands, explained
text
mkdir -p /root/shop-project/src/utils /root/shop-project/config /root/shop-project/logs /root/shop-project/docs
cd /root/shop-project && touch README.md src/app.py config/app.conf

What each part does

  • mkdir -p A B C D: create all four folders in one command; -p also creates missing parents (like src for src/utils) and doesn't complain if a folder exists.
  • cd /root/shop-project && touch ...: go into the project, then (only if cd worked, that's what && means) create three empty files with relative paths.
First start the lab machine in the terminal panel on the right.

Copying: cp

cp always takes the source first and the destination last:

text
cp SOURCE DESTINATION
What you writeWhat happens
cp app.conf app.conf.bakcopy to a new name in the same folder
cp app.conf /tmp/copy into a folder, keeping the name
cp a.conf b.conf c.conf /tmp/several sources: the last argument must be a folder
cp *.conf /tmp/everything matching a wildcard, into a folder

cp versus mv

cp app.conf /backup/a second, independent file is created
app.confstill here
copy
/backup/app.confnew copy
mv app.conf /backup/the same file changes place
app.confgone from here
move
/backup/app.confnow lives here

Backing up before editing

The single most important habit when touching a config file on a server:

text
cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf.bak

If your change breaks something, cp nginx.conf.bak nginx.conf puts things back in seconds. Many engineers add the date: nginx.conf.2026-11-24.

Copying folders: -r

bash
cp /root/app /root/app-backup
text
cp: -r not specified; omitting directory '/root/app'

By default cp copies files only, and it even tells you the fix.

bash
cp -r /root/app /root/app-backup
ls /root/app-backup

What -r does: recursive: copy the folder, everything in it, and everything in its subfolders.

text
config
logs
src

app-backup was created as a copy of app.

Running the same cp -r twice. The first time, /root/app-backup doesn't exist, so cp creates it as a copy. The second time it does exist, so cp copies app into it, and you get /root/app-backup/app/:

text
$ cp -r /root/app /root/app-backup && ls /root/app-backup
app
config
logs
src

The meaning of the destination changes depending on whether it already exists. Check with ls before and after copying folders.

-a: an exact copy, for backups

A plain copy is a new file: it gets the current time as its timestamp, and if you're not root, you become its owner. For backups you usually want an exact replica. That's -a (archive): recursive, and it preserves permissions, owner, group and timestamps.

bash
cd /root/app/config
cp app-dev.conf /tmp/copy-plain.conf
cp -a app-dev.conf /tmp/copy-archive.conf
ls -l app-dev.conf /tmp/copy-plain.conf /tmp/copy-archive.conf
text
-rw-r--r-- 1 root root 0 Jan 15  2026 /tmp/copy-archive.conf
-rw-r--r-- 1 root root 0 Nov 24 15:17 /tmp/copy-plain.conf
-rw-r--r-- 1 root root 0 Jan 15  2026 app-dev.conf

The original is dated January 15. The plain copy says today; the -a copy kept January 15. For backups, logs and anything where "when was this last changed?" matters, use -a.

The cp options worth knowing

OptionEffect
-rcopy folders recursively
-aarchive: recursive + keep permissions, owner, timestamps, links
-iinteractive: ask before overwriting an existing file
-nno clobber: never overwrite
-uupdate: copy only if the source is newer than the destination
-vverbose: show each file copied

With -v, you can watch a wildcard copy:

bash
cp -v /root/app/config/*.conf /tmp/
text
'/root/app/config/app-dev.conf' -> '/tmp/app-dev.conf'
'/root/app/config/app-prod.conf' -> '/tmp/app-prod.conf'
'/root/app/config/app-staging.conf' -> '/tmp/app-staging.conf'

Each line reads source -> destination.

With -i, cp stops and asks cp: overwrite '/tmp/plain.conf'? Type y and Enter to overwrite, anything else to skip.

Try it · Task 2 of 4

Copy and back up

Back up the config file and the whole config folder before anyone edits them.

1 · See how it's done Read this, then run the commands in your terminal (or press ▶ Run)

Rule number one before editing any config file on a server: make a copy first. If your change breaks something, you can put the original back in seconds. The usual habit is to copy app.conf to app.conf.bak (or add a date, like app.conf.2026-11-24) right next to it.

cp always takes the source first and the destination second: cp FROM TO.

First, give the config file some content so the copy has something in it:

bash
printf 'port=8080\ndebug=false\n' > /root/shop-project/config/app.conf
cat /root/shop-project/config/app.conf

1. Copy a file

bash
cd /root/shop-project
cp config/app.conf config/app.conf.bak
ls -l config
PartMeaning
cpcopy
config/app.confthe source: the file to copy
config/app.conf.bakthe destination: the new file's name
text
total 8
-rw-r--r-- 1 root root 22 Nov 24 15:00 app.conf
-rw-r--r-- 1 root root 22 Nov 24 15:00 app.conf.bak

Two files of the same size (22 bytes): an identical copy. Now you can edit app.conf safely, and undo with cp config/app.conf.bak config/app.conf.

2. Copy into a folder

If the destination is an existing folder, cp puts the copy inside it and keeps the name. Add -v to see what happens:

bash
cp -v config/app.conf /tmp/

What -v does: verbose. The command prints each file it copies, as source -> destination.

text
'config/app.conf' -> '/tmp/app.conf'

3. Copy a whole folder: -r

bash
cp /root/shop-project/config /root/backups
text
cp: -r not specified; omitting directory '/root/shop-project/config'

By default cp only copies files. It skipped the folder and even tells you the fix.

bash
mkdir -p /root/backups
cp -r /root/shop-project/config /root/backups/config
tree /root/backups

What -r does: recursive. It copies the folder, everything inside it, and everything inside those, all the way down.

text
/root/backups
└── config
    ├── app.conf
    └── app.conf.bak

2 directories, 2 files

The whole folder and its two files were copied.

cp overwrites silently. If the destination file exists, it's replaced without asking. Use cp -i (interactive) to be asked first, or cp -n to never overwrite. To also keep the original owner, permissions and timestamps (important for backups), use cp -a (archive), which includes -r.

2 · Your task
  1. Back up /root/shop-project/config/app.conf as app.conf.bak in the same folder.
  2. Copy the whole /root/shop-project/config folder to /root/backups/config.

Expected result: ls /root/shop-project/config shows app.conf and app.conf.bak, and tree /root/backups shows the copied config folder.

Hint: the commands, explained
text
cp /root/shop-project/config/app.conf /root/shop-project/config/app.conf.bak
mkdir -p /root/backups
cp -r /root/shop-project/config /root/backups/config

What each part does

  • cp SOURCE DEST: copy one file under a new name (.bak = backup).
  • mkdir -p /root/backups: make sure the destination folder exists.
  • cp -r SOURCE DEST: copy a whole folder and everything in it (recursive). Without -r, cp refuses to copy folders.
First start the lab machine in the terminal panel on the right.

Moving and renaming: mv

There is no separate "rename" command on Linux. Renaming is moving a file to a new name. mv works on files and folders alike, and needs no -r:

What you writeWhat happens
mv old.conf new.confrename, in the same folder
mv app.conf /etc/myapp/move into a folder, same name
mv app.conf /etc/myapp/main.confmove and rename in one go
mv a.log b.log c.log archive/several sources into a folder
mv project project-oldrename a whole folder
bash
mv -v /root/app/config/app-dev.conf /root/app/config/app-development.conf
text
renamed '/root/app/config/app-dev.conf' -> '/root/app/config/app-development.conf'

mv calls it "renamed" even when you move to another folder: on the same disk, moving a file just changes its name and location in the directory tree. The data itself isn't copied, which is why moving a 50 GB file within one disk is instant.

Like cp, mv overwrites silently. mv -i asks first, mv -n never overwrites.

Try it · Task 3 of 4

Move and rename

Collect all log files into one folder and give the release notes a clean name.

1 · See how it's done Read this, then run the commands in your terminal (or press ▶ Run)

Linux has no separate "rename" command. Renaming is moving: mv old-name new-name moves the file to a new name in the same folder. And mv file folder/ moves it into another folder, keeping its name. Unlike cp, mv leaves nothing behind.

You'll also meet the most useful shortcut in the shell: the wildcard *, which means "any characters". *.log matches every name that ends in .log.

Go to the messy downloads folder and look around:

bash
cd /root/downloads
ls -l
text
total 40
-rw-r--r-- 1 root root   26 Nov 24 15:00 Release Notes.txt
-rw-r--r-- 1 root root   20 Nov 24 15:00 app-2026-11-01.log
-rw-r--r-- 1 root root   24 Nov 24 15:00 app-2026-11-02.log
-rw-r--r-- 1 root root  512 Nov 24 15:00 cache1.tmp
-rw-r--r-- 1 root root  512 Nov 24 15:00 cache2.tmp
-rw-r--r-- 1 root root  512 Nov 24 15:00 cache3.tmp
-rw-r--r-- 1 root root   28 Nov 24 15:00 error.log
-rw-r--r-- 1 root root   16 Nov 24 15:00 important.txt
-rw-r--r-- 1 root root 4096 Nov 24 15:00 invoice-1042.pdf
drwxr-xr-x 2 root root 4096 Nov 24 15:00 old-stuff

Three log files, three temporary files, a file name with a space in it, two files to keep and an empty folder.

1. Rename a file

bash
mv error.log errors.log
ls
PartMeaning
mvmove
error.logthe source: what to move
errors.logthe destination: here, just a new name in the same folder
text
Release Notes.txt   app-2026-11-02.log  cache2.tmp  errors.log     invoice-1042.pdf
app-2026-11-01.log  cache1.tmp          cache3.tmp  important.txt  old-stuff

error.log is gone and errors.log is there. Same file, new name.

2. Move many files with a wildcard

bash
mkdir logs
ls *.log
mv *.log logs/
ls logs
PartMeaning
*.logevery name in this folder that ends in .log
ls *.logpreview which files the wildcard matches, before doing anything
mv *.log logs/move all of them into the logs folder. The trailing / makes it clear logs is a folder.
text
app-2026-11-01.log  app-2026-11-02.log  errors.log
app-2026-11-01.log  app-2026-11-02.log  errors.log

The first line is the preview, the second is what's now inside logs/. One command moved all three.

How it works: the shell replaces *.log with the matching names before running mv. So mv actually receives mv app-2026-11-01.log app-2026-11-02.log errors.log logs/. That's why previewing with ls (or echo *.log) shows exactly what will happen.

3. Names with spaces need quotes

bash
mv Release Notes.txt release-notes.txt
text
mv: target 'release-notes.txt': No such file or directory

The shell splits commands at spaces, so mv received three names: Release, Notes.txt and release-notes.txt. With more than two names, mv thinks the last one must be a folder to move the others into, and there's no such folder.

Put the name in quotes so the shell treats it as one argument:

bash
mv "Release Notes.txt" release-notes.txt
ls

You could also escape the space with a backslash: mv Release\ Notes.txt release-notes.txt. Tab completion adds the backslash for you.

text
cache1.tmp  cache2.tmp  cache3.tmp  important.txt  invoice-1042.pdf  logs  old-stuff  release-notes.txt

This is why people avoid spaces in file names on servers and in projects: use - or _ instead (release-notes.txt). And like cp, mv overwrites silently if the destination exists. Use mv -i to be asked first.

2 · Your task

In /root/downloads:

  1. Move all .log files into a folder called logs (inside /root/downloads).
  2. Rename Release Notes.txt to release-notes.txt.

Expected result: ls /root/downloads/logs shows three log files, no .log file is left directly in /root/downloads, and release-notes.txt exists.

Hint: the commands, explained
text
cd /root/downloads
mkdir -p logs
mv *.log logs/
mv "Release Notes.txt" release-notes.txt

What each part does

  • mv *.log logs/: *.log matches every file ending in .log; mv moves them all into logs/.
  • mv "Release Notes.txt" release-notes.txt: rename a file. The quotes are needed because the name contains a space; otherwise the shell would see two words.
First start the lab machine in the terminal panel on the right.

Deleting: rm and rmdir

bash
rm -v /tmp/plain.conf
text
removed '/tmp/plain.conf'

rm refuses to delete folders on its own:

text
$ rm /root/app-backup
rm: cannot remove '/root/app-backup': Is a directory

There are two ways to delete folders:

CommandDeletesSafety
rmdir folderthe folder, only if it's emptysafe: it refuses if anything is inside
rm -r folderthe folder and everything in it, all the way downno questions asked
bash
rm -rv /root/app-backup
text
removed directory '/root/app-backup/src'
removed '/root/app-backup/config/app-staging.conf'
removed '/root/app-backup/config/app-prod.conf'
removed '/root/app-backup/config/app-dev.conf'
removed directory '/root/app-backup/config'
...
removed directory '/root/app-backup'

rm -r works from the inside out: first the files, then each emptied folder, and finally the top folder itself.

The rm options and what they really mean

OptionEffect
-rrecursive: delete folders and their contents
-iask before every file
-Iask once if deleting more than 3 files or recursively. A good compromise.
-fforce: never ask, and don't complain about missing files
-vshow each file deleted

-f changes two things. It silences prompts, and it hides errors about files that don't exist:

text
$ rm /tmp/nope.txt
rm: cannot remove '/tmp/nope.txt': No such file or directory

$ rm -f /tmp/nope.txt; echo "exit code $?"
exit code 0

That's why scripts use rm -f for clean-up steps: "delete it if it's there" without failing. It's also why rm -rf is the most dangerous command on Linux: recursive, no questions, no errors, no undo.

A classic production disaster: a script runs rm -rf $BUILD_DIR/* and the variable is empty because of a typo, so the command becomes rm -rf /*. Protect yourself: use rm -rf "${BUILD_DIR:?}/"* in scripts (it refuses to run if the variable is empty), always run pwd before deleting with relative paths, and never type rm -rf on autopilot.

Wildcards (globbing)

Wildcards let one pattern match many names. The shell expands them into the list of matching names before the command runs, so the command never sees the *.

PatternMatchesExampleMatches
*any characters, any number (even none)*.confapp.conf, nginx.conf (but not hidden files, see below)
?exactly one characterapp-???.confapp-dev.conf, not app-prod.conf
[abc]one character from the list[ap]*.confnames starting with a or p
[0-9]one character from a rangelog-[0-9].txtlog-1.txt … log-9.txt
[!abc]one character not in the list[!a]*names not starting with a
bash
cd /root/app/config
ls app-???.conf app-????.conf
text
app-dev.conf
app-prod.conf

??? matched the three letters of dev, ???? the four of prod. staging has seven letters, so neither pattern matched it.

Two surprises

1. * skips hidden files. Names starting with a dot are not matched unless the pattern itself starts with a dot:

bash
cd /root/app
echo *
echo .* *
text
config logs src visible.txt
.hidden config logs src visible.txt

So rm * in a folder leaves .env and other dotfiles behind, and cp * backup/ doesn't copy them either. Use cp -a folder/. backup/ to copy a folder's full contents, hidden files included.

2. When nothing matches, the pattern stays as it is:

text
$ ls *.yaml
ls: cannot access '*.yaml': No such file or directory

The shell found no .yaml files, so it passed the literal text *.yaml to ls, which then looked for a file with that strange name.

Preview first, always

Because the shell expands the pattern first, you can see exactly what a command will touch by running the same pattern with ls or echo:

text
ls /var/log/app/*.log.old      # 1. preview: read the list
rm /var/log/app/*.log.old      # 2. press ↑, change ls to rm, run

This two-step habit costs two seconds and prevents most deletion accidents.

Try it · Task 4 of 4

Delete safely with wildcards

Remove the temporary files and the empty folder, and keep everything else.

1 · See how it's done Read this, then run the commands in your terminal (or press ▶ Run)

rm deletes for good: no recycle bin, no undo. Experienced engineers follow one simple routine whenever they delete with a wildcard:

  1. Preview with ls using exactly the same pattern.
  2. Read the list. Is everything on it safe to delete? Is anything missing?
  3. Only then press ↑, replace ls with rm, and run it.

Wildcards are powerful in both directions: rm *.tmp deletes three files, and a stray space in rm * .tmp deletes everything in the folder.

1. The wildcards

PatternMatchesExample
*any characters, any number of them (even none)*.tmp → cache1.tmp, cache22.tmp
?exactly one charactercache?.tmp → cache1.tmp but not cache22.tmp
[abc]one character from the listcache[12].tmp → cache1.tmp, cache2.tmp

2. Preview first

bash
cd /root/downloads
ls *.tmp
text
cache1.tmp  cache2.tmp  cache3.tmp

Exactly the three temporary files, nothing else. Safe to delete.

3. Delete files

bash
rm -v *.tmp
PartMeaning
rmremove (delete) files
-vverbose: print each file as it's deleted
*.tmpevery name ending in .tmp
text
removed 'cache1.tmp'
removed 'cache2.tmp'
removed 'cache3.tmp'

4. Delete folders

bash
rm old-stuff
text
rm: cannot remove 'old-stuff': Is a directory

rm refuses to delete folders on its own. There are two ways:

CommandDeletesSafety
rmdir old-stuffthe folder only if it's emptysafe: it refuses if anything is inside
rm -r old-stuffthe folder and everything in itdangerous: no questions asked
bash
rmdir old-stuff
ls
text
important.txt  invoice-1042.pdf  logs  release-notes.txt

Only the files worth keeping are left.

rm -i asks "remove ...?" for every file, which is good when you're unsure. rm -rf (recursive + force, never ask, ignore errors) is the command behind many famous outages: always pwd and preview with ls before using it, and never run it with a variable or path you haven't double-checked.

2 · Your task

In /root/downloads, delete all .tmp files and the empty old-stuff folder. Keep everything else.

Expected result: ls /root/downloads shows only important.txt, invoice-1042.pdf, logs and release-notes.txt.

Hint: the commands, explained
text
cd /root/downloads
ls *.tmp
rm *.tmp
rmdir old-stuff

What each part does

  • ls *.tmp: check first which files the pattern matches.
  • rm *.tmp: delete them. There is no undo and no recycle bin on Linux.
  • rmdir old-stuff: delete a folder, but only if it's empty, which makes it a safe way to remove folders.
First start the lab machine in the terminal panel on the right.

File names: the rules

  • Case matters: Report.txt and report.txt are two different files.
  • Names can contain almost anything except /, but avoid spaces and special characters (*, ?, &, $, quotes). They work, but every command then needs quotes: rm "my file.txt".
  • Use lowercase, - and _: release-notes.txt, backup_2026-11-24.tar.gz.
  • Extensions like .txt are just part of the name. Linux decides what a file is from its contents (file command), not its extension.
  • A leading . makes a file hidden.

"How do you copy a directory and keep permissions and timestamps?" cp -a source destination. -r alone copies recursively but doesn't preserve everything.

"How do you rename a file?" mv old new. There's no separate rename command (some distros have a rename tool for bulk renaming with patterns).

"What's the difference between rm -r and rmdir?" rmdir deletes only empty directories; rm -r deletes a directory and everything inside it.

"Why is rm -rf dangerous?" It deletes recursively, never asks, ignores errors, and Linux has no recycle bin. Combined with an empty variable or a wrong current directory, it can wipe a server.

Summary

  • mkdir -p creates nested folders safely; {a,b} brace expansion creates many names at once.
  • touch creates empty files or updates timestamps (-d for a specific date).
  • cp SOURCE DEST: -r for folders, -a for exact backups, -i/-n to avoid overwriting. Back up configs before editing.
  • mv moves and renames, files and folders alike, and overwrites silently unless you use -i.
  • rm is permanent. rmdir only removes empty folders; rm -r removes everything inside; -f never asks.
  • Wildcards *, ?, [...] are expanded by the shell, skip hidden files, and should always be previewed with ls before rm.
Check your understanding

Quick quiz

Feedback