GREP Find shell foundation

1, define a command alias that is effective for all users, for example: lftps=’172.168.0.1/pub’

echo "alias lftps='172.168.0.1/pub'" >> /etc/bashrc && source /etc/bashrc

2, display all lines in the /etc/passwd file that do not end with /bin/bash

grep -v "/ bin/bash$" /etc/passwd

3, find the line containing two or three digits in the /etc/passwd file

grep "\<[0 -9]\{2,3\}\>" /etc/passwd

4, display the line starting with case s in the /proc/meminfo file, in three ways

grep -i'^s' /proc/meminfo
grep'^[sS]]' /proc/meminfo
grep -E'^(s|S)' /proc/meminfo

5, Use echo to output an absolute path, use egrep to take the path name type and execute the result of dirname /etc/passwd

echo "/a/b/c/d" | egrep -o ' .*/'

6 Find out the ip address in ifconfig, and require the result to display only the ip address

ifconfig | egrep -o'inet (addr:)?([0-9 ]*\.){3}[0-9]*' | egrep -o'([0-9]*\.){3}[0-9]*' | head -n 1

< p>7 Vim custom automatic indentation of 4 characters
cat >> /etc/vimrc << EOF
set ai
set tabstop=4
EOF
8 Write a script to realize automatic addition Three users, and calculate the sum of the uids of these three users

#!/bin/bash
#
sum_uid=0
for account in user1 user2 user3< br /> do
if id $account &> /dev/null
then echo "$account exists"
else
useradd $account
fi
uid=$(id -u $account )
sum_uid=$[$sum_uid+$uid]
done
echo "The sum of the UID of 3 users is $sum_uid"

9 find usage and common examples< /p>

fine [options] [Search start path] [Search condition] [Processing action]

-name file name search supports glob
-iname ignore case
Search by subordinate
-user USERNAME

-user groupname

-uid

-gid

-nouser finds files without an owner

-nogroup
finds file types
-type

f normal files

d directory file

l symbolic link file

b block device file

c character device file

p pipe file

s socket
combined search
and: -a
or: -o< br /> Non: -not,!
File size

-size [+|-]#unit

Commonly used unit: k MG
< br /> #unit: (#-1, #]

-#unit: [0-#-1 ]

+#unit: (#, infinity)< br /> Time
In days
-atime [+|-]# Visit
#: The past few days [#,#-1)
-# (# , 0] In the past #days
+# (00, #-1] How many days have passed
-mtime modification
-ctime modification
In minutes
-amin
-mmin
-cmin
Permission
-perm [+|-]mode
mode: exactly matches the mode
+mode: ugo group has one set of satisfaction
br /> -mode: Less than mode permission is sufficient
Processing action:
-print output to standard output default action
-ls
-delete delete
- fls /path The detailed information of the file searched is saved to the specified file.
-ok COMMAND {} \; Execute the command specified by COMMAND for each file found, and each operation is confirmed by the user.
-exec COMMANd {} \; Execute the command specified by COMMAND for each file found, no user confirmation is required for each operation

Leave a Comment

Your email address will not be published.