Master Essential Linux Commands and Regex Tricks for System Operations
This guide presents a concise collection of practical CentOS 8 Linux commands and regular‑expression patterns, showing how to retrieve IP addresses, disk usage, user information, file permissions, and more, complete with command examples and visual output screenshots.
Regular expressions are patterns used to match each line of input, providing powerful character search and convenient filtering of desired content.
Linux system: CentOS Linux release 8.1.1911 (Core)
1. Find the IPv4 address of the local machine from the ifconfig output
ifconfig | head -n 2 | tail -1 | tr -s " " | cut -d" " -f32. Get the maximum partition usage percentage
df | tr -s " " | cut -d" " -f53. Show the username, UID, and default shell of the user with the highest UID
cat /etc/passwd | cut -d: -f1,3,7 | sort -nt: -k2 | tail -n 14. Display the permissions of the /tmp directory
stat /tmp | head -n 4 | tail -n 1 | cut -c10-135. List all system users with their usernames and UIDs
cat /etc/passwd | cut -d: -f1,3 | egrep "[0-9]{4,}"6. Show UID and default shell for users root, linuxmi, and mi (replace mi with A8)
cat /etc/passwd | egrep "^(root|A8)" | cut -d: -f1,37. Use egrep to extract lines ending with a lowercase letter from /etc/rc.d/init.d/functions
echo /etc/rc.d/init.d/functions | egrep "[a-z]$"8. Use egrep to extract directory names from the same path
echo /etc/rc.d/init.d/functions | egrep "/.*/"9. Count login attempts per host IP for root users from the last command
10. Use extended regular expressions to match numeric ranges
echo {1..255} | egrep "<[0-9]>"egrep "<1[0-9]>"egrep "<1[0-9][0-9]>"egrep "<2[0-4][0-9]>"egrep "<25[0-5]>"11. Show all IPv4 addresses from the ifconfig output
ifconfig | egrep "[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}"In short, regular expressions provide a concise way to describe and process text patterns.
Source: https://www.linuxmi.com/linux-zhengzebiaodashi.html
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Open Source Linux
Focused on sharing Linux/Unix content, covering fundamentals, system development, network programming, automation/operations, cloud computing, and related professional knowledge.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
