LinuxMemo
Cover the knowledge of RHCSA, and will be updated continuously. Given the fact CentOS is discontinued, use Alma Linux or Rocky Linux instead for practice.
19 flashcards · Computer Science · by claudehsu
How to fix below issue? [claude@localhost ~]$ man -k time time: nothing appropriate. sudo mandb
Tip: The command needs admin privilege.
If we know the command name, we can use `man <cmd_name>` to check the help manual. When we don't know the command name, but only know the keyword, we can use the `-k` option like `man -k time`. [claude@localhost ~]$ man -k time __ppc_get_timebase (3) - get the current value of the Time Base Register on Power architecture and its frequency. __ppc_get_timebase_freq (3) - get the current value of the Time Base Register on Power architecture and its frequency. ac (1) - print statistics about users'…
Tips: If we'd like to search against specific sections, we can do something like man -k time | grep -E '1|8' section 1: user commands(programs) section 8: system management commands
To check the help manual for globbing patterns, we do man glob However, the the command gives us the information of glob related C library. How to check the info of globbing? man 7 glob
ls ?ost one character placeholder ls [hm]ost match either letter 'h' or letter 'm' ls [!hm]ost match not 'host' or 'most' ls -d [!a-d]* directries not starting with 'a', 'b', 'c', or 'd'
Regarding IO redirection Standard in operator(override): < number: 0 Standard out operator(override): > number: 1 Standart error operator(override): 2> number: 2
Also think about the appending operator
As a regular user, when we do `find` against the root directory, we may encounter many permission error like [claude@localhost ~]$ find / -iname 'rpm' find: ‘/root’: Permission denied find: ‘/proc/tty/driver’: Permission denied find: ‘/proc/1/task/1/fd’: Permission denied ... In above case, how to simply ignore the error and only keep 'successful cases'? find / -iname 'rpm' 2> /dev/null
Sometimes we need to check the network port usage. How to check which process is using port 22? Tips We need to use `sudo` for permission reason
[claude@localhost ~]$ sudo netstat -ntpl | grep 22 [sudo] password for claude: tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1051/sshd: /usr/sbi tcp6 0 0 :::22 :::* LISTEN 1051/sshd: /usr/sbi Note `netstat` shows the network status `grep` helps us keeps port 22 related records
Indicate below paths contains administrative configuration files: /etc contains common linux user commands such as `ls`, `sort`, `data` and etc.: /bin directory to store add-on application software: /opt contains information about system resources: /proc contains administrative commands and daemon processes: /sbin contains temporary files used by applications: /tmp contains user documentations, games, graphical files(such as X11), libraries and variety of other commands and files that are NOT n…
If we need to set services like ftp, or web, which directory under the root directory is most likely to be used? /var If we need to check the log files, which directory under the root directory is most likely to be accessed? /var
How to check the size of a directory using command line? For example, if we'd like to know the size of `/var/log`, which command can we use?
The essential command is `du` to estimate the file space usage. With `-h` option, the size will be displayed in a human readable way. [claude@localhost ~]$ sudo du -h /var/log [sudo] password for claude: 12K /var/log/sssd 4.0K /var/log/gdm 4.0K /var/log/private 12K /var/log/tuned 4.0K /var/log/samba/old 8.0K /var/log/samba 936K /var/log/audit 4.0K /var/log/chrony 6.6M /var/log/anaconda 10M /var/log Proper permission is desired.
When removing a non-empty directory, we can use `rm -rf <dir_path>`. However, that command is dangerous, because we accidentally provide the wrong <dir_path>, we'll remove that directory unexpectedly. How can we prevent above issue?
We can use the `-i` or `-I` option of `rm`. `-I` is less intrusive than `-i`, because it only prompt once. The whole command is `rm -rfI <dir_path>`
Suppose we'd like to create a directory/sub-directory structure like `~/Temp/<Current_Date>`. Technically, we can do mkdir ~/Temp mkdir ~/Temp/`date +%Y%m%d` Tow steps seem a little verbose. How to create the directory structure with one command?
Use the `-p` operation of `mkdir` command. `mkdir -p <full_dir_path>`. The needed directories in the path will be created on the fly automatically. mkdir -p ~/Temp/`date +%Y%m%d`
To find a file, we can utilize `find` command. Q1: if I'd like to find the log file of vbox related log files, but I don't remember the full name of the file, how to do that? Q2: suppose we'd like to search all the conf files under `/etc` directory. If we do `sudo find /etc -iname '*conf'`, conf files under 'deeper' directories will also be matched, such as `/etc/lvm/lvmlocal.conf`. How to resolve the issue?
A1: we can use globbing to indicate the file name [claude@localhost ~]$ sudo find / -iname 'vbox*log' [sudo] password for claude: /var/log/vboxadd-uninstall.log /var/log/vboxadd-install.log /var/log/vboxadd-setup.log A2: use `-maxdepth` option of `find` to indicate we only go 1 directorty further, meaning we dont go into sub-directories [claude@localhost etc]$ sudo find /etc/ -maxdepth 1 -iname '*conf' /etc/yum.conf /etc/libuser.conf /etc/dconf /etc/krb5.conf /etc/xattr.conf /etc/sestatus.conf…
Q: In Linux desktop environment, `locate` is also commonly usd to find the desired items. The command utilizes an index database to do the search. If `locate` is never executed, or if it's newly installed, which command we may need to run to build the index database? A: sudo updatedb
Q: How to utilize `locate` to list all the conf files(file name ends with `conf`)? T: use regular expression A: locate -i --regex '.*conf$'
Given below shell snippet [lisa@rhelserver ~]$ touch Documents/readme [lisa@rhelserver ~]$ ls -il Documents/ total 0 2139868 -rw-rw-r--. 1 lisa lisa 0 Aug 27 12:58 readme [lisa@rhelserver ~]$ ln Documents/readme Documents/hello [lisa@rhelserver ~]$ ls -il Documents/ total 0 2139868 -rw-rw-r--. 2 lisa lisa 0 Aug 27 12:58 hello 2139868 -rw-rw-r--. 2 lisa lisa 0 Aug 27 12:58 readme [lisa@rhelserver ~]$ chmod u+x Documents/readme [lisa@rhelserver ~]$ ll Documents/ total 8 -rwxrw-r--. 2 lisa lisa 23…
`readme` and `hello` are actually tow hard links pointing to the same iNode, 2139868 in above case. The permission info is stored in the iNode, so changing permission via `readme` updates the info in iNode 2139868 and that can be reflected by hard link `hello`.
Given below shell snippet [lisa@rhelserver ~]$ ln /etc/passwd Documents/pass ln: failed to create hard link \u2018Documents/pass\u2019 => \u2018/etc/passwd\u2019: Operation not permitted why do we get an error showing the operation is not permitted?
The reason is to add a hard link requires to update the info stored in iNode, and therefore write permission is needed. In above case, user `lisa` does NOT have the write permission to the iNode that `/etc/passwd` points to, so the error happens.
Given below shell snippet [claude@thinbox ~]$ mkdir Temp [claude@thinbox ~]$ ls -lid Temp 402653318 drwxr-xr-x. 2 claude claude 6 Dec 17 18:28 Temp Why there are two hard links pointing to the iNode once we create a new directory?
Linux automatically create a `.` dot to point to the current directory. So to above `Temp` directory, there are two hard links `.` representing the current directory when in `Temp` `Temp` representing the `Temp` directory when in `~`
How to understand the symbolic link? Especially, what's the relationship between it and hard link?