Dit deel is nog niet vertaald. Je ziet de Engelse tekst.
$ als gewone gebruiker# als root (of met sudo)
Vaardigheden in dit hoofdstuk
- Bestanden en mappen kopiëren, verplaatsen, linken en verwijderen
Create files and folders
mkdir makes folders, touch makes empty files (or updates the time of an existing file).
mkdir reports
mkdir -p projects/web/{html,logs,backup}
mkdir -m 750 private
touch notes.txt
touch -d "2026-01-01 08:00" old.log
ls -l old.log
-rw-r--r--. 1 student student 0 Jan 1 2026 old.logmkdir -pmakes all missing parent folders and gives no error if the folder exists — good in scripts.mkdir -m 750sets the rights at once.
Copy files and folders
cp SOURCE TARGET copies. For folders you need -r. Use -a to keep owner, rights and dates.
cp /etc/hosts ~/hosts.bak
cp file1 file2 file3 /tmp/
cp -a /etc/ssh /root/ssh-backup-$(date +%F)
cp -r projects /tmp/
cp -i notes.txt /tmp/
cp: overwrite '/tmp/notes.txt'? n
cp -v *.conf /backup/
cp -u *.html /var/www/html/| Option | What it does |
|---|---|
-r | Copy folders with everything inside |
-a | Archive: like -r, and keep rights, owner, dates, links, SELinux context |
-i | Ask before you overwrite |
-v | Show each file |
-u | Copy only when the source is newer |
-p | Keep rights, owner and dates (for files) |
Op het werk
Before you edit a config file, copy it: cp -a /etc/ssh/sshd_config{,.orig}. The braces make /etc/ssh/sshd_config /etc/ssh/sshd_config.orig.
Move and rename
mv moves a file to another folder or gives it a new name. There is no separate rename command.
mv notes.txt notes-2026.txt
mv notes-2026.txt ~/Documents/
mv *.log /var/tmp/oldlogs/
mv -i report.pdf /srv/share/
mv -n data.csv archive/
mv projects/web projects/website-iasks before it overwrites,-nnever overwrites.- Moving inside the same file system is fast (only the name changes). Moving to another disk copies the data and then deletes the source.
Delete files and folders
rm deletes files, rm -r deletes folders with all content, rmdir deletes only empty folders. There is no recycle bin on the command line.
| Option | What it does |
|---|---|
-i | Ask for every file |
-I | Ask once when you delete more than 3 files or go into folders |
-r | Delete folders and everything inside |
-f | Force: no questions, no error when a file is missing |
-- | End of options: the next word is a file name, even if it starts with - |
Let op
rm -rf with a variable is dangerous: if $DIR is empty, rm -rf $DIR/* becomes rm -rf /*. In scripts write rm -rf "${DIR:?}"/* — Bash stops when the variable is empty.
Onthoud
Deleted = gone. Copy important data to a backup before big clean-ups.
Make hard links and soft links
A link is a second name for a file. A soft link (symbolic link) points to a path. A hard link is a second name for the same data on the disk.
ln -s /var/log/httpd weblogs
ls -l weblogs
lrwxrwxrwx. 1 student student 14 Oct 27 10:02 weblogs -> /var/log/httpd
ln report.txt report-copy.txt
ls -li report*.txt
1835015 -rw-r--r--. 2 student student 512 Oct 27 10:03 report-copy.txt
1835015 -rw-r--r--. 2 student student 512 Oct 27 10:03 report.txtSoft link (ln -s) | Hard link (ln) | |
|---|---|---|
| Points to | A path (name) | The same inode (data) |
| Works for folders | Yes | No |
| Works across disks | Yes | No, only on the same file system |
| Original deleted | The link breaks ("dangling") | Data stays until the last name is gone |
Seen in ls -l | l type and -> | Link count higher than 1 |
Examentip
The order is always ln -s TARGET LINKNAME — the real thing first, like cp.
Find files
find searches the folder tree by name, size, owner, time or type, and can run a command on every hit.
find /etc -name "*.repo"
find / -user anna 2> /dev/null
find /var/log -type f -size +100M
find ~ -mtime -1
find /tmp -type f -mtime +30 -delete
find /srv -type f -name "*.sh" -exec chmod 750 {} \;
locate sshd_config| Test | Finds |
|---|---|
-name "*.conf" / -iname | By name (with -iname big and small letters are the same) |
-type f / -type d / -type l | Files / folders / links |
-size +100M | Bigger than 100 MiB (- = smaller) |
-user anna / -group sales | By owner / group |
-mtime -1 / -mtime +30 | Changed in the last day / more than 30 days ago |
-perm -4000 | With the SUID right |
-exec CMD {} \; | Run CMD on every hit ({} = the file) |
More options: the RHCSA lesson about find.
Look at file details
stat shows everything about a file: size, rights, owner, inode and the three times. file says what kind of data is inside.
stat /etc/hosts
File: /etc/hosts
Size: 158 Blocks: 8 IO Block: 4096 regular file
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Modify: 2026-10-20 10:12:04.000000000 +0300
file /usr/bin/passwd backup.tar.gz
/usr/bin/passwd: setuid ELF 64-bit LSB pie executable, x86-64
backup.tar.gz: gzip compressed data
du -sh ~/Downloads
1.2G /home/student/Downloads