Miscellaneous Operations in Linux
Table of Contents
recursive lookup#
To lookup a string or file name recursively in every file, directory and subdirectory starting at a current position, use grep -r. In the example, the command found instances of journald.conf in the file named a and in the .bash_history file:
user1@rhel10-vm2:~$ pwd
/home/user1
user1@rhel10-vm2:~$ ls -l
total 152
-rw-r--r--. 1 user1 user1 2470 Aug 21 19:40 a
-rw-r--r--. 1 user1 user1 150459 Aug 19 18:13 q
drwxr-xr-x. 2 user1 user1 6 Aug 21 19:49 test
user1@rhel10-vm2:~$
user1@rhel10-vm2:~$ grep -r journald.conf
.bash_history:ls /etc/systemd/journald.conf
.bash_history:find /etc -mindepth 1 -name "journald.conf" -type f 2>/dev/null
.bash_history:find / -mindepth 1 -name "journald.conf" -type f 2>/dev/null
.bash_history:ls /usr/lib/systemd/journald.conf
.bash_history:cat /usr/lib/systemd/journald.conf
.bash_history:find / -mindepth 1 -name "journald.conf" -type f 2>/dev/null
.bash_history:find / -maxdepth 4 -name "journald.conf" -type f 2>/dev/null
.bash_history:cat /usr/lib/systemd/journald.conf
.bash_history:systemd-analyze cat-config systemd/journald.conf
.bash_history:cat /run/lib/systemd/journald.conf
.bash_history:cat /usr/lib/systemd/journald.conf
a:# journald.conf/usr/lib/systemd/journald.conf
a:# the /etc/systemd/journald.conf.d/ directory. The latter is generally
a:# Use 'systemd-analyze cat-config systemd/journald.conf' to display the full config.
a:# See journald.conf(5) for details.
user1@rhel10-vm2:~$
To return only the first occurrence of the files which contain the search string, instead of returning the lines where the string appears, use grep -l:
user1@rhel10-vm2:~$ ls -l
total 152
-rw-r--r--. 1 user1 user1 2470 Aug 21 19:40 a
-rw-r--r--. 1 user1 user1 150459 Aug 19 18:13 q
drwxr-xr-x. 2 user1 user1 6 Aug 21 19:49 test
user1@rhel10-vm2:~$
user1@rhel10-vm2:~$ grep -l journald.conf a
a
user1@rhel10-vm2:~$ grep -l journald.conf test
grep: test: Is a directory
user1@rhel10-vm2:~$
Basic vs extended regex in grep#
With basic regex expressions (short BRE), special characters must be preceeded with a backslash if they are to be interpreted as special. Otherwise, they are interpreted as regular characters. The exception to this rule is the carrot character (^). BRE mode is activated with the -e option.
Let us consider a sample file /tmp/test.log":
Wassim@linux:/tmp$ cat test.log
a+b
a plus b
aaaaaaaab
Wassim@linux:/tmp$
Example 1: grep -e and passing the special characters without a backslash:
Wassim@linux:/tmp$ grep -e 'a+b' test.log
a+b
Wassim@linux:/tmp$
Example 2: grep -e and passing special characters wit a backslash:
Wassim@linux:/tmp$ grep -e 'a\+b' test.log
aaaaaaaab
Wassim@linux:/tmp$
grep -e 'a\+b' test.log searched for patterns like ab, aab, aaaab, etc. in the /tmp/test.log file.
With extended regex expressions (short ERE), special characters are interpreted as special without the need for a backslash.
Example 3: grep -E and passing special characters. No backslash involved.
Wassim@linux:/tmp$ grep -E 'a+b' test.log
aaaaaaaab
Wassim@linux:/tmp$
getting cpu info#
user1@rhel10-vm2:~$ lscpu
Architecture: x86_64
CPU op-mode(s): 32-bit, 64-bit
Address sizes: 46 bits physical, 48 bits virtual
Byte Order: Little Endian
CPU(s): 2
On-line CPU(s) list: 0,1
Vendor ID: GenuineIntel
Model name: Intel(R) Core(TM) Ultra 5 125H
CPU family: 6
Model: 170
Thread(s) per core: 1
Core(s) per socket: 1
Socket(s): 2
Stepping: 4
BogoMIPS: 5990.40
Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat
pse36 clflush mmx fxsr sse sse2 ss syscall nx pdpe1gb rdtscp lm
constant_tsc rep_good nopl xtopology cpuid tsc_known_freq pni pcl
mulqdq vmx ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt
tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm a
bm 3dnowprefetch cpuid_fault ssbd ibrs ibpb stibp ibrs_enhanced t
pr_shadow flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 a
vx2 smep bmi2 erms invpcid rdseed adx smap clflushopt clwb sha_ni
xsaveopt xsavec xgetbv1 xsaves avx_vnni arat vnmi umip pku ospke
waitpkg gfni vaes vpclmulqdq rdpid bus_lock_detect movdiri movdi
r64b fsrm md_clear serialize flush_l1d arch_capabilities
Virtualization features:
Virtualization: VT-x
Hypervisor vendor: KVM
Virtualization type: full
Caches (sum of all):
L1d: 64 KiB (2 instances)
L1i: 64 KiB (2 instances)
L2: 8 MiB (2 instances)
L3: 32 MiB (2 instances)
NUMA:
NUMA node(s): 1
NUMA node0 CPU(s): 0,1
Vulnerabilities:
Gather data sampling: Not affected
Indirect target selection: Not affected
Itlb multihit: Not affected
L1tf: Not affected
Mds: Not affected
Meltdown: Not affected
Mmio stale data: Not affected
Reg file data sampling: Not affected
Retbleed: Not affected
Spec rstack overflow: Not affected
Spec store bypass: Mitigation; Speculative Store Bypass disabled via prctl
Spectre v1: Mitigation; usercopy/swapgs barriers and __user pointer sanitizat
ion
Spectre v2: Mitigation; Enhanced / Automatic IBRS; IBPB conditional; PBRSB-eI
BRS Not affected; BHI BHI_DIS_S
Srbds: Not affected
Tsx async abort: Not affected
user1@rhel10-vm2:~$
user1@rhel10-vm2:~$ cat /proc/cpuinfo
processor : 0
vendor_id : GenuineIntel
cpu family : 6
model : 170
model name : Intel(R) Core(TM) Ultra 5 125H
stepping : 4
microcode : 0x28
cpu MHz : 2995.200
cache size : 16384 KB
physical id : 0
siblings : 1
core id : 0
cpu cores : 1
apicid : 0
initial apicid : 0
fpu : yes
fpu_exception : yes
cpuid level : 35
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss syscall nx pdpe1gb rdtscp lm constant_tsc rep_good nopl xtopology cpuid tsc_known_freq pni pclmulqdq vmx ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch cpuid_fault ssbd ibrs ibpb stibp ibrs_enhanced tpr_shadow flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid rdseed adx smap clflushopt clwb sha_ni xsaveopt xsavec xgetbv1 xsaves avx_vnni arat vnmi umip pku ospke waitpkg gfni vaes vpclmulqdq rdpid bus_lock_detect movdiri movdir64b fsrm md_clear serialize flush_l1d arch_capabilities
vmx flags : vnmi preemption_timer posted_intr invvpid ept_x_only ept_ad ept_1gb flexpriority apicv tsc_offset vtpr mtf vapic ept vpid unrestricted_guest vapic_reg vid shadow_vmcs pml tsc_scaling usr_wait_pause
bugs : spectre_v1 spectre_v2 spec_store_bypass swapgs bhi ibpb_no_ret spectre_v2_user
bogomips : 5990.40
clflush size : 64
cache_alignment : 64
address sizes : 46 bits physical, 48 bits virtual
power management:
processor : 1
vendor_id : GenuineIntel
cpu family : 6
model : 170
model name : Intel(R) Core(TM) Ultra 5 125H
stepping : 4
microcode : 0x28
cpu MHz : 2995.200
cache size : 16384 KB
physical id : 1
siblings : 1
core id : 0
cpu cores : 1
apicid : 1
initial apicid : 1
fpu : yes
fpu_exception : yes
cpuid level : 35
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss syscall nx pdpe1gb rdtscp lm constant_tsc rep_good nopl xtopology cpuid tsc_known_freq pni pclmulqdq vmx ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch cpuid_fault ssbd ibrs ibpb stibp ibrs_enhanced tpr_shadow flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid rdseed adx smap clflushopt clwb sha_ni xsaveopt xsavec xgetbv1 xsaves avx_vnni arat vnmi umip pku ospke waitpkg gfni vaes vpclmulqdq rdpid bus_lock_detect movdiri movdir64b fsrm md_clear serialize flush_l1d arch_capabilities
vmx flags : vnmi preemption_timer posted_intr invvpid ept_x_only ept_ad ept_1gb flexpriority apicv tsc_offset vtpr mtf vapic ept vpid unrestricted_guest vapic_reg vid shadow_vmcs pml tsc_scaling usr_wait_pause
bugs : spectre_v1 spectre_v2 spec_store_bypass swapgs bhi ibpb_no_ret spectre_v2_user
bogomips : 5990.40
clflush size : 64
cache_alignment : 64
address sizes : 46 bits physical, 48 bits virtual
power management:
user1@rhel10-vm2:~$
Linux networking#
Display IPv4 addresses in oneline:
user1@rhel10-vm2:~$ ip -4 -o address show
1: lo inet 127.0.0.1/8 scope host lo\ valid_lft forever preferred_lft forever
2: enp8s0 inet 192.168.122.6/24 brd 192.168.122.255 scope global dynamic noprefixroute enp8s0\ valid_lft 2789sec preferred_lft 2789sec
user1@rhel10-vm2:~$
user1@rhel10-vm2:~$
Another example:

Interface ’ens224’ has two IP addresses, one of which is secondary.
To delete the secondary IP address, start by removing it using nmcli connection modify:

But removing the secondary IPv4 address with nmcli alone does not clear it from the assigned IP addresses to the interface:

Bouncing the network connection:

Verifying the IPv4 addresses assigned to the network interface demonstrates that an interface bounce is mandatory to refresh the number of assigned IP addresses:

disk usage#
To display the disk usage of each directory of a directory passed in the argument recursively, and a total usage in the last line of the output:
Wassim@linux:~$ ls -l Videos/
total 0
drwxr-xr-x. 2 Wassim Wassim 26 Apr 7 12:42 Camera
drwxr-xr-x. 2 Wassim Wassim 54 Mar 5 2026 Screencasts
Wassim@linux:~$
Wassim@linux:~$ du Videos
45760 Videos/Camera
3180 Videos/Screencasts
48940 Videos
Wassim@linux:~$
In a human-readable format, i.e. using KiB, MiB and GiB:
Wassim@linux:~$ du -h Videos
45M Videos/Camera
3.2M Videos/Screencasts
48M Videos
Wassim@linux:~$
To display only one line summary of the disk usage of the directory passed in the argument:
Wassim@linux:~$ du -s Videos
48940 Videos
Wassim@linux:~$
Wassim@linux:~$ du -sh Videos
48M Videos
Wassim@linux:~$
To recursively display directory and file disk usage of the directory passed in the argument:
du -ha Videos
45M Videos/Camera/MOV00000.AVI
45M Videos/Camera
3.2M Videos/Screencasts/Screencast From 2026-03-05 14-35-36.webm
3.2M Videos/Screencasts
48M Videos
Wassim@linux:~$
Adding time of last modification:
Wassim@linux:~$ du -ha --time Videos
45M 2024-03-09 03:26 Videos/Camera/MOV00000.AVI
45M 2026-04-07 12:42 Videos/Camera
3.2M 2026-03-05 14:37 Videos/Screencasts/Screencast From 2026-03-05 14-35-36.webm
3.2M 2026-03-05 14:37 Videos/Screencasts
48M 2026-04-07 12:42 Videos
Wassim@linux:~$
To add a cumulative line of total disk usage of the directory passed in argument:
Wassim@linux:~$ du -hc Videos
45M Videos/Camera
3.2M Videos/Screencasts
48M Videos
48M total
Wassim@linux:~$
mount and umount of external storage disks#
Disk inserted. Then:
Wassim@linux:~$ dmesg | grep sd
dmesg: read kernel buffer failed: Operation not permitted
Wassim@linux:~$
Wassim@linux:~$ sudo dmesg | grep sd
[sudo] password for Wassim:
[ 1.860365] ahci 0000:00:17.0: flags: 64bit ncq sntf pm clo only pio slum part deso sadm sds
[ 2879.451415] sd 2:0:0:0: [sda] Spinning up disk...
[ 2879.483095] sd 2:0:0:0: Attached scsi generic sg0 type 0
[ 2882.551227] sd 2:0:0:0: [sda] 1953525168 512-byte logical blocks: (1.00 TB/932 GiB)
[ 2882.552147] sd 2:0:0:0: [sda] Write Protect is off
[ 2882.552151] sd 2:0:0:0: [sda] Mode Sense: 43 00 00 00
[ 2882.552567] sd 2:0:0:0: [sda] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA
[ 2882.642396] sda: sda1 sda2 < sda5 sda6 >
[ 2882.643274] sd 2:0:0:0: [sda] Attached SCSI disk
[ 2884.743386] FAT-fs (sda5): Volume was not properly unmounted. Some data may be corrupt. Please run fsck.
[ 2884.829641] FAT-fs (sda1): Volume was not properly unmounted. Some data may be corrupt. Please run fsck.
Wassim@linux:~$
I look for /dev/sda virtual block device:
Wassim@linux:~$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
sda 8:0 0 931.5G 0 disk
├─sda1 8:1 0 612.6G 0 part /run/media/Wassim/BLACK 3
├─sda2 8:2 0 1K 0 part
├─sda5 8:5 0 161.5G 0 part /run/media/Wassim/BLACK 1
└─sda6 8:6 0 157.5G 0 part /run/media/Wassim/Black 2
<---- output omitted ---->