— Marc Verhaar 2021/11/02 19:08
====== Uitreksel RHCSA 8 ======
| Command | Function | Example |
|---|---|---|
| cp | Copy file | cp file1 file2 |
| rm | Remove file | rm file2 |
| mv | Move file (also rename!) | mv file /path/newfile |
| mkdir | Make directory | mkdir newdir |
| rmdir | Remove directory (must be empty!) | rm newdir |
| rm -rf | Remove file or directory | rm -rf /bin |
| chgrp | Change group of file or directory | '' sudo chgrp root file 1'' |
| chown | Change ownership of file or directory | chown user file |
chown user:group file |
||
chown -R user: dir |
| Command | Function | Example |
|---|---|---|
| ln | create a hardlink | ln target linkname |
| ln -s | create a soft link | ln -s target linkname |
| ls -i | show files with inode numbers | ls -li |
''''
touch original
echo “some stuff” > original
ln -s original softlink
ln original hardlink
ls -li
46271969 -rw-rw-r– 2 marcv marcv 24 Nov 2 20:54 hardlink
46271969 -rw-rw-r– 2 marcv marcv 24 Nov 2 20:54 original
46271970 lrwxrwxrwx 1 marcv marcv 8 Nov 2 20:54 softlink → original
rm original
ls -l
-rw-rw-r– 1 marcv marcv 24 Nov 2 20:43 hardlink
lrwxrwxrwx 1 marcv marcv 8 Nov 2 20:44 softlink → original (broken link)
''''
There are 3 redirects in Linux:
We can redirect these output using >, <, and 2>:
| Command | Redirects |
|---|---|
ls -l > output | output to “output” (not overrides output to stdout which is terminal) |
ls -l » output | same but appends to existing content instead of overwriting |
| '' cat < file'' | redirect content of file to cat (quite useless as cat file will do the same) |
mail user@here.nl < content | using mailprogram, send content |
ls -l /root 2> errorfile | redirect errors to errorfile (valid output to stdout) |
sql=$(cat <<EOF SELECT foo, bar FROM db WHERE foo='baz' EOF )
The $sql variable now holds the new-line characters too. You can verify with echo -e “$sql”
cat <<EOF > print.sh #!/bin/bash echo \$PWD echo $PWD EOF
The double “«” is necessary! It does not matter if you use EOF, eof or any other string for closing
The print.sh file now contains:
#!/bin/bash echo $PWD echo /home/user
cat <<EOF | grep 'b' | tee b.txt foo bar baz EOF
The b.txt file contains bar and baz lines. The same output is printed to stdout.
| command | what it does |
|---|---|
ls -ltr | less | feed less with output of ls -ltr |
find . *file | grep name | find files and grep in filenames(!) |
cat file* | grep string | cat files and grep inside content(!) This can also be done using grep -R string ./* |
For RHCSA you'll be using vi because it's present on almost all *nix systems.
Common keys in command mode:
Some examples:
| Command | What it does |
|---|---|
| useradd -d /homedir -g group username | add user, assign to group and define homedir |
| usermod -a -G wheel user | add user to additional group wheel |
| useradd -r nonuser | create system account |
| useradd -s /bin/zsh user | create user and define shell |
| chage -m 5 user | user can change password in 5 days |
| chage -M 90 -W 70 user | user must change password every 90 days and gets warning 7 days prior |
| chage -I 7 user | account will be disabled 7 days after password expires |
Log directory is /var/log/ (unless specified other per application)
Accurate system time is critical!
RedHat 8 uses NTP for time synchronization.
dmesg)Become root using:
su -
The minus ensures that correct environment (variables) is loaded so don't use su without it.
If configured properly (sudo is installed and user is member of group wheel), you can also do:
sudo su -
env | less will show you all environment variablesalias upgrade='sudo apt update && sudo apt upgrade -y'-rw-r--r-- 1 root root 237884 okt 15 19:56 config-5.4.0-90-generic -rw-r--r-- 1 root root 237884 nov 5 17:02 config-5.4.0-91-generic drwx------ 2 root root 4096 jan 1 1970 efi drwxr-xr-x 4 root root 4096 dec 1 13:46 grub lrwxrwxrwx 1 root root 27 nov 30 06:55 initrd.img -> initrd.img-5.4.0-91-generic -rw-r--r-- 1 root root 52057331 nov 23 08:05 initrd.img-5.4.0-90-generic -rw-r--r-- 1 root root 52057689 nov 30 06:56 initrd.img-5.4.0-91-generic lrwxrwxrwx 1 root root 27 nov 30 06:55 initrd.img.old -> initrd.img-5.4.0-90-generic -rw-r--r-- 1 root root 182704 aug 18 2020 memtest86+.bin -rw-r--r-- 1 root root 184380 aug 18 2020 memtest86+.elf -rw-r--r-- 1 root root 184884 aug 18 2020 memtest86+_multiboot.bin -rw------- 1 root root 4755119 okt 15 19:56 System.map-5.4.0-90-generic -rw------- 1 root root 4755132 nov 5 17:02 System.map-5.4.0-91-generic lrwxrwxrwx 1 root root 24 nov 30 06:55 vmlinuz -> vmlinuz-5.4.0-91-generic (KERNEL) -rw------- 1 root root 11780352 okt 15 21:36 vmlinuz-5.4.0-90-generic (KERNEL) -rw------- 1 root root 11784448 nov 5 17:04 vmlinuz-5.4.0-91-generic (KERNEL) lrwxrwxrwx 1 root root 24 nov 30 06:55 vmlinuz.old -> vmlinuz-5.4.0-90-generic (KERNEL)
man hier for more info!01-02-6