The shell script implementation classifies files according to the time the file was modified _linux shell

Source: Internet
Author: User
#!/bin/bash # exctute #/mod.sh File_type input_folder Output_folder #/mod.sh Count I f [! $#-eq 3];
  then echo "[ERROR] Error paramater." Exit Fi # File Type file_type= ' ${1} ' # input Foloder if [-d ' ${2} '];
  Then folder= "${2}" Else echo [ERROR] Input folder is not exsit. " Exit Fi # Output folder if [-D "${3}"];
  Then output= "${3}" Else echo [ERROR] output folder is not exsit. " Exit Fi # Search file Find ${folder}-name "${file_type}" | 
while read filename; Do # file type file_type= ' echo ${filename##*.} ' # File size file_size= ' stat ' ${filename} ' | Sed-n ' 2,1p ' | awk ' {print $} ' # file modify time file_modify= ' stat ' ${filename} ' | Sed-n ' 6,1p ' | awk ' {print $, $ $} ' | Sed-e ' s/[-:]//g ' # output folder path= ' ${output}/${file_modify:0:6} ' if [!-d ' ${path} '];
  Then Mkdir-p ${path} echo "folder (${path}) is created." Fi # New file full name New_file_name= ' echo ${path}/${file_mOdify}_[${file_size}].${file_type} ' if [!-f ' ${new_file_name} '];
  Then MV "${filename}" "${new_file_name}" Else echo "file (${new_file_name}) is Exsit, can isn't be removed." Fi done echo "Finished!" exit

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.