Linux regular expression practice

1. Find all files in the /etc/ directory that are larger than 1MB and whose types are ordinary files

find /etc -size +1M -type f

2. Pack all the files ending with conf in the /etc/ directory, the compressed package name is the time of the day, copy to the /usr/local/src directory for backup

find /etc -name "*conf" | xargs tar -czf `date +"%F"`.tar.gz -C /usr/local/src

3. Use sed to take out the IPv4 address of the machine in the ifconfig command

ifconfig ens33 | sed -nr '2s/^[^0-9]+([0-9.]+) .*$/\1/p'

4. Delete all the # and blank characters at the beginning of the line starting with # and followed by at least one blank character in the /etc/fstab file

sed -i -e '/^\s*$/d' -e '/^#/d' /etc/fstab

5. Process the /etc/fstab path and use the sed command to retrieve its directory name and base name

# 取目录名
echo "/etc/fstab" | sed -r 's#(^/.*/)([^/]+/?)#\1#'

# 取基名
echo "/etc/fstab" | sed -r 's#(^/.*/)([^/]+/?)#\2#'

Guess you like

Origin blog.51cto.com/14920534/2548001