1, use a command complete replace the file with a newline character except letters all content
Sed 's//\ [^ a zA - Z] n/g' [filename]
2, print/etc/passwd first field at the end of the two Numbers lines
The awk - F: '$1 ~/[0-9] [0-9] $/{print $0}'/etc/passwd
3, use awk statistical the current directory, all files, the size of the display unit of M
The ls -l | awk '{size=size + $5} END {print "Total size:", the size/1024/1024, "M"}'
4, the use of a command to/etc/passwd username and home directory interchange (do not modify the original file)
Sed -r 's/([a zA - Z0-9] * (. *) :) ([a - zA - Z0-9/] * :) ([a zA - Z0 -/- 9] *)/\ \ \ 1 2 3\4/'/etc/passwd
5, use the ping command. Write a test network whether normal script
Ping - c4 $1 & gt;/dev/null 2 & gt; & 1
If [$? - eq 0]; Then
Echo detection network normal
The else
Echo detecting abnormal network connection
Fi
6, will eamil. HTM file email address fetching out, put the send. TXT file, and statistical grab line at the end of the file number email address
Cat email. HTM | grep - I - E '^ [a - z0-9 _] + [a - z0 - _ - 9] + @ ([a - z0-9] + [.]) + [a - z0-9] + $' & gt; Send. TXT
The count=0
For the line in ` cat send. TXT `
Do
Count++
The done
Echo "total number of email address:" $count & gt;> Send. TXT
7, the/var directory all the file size of 0, unified copied to/temp/sfile directory, and add read-only access to all files (sfile directory to exist, other users can access)
SourcePath="/var/"
NewPath="/temp/sfile/"
For the line in ` ls -l/var | awk '$1 ~/^ -/{the if ($5==0) {print $9}}' `
Do
Cp $SourcePath $$NewPath line
Chmod a + r $NewPath $line
The done
8, use grep and sed to delete files in one of two ways of comment lines and empty line (empty line does not contain Spaces)
The cat filename | grep -v '^ $| grep -v' ^ [#] '
The cat filename | sed '/^ $/d | sed'/^ [#]/d '
9, in the disk name lookup to see if there is a softconfig. Sh file, if there is, to find and copy it to the current user's home directory, if the file does not exist, the new
Built and the machine, the current time, IP address, host name, current login user name information input to softconfig. Sh in the text, and other users can edit this file,
(the find command to find a file or directory exists)
The find -name softconfig. Sh & gt;/dev/null 2 & gt; & 1
If [$? - eq 0]
Then
Path=` find -name softfig. Sh `
Cp path ~
The else
Echo $$(date) (ifconfig ens33 | grep -o - E "inet ([0-9] {1, 3}.) + [0-9] {1, 3}" | awk '{print $2}) $(cat/etc/hostname) $(whoami) & gt; Softconfig. Sh
Fi
10, write a script to use a for loop to achieve the following functions: to determine the input user name exists, if it does not create the user and password, otherwise the program continues to prompt the user, prompt heavy
New type new user name (interactive) read way
While ((1))
Do
Flag="T"
Read -p "please input the user name:" nn
For cc in ` cat/etc/passwd `
Do
If [$" nn "==" ${cc % % : *} "]
Then
Flag="F"
Break
Fi
The done
If [$" flag "==" T "]
Then
Echo $nn "does not exist, will create the user"
Break
The else
Echo "$nn already exists, please input again!"
The continue
Fi
The done
Read -p "please set user" $nn "password:" mm
Useradd $nn
Echo $mm | passwd $nn - stdin