Shell script Article 4 001 # file verification 002md5sum filename003 004 # sort by array 005 sort-n filename.txt 006 007 # sort by Reverse Order 008 sort-r file.txt 009 010 # sort by month 011 012 sort -M file.txt 013 014 # sort by month (by January, ,) 015 016 # determine whether a file has been sorted 017 #! Bin/bash018 # filename019sort-C file; 020if [$? -Eq 0]; then021 echo sored022else023 echo unsored024fi025 026 # to merge two sorted files 027 sort-m sorted1 sorted2028 029cat data.txt 0301 mac 20000312 winxp 40000323 bsd 10000334 linux 1000034 # There are many ways to sort this text 035 036 # Which column is used for sorting 037 038 sort-nrk 1 data.txt 039 winxp 4000040mac 2000041 linux 12742bsd 1000043 044 # based on the first column, sort 045 046 # Clothes in reverse order 047 sork-k 2 data.txt 048 049bsd 1000050 linux kernel 51mac 2000052 winxp 40000 53 054 # uniq repeated characters 055 056cat uniq. txt | uniq057 058cat uniq.txt | uniq-u # show only strings that have not been repeated 059 060cat uniq.txt | uniq-c # to count the number of times each row appears in the file 061 062cat uniq.txt | uniq- d # Find the duplicate row 063 064cat data.txt 065u in the file: 01: gnu066d: 04: linux067u: 01: bash068u: 01: back069 # We need the string in the middle of 01 and 04 as the only keyboard, ignore the first two characters (-s 2) and use the-w option (-w 2) specify the maximum number of characters used for comparison to select the key 070 071 sort data.txt | uniq-s 2-w 2072 073 074 uniq-z file.txt # Use the uniq command Generate the output 075 076 uniq-z file.txt | xargs-0 rm # delete all specified files. If a file appears multiple times, the uniq command only writes this file to stdout once 077 078 # temporary file name 079temp_file = "/tmp/var. $"080 echo $ temp_file; 081 #. $ as the added suffix will be extended to the ID082 083 process of the current script # generate a temporary test file 084dd if =/dev/zero bs = 100 k count = 1 of = data. file085 086 # split the file 087-B 10 k data. file088 089 # Add the prefix 090 split-B 10 k data to the split file. file-d-a 4 split_file091 092 # If you do not want to cut 093 split-l 10 data according to the data block by default. file 0 94 # split the file into multiple files. Each file contains 10 095 096 lines. # The file extension must be extracted using % 097file_jpg = "sample.jpg" 098 name =$ {file_jpg %. *} 099 echo File name Is $ name; 100 # $ {VAR %. *} indicates that the wildcard on the Right of % is deleted. Non-Greedy mode 101 # $ {VAR %. *} perform greedy mode match 102 103 from the right to the left # use the help letter operation symbol to extract the. jpg image in the file name =$ {file_jpg #. *} 105 echo $ jpg106 #$ {VAR #. *} removes the wildcard located on the right of # from $ VAR. The wildcard matches 107 from the left to the right #$ {VAR ##*.} greedy mode 108 109 # batch rename shell script 110 111 #! /Bin/bash112 # filename rename113 # initialization variable 114 count = 1115 # loop through jpg files in all folders for img *. jpg117 do118 # generate new file name 119 new = image-$ count. $ {img ##*.} 120 # Move file 2>/dev/null standard error pointing to null, prevent printing to terminal 121 mv "$ img" "$ new" 2>/dev/null122 # If wildcard *. if jpg does not match a person or an image file, shell Concatenates the wildcard character into a string. From the outputs of images, you can see the .jpg file that does not exist, so 123 # if the mv *. jpg image-x.jpg will certainly produce an error, if ($? -Eq] Check the exit status ($ ?) If the latest command is not incorrect, then $? The value of is 0, otherwise 124 # returns a non-zero value. When an error occurs in the mv command, a non-zero value is returned to prevent the resulting Renameing file from being null, and the count is also added to 125 if [$? -Eq 0]; 126 then127 echo "Renameing $ img to $ new" 128 let count + + 129 fi130done131 132 will *. JPG renamed Wei *. jpg133rename *. JPG *. jpg134 135 Replace the space in the file name with _ 136 rename's // _/G' * 137 #'s // _/G' to replace the file name, while * wildcard 138 139 for matching file names convert case-insensitive 140 rename 'y/A-Z/a-z/'* 141 rename 'y/a-z/A-Z/* 142 143 transfer An mp3 file to a specified directory, you can use 144 find path-type f-name "*. mpe "-exec mv {} target_dir \; 145 146 replace spaces in all file names with characters _ 147 find path-type f-exec rename '/s/_/G '{}\/;