Created
December 6, 2013 02:42
-
-
Save jackode/7817748 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 Kill the Processes Clearly We always met the case to kill a group processes without affecting others belong to the same user. 1.1 kill the processes which are the child process of a target PID kill -9 -<pid> Notes: It is recommended that you start a new connection to the server and execute the command with possible exception, which provide a new process group and the above command would not affect others. 1.2 kill all of the processes belong to the same user: pkill -9 -U <username> 2 Using find find is a very strong command on Unix Platform, and it is more strong on Linux. 2.1 Find all of files whose name like "*.sql" or like "*.SQL" or like "*.sh" find . -type f -name "*.sql" -o -name "*.SQL" -o -name "*.sh" 2.2 Find all of files with size more/less than 1024 and modified more / less than one week(7 days): find . -type f -size +1024 -ctime +7 find . -type f -size -1024 -ctime -7 2.3 Find all of executable files which contains some strings find <dir name> -type f -perm -500 -exec grep -in "kkkk" {} \; Notes: Don't forget "\;" at the end of the commands. 3 Pattern Matching with awk/nawk There are a lot of cases related to pattern matching with awk. While, on Solaris, the strong version of awk is nawk. 3.1 Supposed that data file is separated by '|', the following command give all of rows whose last field contain the string "KKKK" by case sensitive nawk -F \| '{if( toupper($(NF)) ~ /KKKK/ ){print NR, ":", $0;}}' <target file name> 3.2 List all of the processes whose command contain the string "tpt" by case sensitive ps -ef | nawk '{if( tolower($(NF)) ~ /tpt/ ){print $0;}}' 3.3 Rename many files whose name have the same pattern find . -type f -name "*PPPP" | nawk '{srcname=$1; newname=$1; gsub("PPPP","", newname);scmd=" mv " srcname " " newname; print scmd;}' find . -type f -name "*PPPP" | nawk '{srcname=$1; newname=$1; gsub("PPPP","XXXX", newname);scmd=" mv " srcname " " newname; print scmd;}' *print and execute: find . -type f -name "*PPPP" | nawk '{srcname=$1; newname=$1; gsub("PPPP","", newname);scmd=" mv " srcname " " newname; print scmd; system(scmd); } ' find . -type f -name "*PPPP" | nawk '{srcname=$1; newname=$1; gsub("PPPP","XXXX", newname);scmd=" mv " srcname " " newname; print scmd; system(scmd); } ' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment