Dit deel is nog niet vertaald. Je ziet de Engelse tekst.
$ als gewone gebruiker# als root (of met sudo)
Vaardigheden in dit hoofdstuk
- Absolute en relatieve paden gebruiken
Know the main folders
Every RHEL system uses the same folder layout (the File-system Hierarchy Standard). Learn it once and you find things on every server.
| Folder | What is in it |
|---|---|
/ | The root of the tree. Everything starts here. |
/etc | System configuration files (text). Back up this folder! |
/home | The home folders of normal users (/home/anna) |
/root | The home folder of the user root |
/usr | Installed programs, libraries and docs. /usr/bin = commands, /usr/sbin = admin commands |
/var | Data that changes: logs (/var/log), web sites (/var/www), databases, mail, caches |
/tmp | Temporary files for everybody. Files older than 10 days are cleaned up. |
/run | Runtime data since the last boot (PID files, sockets). Empty after a reboot. |
/boot | The kernel, the initramfs and the boot loader files |
/dev | Device files: disks (/dev/vda, /dev/sda), terminals, /dev/null |
/proc, /sys | Virtual files made by the kernel: processes, hardware, kernel settings |
/opt | Extra software from other vendors |
/srv | Data served by this system (FTP, web), if you choose to put it here |
ls /
afs bin boot dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var
ls -ld /bin /sbin /lib
lrwxrwxrwx. 1 root root 7 Jun 24 2024 /bin -> usr/bin
lrwxrwxrwx. 1 root root 8 Jun 24 2024 /sbin -> usr/sbin
lrwxrwxrwx. 1 root root 7 Jun 24 2024 /lib -> usr/libOnthoud
/bin, /sbin and /lib are only links to folders in /usr. All programs live in /usr.
Op het werk
When a disk is full, look first in /var (logs, caches) and /home. du -sh /var/* | sort -h shows the biggest folders.
Use absolute and relative paths
An absolute path starts with / and works from anywhere. A relative path starts from the folder you are in now.
pwd
/home/student
ls /etc/ssh/sshd_config
ls Documents/report.txt
ls ./Documents/report.txt
ls ../anna
ls ~/Documents
ls ~anna| Sign | Meaning |
|---|---|
/ at the start | The root: an absolute path |
. | This folder |
.. | The folder above (the parent) |
~ | My home folder |
~anna | The home folder of the user anna |
Onthoud
In a script or a cron job, always use absolute paths. A script does not know which folder it starts in.
Move between folders
List the content of a folder
ls shows files. With options it shows sizes, owners, rights, hidden files and dates.
| Option | What it shows |
|---|---|
-l | Long list: type, rights, links, owner, group, size, date, name |
-a | Also hidden files (names that start with .) |
-h | Sizes like 4.0K, 12M (with -l) |
-t / -r | Sort by time / reverse the order |
-d | The folder itself, not what is inside |
-R | Go into sub-folders too |
-Z | The SELinux context |
-rw-r--r--. 1 root root 3667 Oct 20 10:12 sshd_config
drwxr-xr-x. 2 root root 4096 Oct 20 10:12 sshd_config.dThe first letter is the type: - file, d folder, l link. The rest is explained in Control access to files.
Use wildcards to pick many files
The shell turns wildcard patterns into a list of file names before the command runs (this is called globbing).
| Pattern | Matches |
|---|---|
* | Any text, also nothing |
? | Exactly one character |
[abc] / [0-9] | One of these characters / one digit |
[!0-9] | One character that is not a digit |
{a,b,c} | Makes several words (brace expansion), files do not need to exist |
ls /etc/*.conf
ls /var/log/messages-*
ls file?.txt
ls report[0-9][0-9].pdf
mkdir -p project/{src,docs,tests}
touch log{1..5}.txt
echo /etc/sys*Let op
rm * in the wrong folder deletes everything there. Run ls PATTERN first to see what it matches, then use the same pattern with rm.
Understand tilde, variables and command substitution
Before a command runs, the shell also replaces ~, $VARIABLE and $(command) with their values.
echo ~
/home/student
echo $HOME $USER
/home/student student
echo "Today is $(date +%A)"
Today is Monday
tar czf /tmp/etc-$(date +%F).tar.gz /etc
echo '$HOME is not changed in single quotes'
echo "\$HOME is not changed here either"| Quoting | Effect |
|---|---|
"double" | Keeps spaces together, but $VAR and $(cmd) still work |
'single' | Everything stays exactly as written |
\ | Protects the next character only |
More examples: Variables in the shell.