- Sum of 2 numbers
- Calculates the 1-100 and
- Change the extension of all files in a directory to Bak
- Compile all. c files in the current directory:
- Print root can use the number of executable files to process the result: Root ' s bins:2306
- Prints the port and process ID of the current sshd, processing the result: sshd port&&pid:22 5412
Outputs the time it takes to create 20,000 directories, processing the results:
Real 0m3.367suser 0m0.066ssys 0m1.925s
Print native swap partition size, processing result: swap:1024m
Text analysis, removing the number of occurrences of the shell in/etc/password
The first method results: 4/bin/bash 1/bin/sync 1/sbin/halt 31/sbin/nologin 1/sbin/shutdown The result of the second method: / Bin/sync 1 /bin/bash 1 /sbin/nologin /sbin/halt 1 /sbin/shutdown 1
File collation, employee file records the work number and name, (prompted join)
Employee.txt: Jason Smith, John Doe, Sanjay Gupta Ashok Sharma Bonus document record number and salary Bonus.txt: $5,000 400 $1,250 $3,000 Two files are required to be merged and output as follows, processing results: 400 Ashok Sharma $1,250 Jason Smith $5,000 John Doe $ Sanjay Gupta $3,000
Write a shell script to get the current date, time, user name and current working directory.
- Write a shell script to get the network address of this machine.
- Write a shell script to transfer files larger than 10K in the current directory to the/tmp directory
Write a script called myfirstshell.sh, which includes the following content.
A) contains a comment that lists your name, the name of the script, and the purpose of writing the script. b) Greeting the user. c) Displays the date and time. d) display the calendar for this month. E) Displays the name of your machine. f) Displays the name and version of the current operating system. g) Displays a list of all files in the parent directory. h) Shows all processes that root is running. i) Displays the value of the variable term, path, and home. j) Display of disk usage. k) Print out your group ID with the ID command. m) say "good bye" with the user
File move copy, have m1.txt m2.txt m3.txt m4.txt, create the corresponding directory, M1 m2 M3 M4 and move the file to the corresponding directory
- How long did the root user log on today?
- Terminal Enter a file name to determine if it is a device file
Statistics IP access: Requires analysis of Apache access logs to find out the number of access pages in the first 100 bits of IP. The log size is around 78M. The following is an excerpt from Apache's access log
202.101.129.218--[26/mar/2006:23:59:55 +0800] "get/online/stat_inst.php?pid=d065 http/1.1" 302 20-"-" "-" "MOZILLA/4. 0 (compatible; MSIE 6.0; Windows NT 5.1) "
Design a shell program, set up 50 directories in the/userdata directory, that is, USER1~USER50, and set permissions for each directory, where the permissions of the other users are: Read, the file owner's permissions are: Read, write, execute, the permissions of the group of the file owner are: Read, execute.
- Design a shell program, add a new group to Class1, and then add 30 users belonging to this group, the user name is Stdxx, where xx is from 01 to 30, and set the password for the corresponding stdxx.
- Write a shell program to automatically delete 30 account functions. The account name is STD01 to Std30.
- User cleanup, clears all users except the current logged-on user
- Design a shell program, on the first day of each month to back up and compress all contents of/etc directory, stored in the/root/bak directory, and the file name for the following form Yymmdd_etc,yy for the year, MM for the month, DD for the day. The shell program Fileback stored in the/usr/bin directory.
- For a user log file, each row records a user query string, length of 1-255 bytes, a total of tens of millions of rows, please drain the top 100 queries. Logs can be constructed on their own. (Hint: awk sort uniq head)
- Write your own Ubuntu environment installation script
- Write the server daemon management script.
View TCP connection Status
Netstat-nat |awk ' {print $6} ' |sort|uniq-c|sort-rnnetstat-n | awk '/^tcp/{++s[$NF]}; END {for (a in S) print A, s[a]} ' or Netstat-n | awk '/^tcp/{++state[$NF]}; END {for (key in) print key, "\ T", State[key]} ' netstat-n | awk '/^tcp/{++arr[$NF]}; END {for (k in arr) print K, "T", arr[k]} ' netstat-n |awk '/^tcp/{print $NF} ' |sort|uniq-c|sort-rnnetstat-ant | awk ' {print $NF} ' | Grep-v ' [A-z] | Sort | Uniq-c
Find requests 20 IP (commonly used to find the source of attack):
Netstat-anlp|grep 80|grep Tcp|awk ' {print $} ' |awk-f: ' {print '} ' |sort|uniq-c|sort-nr|head-n20netstat-ant |awk '/:8 0/{split ($5,ip, ":"); ++a[ip[1]]}end{for (i in A) print A[i],i} ' |sort-rn|head-n20
Sniff 80-port access with tcpdump to see who is the tallest
Tcpdump-i ETH0-TNN DST Port 80-c 1000 | Awk-f "." ' {print $ '. $ "." $ "." $4} ' | Sort | uniq-c | Sort-nr |head-20
Find more time_wait connections
Netstat-n|grep Time_wait|awk ' {print $} ' |sort|uniq-c|sort-rn|head-n20
Find more SYN connections
Netstat-an | grep SYN | awk ' {print $} ' | Awk-f: ' {print $} ' | Sort | uniq-c | Sort-nr | More
Depending on the port column process
NETSTAT-NTLP | grep 80 | awk ' {print $7} ' | Cut-d/-F1
Get access to the top 10-bit IP address
Cat Access.log|awk ' {print $} ' |sort|uniq-c|sort-nr|head-10cat Access.log|awk ' {counts[$ (11)]+=1}; END {for (URL in counts) print Counts[url], url} '
The most visited file or page, take the top 20
Cat Access.log|awk ' {print $11} ' |sort|uniq-c|sort-nr|head-20
List the maximum number of EXE files transmitted (used when analyzing the download station)
Cat Access.log |awk ' ($7~/.exe/) {print $ "" $ "" $4 "" $7} ' |sort-nr|head-20
Lists EXE files with output greater than 200000byte (approx. 200kb) and the number of corresponding file occurrences
Cat Access.log |awk ' ($ > 200000 && $7~/.exe/) {print $7} ' |sort-n|uniq-c|sort-nr|head-100
If the last column of the log records the paging file transfer time, there are the most time-consuming pages listed to the client
Cat Access.log |awk ' ($7~/.php/) {print $NF "" $ "" $4 "" $7} ' |sort-nr|head-100
List the most time-consuming pages (more than 60 seconds) and the number of corresponding page occurrences
Cat Access.log |awk ' ($NF > && $7~/.php/) {print $7} ' |sort-n|uniq-c|sort-nr|head-100
List files that have been transmitted for longer than 30 seconds
Cat Access.log |awk ' ($NF >) {print $7} ' |sort-n|uniq-c|sort-nr|head-20
Statistics website Traffic (G)
Cat Access.log |awk ' {sum+=$10} END {print sum/1024/1024/1024} '
Statistics 404 of Connections
awk ' ($9 ~/404/) ' Access.log | awk ' {print $9,$7} ' | Sort
Statistics HTTP Status
Cat Access.log |awk ' {counts[$ (9)]+=1}; END {for (code in counts) print code, Counts[code]} ' cat Access.log |awk ' {print $9} ' |sort|uniq-c|sort-rn
Spider analysis to see which spiders are crawling content.
/usr/sbin/tcpdump-i Eth0-l-S 0-w-DST Port 80 | Strings | Grep-i User-agent | Grep-i-E ' bot|crawler|slurp|spider '
Create a user Mandriva, whose ID number is 2002, the base group is distro (group ID 3003), and the additional group is Linux;
# groupadd linux# groupadd-g 3003 distro# useradd-u 2002-g distro-g linux Mandriva
Create a user fedora with the full name of Fedora Community, the default shell of Tcsh; # useradd-c "Fedora Community"-s/bin/tcsh Fedora
The ID number of the modified Mandriva is 4004, the basic group is Linux, the additional group is distro and fedora;
# usermod-u 4004-g linux-g Distro,fedora Mandriva
Add password to Fedora and set its minimum password for 2 days, up to 50 days;
# passwd fedora# chage-m 2-m Fedora
Debug commands
Strace-p PID
Write a script
1, create a group newgroup, ID number 4000, 2, create a user mageedu1, ID number 3001, additional group is newgroup;3, create directory/tmp/hellodirxyz4, copy/etc/fstab to the above directory 5, The owner and owner of the directory and the internal files are mageedu1;6, and other users of the directory and internal files do not have any permissions; #!/bin/bash # Description: # Version: # Datetime: # Author: mygroup= "Newgroup1" myuser= "Mageedu2" mydir= "/tmp/hellodirxyz1" myid=3002 Groupadd-g 4001 $myGroup useradd-u $myID-G $myGroup $myUser mkdir $myDir cp/etc/fstab $myDir Chow N-r $myUser: $myUser $myDir chmod-r o= $myDir unset mygroup myUser MyID MyDir
Statistics/bin,/usr/bin,/sbin and/usr/sbin the number of files in each directory;
# Ls/bin | Wc-l
Displays the shell of all users on the current system, requiring that each shell be displayed only once;
# cut-d:-f7/etc/passwd | Sort-u
Remove the 7th line of the/etc/passwd file;
# head-7/ETC/PASSWD | Tail-1
Displays the user name of the 7th row taken out in question 3rd;
# head-7/ETC/PASSWD | Tail-1 | cut-d:-f1# head-7/etc/passwd | Tail-1 | Cut-d:-f1 | Tr ' A-Z ' A-Z
Count the number of files that start with P or p in the/etc directory;
# ls-d/etc/[pp]* | Wc-l
Write a script that shows how many rows of/etc/init.d/functions,/etc/rc.d/rc.sysinit, and/etc/fstab are displayed with a for loop;
For FileName In/etc/init.d/functions/etc/rc.d/rc.sysinit/etc/fstab; Do wc-l $fileNamedone #!/bin/bashfor fileName in/etc/init.d/functions/etc/rc.d/rc.sysinit/etc/fstab; Linecount= ' Wc-l $fileName | Cut-d '-f1 ' echo ' $fileName: $lineCount lines. " Done#!/bin/bashfor FileName In/etc/init.d/functions/etc/rc.d/rc.sysinit/etc/fstab; Do echo "$fileName: ' Wc-l $fileName | cut-d '-f1 ' lines. Done
Write a script that copies three files from the previous question to the/tmp directory, and use the For loop to change the last modification time of each file to December 15, 2016 15:43;
For FileName In/etc/init.d/functions/etc/rc.d/rc.sysinit/etc/fstab; Do CP $fileName/tmp basename= ' baseName $fileName ' touch-m-t 201109151327/tmp/$baseNamedone
Write a script that shows the user name and ID number of the 3, 7, and 11 users in/etc/passwd;
For Lineno in 3 7 11; Do userinfo= ' head-n $lineNo/etc/passwd | tail-1 | cut-d:-f1,3 ' echo-e ' User: ' echo $userInfo | cut-d:-f1 ' \nuid: ' echo $userInfo |cut-d:-f2 ' "Done
Displays the lines in the/proc/meminfo file that begin with the case s;
# grep "^[ss]"/proc/meminfo# grep-i "^s"/proc/meminfo
Remove the default shell as a non-bash user;
# grep-v "bash$"/etc/passwd | Cut-d:-f1
Remove the user whose default shell is bash with the largest ID number;
# grep "bash$"/etc/passwd | Sort-n-T:-k3 | Tail-1 | Cut-d:-f1
Displays the line in the/etc/rc.d/rc.sysinit file, beginning with #, followed by at least one white space character, and then with at least one non-whitespace character;
# grep "^#[[:space:]]\{1,\}[^[:space:]]\{1,\}"/etc/rc.d/rc.sysinit
Displays lines that begin with at least one whitespace character in/boot/grub/grub.conf;
# grep "^[[:space:]]\{1,\}[^[:space:]]\{1,\}"/boot/grub/grub.conf
Find one or two digits in the/etc/passwd file;
# grep--color=auto "\<[0-9]\{1,2\}\>"/etc/passwd
Find the integer between 1 and 255 in the result of the ifconfig command;
# Ifconfig | Grep-e--color=auto "\< ([1-9]|[ 1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]) \> "
View all information about the root user on the current system;
# grep "^root\>"/etc/passwd
Add user bash and Testbash, basher, and then identify the user on the current system whose user name and default shell are the same;
# grep--color=auto "^\ ([[: Alnum:]]\{1,\}\) \>.*\1$"/etc/passwd
Find the line that ends with "LISTEN" or "established" in the results of the Netstat-tan command execution;
- Remove the shell of all users on the current system, requiring that each shell be displayed only once and in ascending order;