Last active
          September 17, 2019 20:20 
        
      - 
      
 - 
        
Save madduci/3934e2c927f1eadb61e411be457e9834 to your computer and use it in GitHub Desktop.  
    Sorting files in folders
  
        
  
    
      This file contains hidden or 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
    
  
  
    
  | #!/bin/bash | |
| readonly INPUT_FOLDER="${1}" | |
| cd ${INPUT_FOLDER} | |
| find . -type f -print0 | while read -d $'\0' file | |
| do | |
| information=$(ls -lt --time-style=+%b-%Y "${file}") | |
| filedate=$(echo "${information}" | awk '{print $6}') | |
| filename=$(echo "${information}" | awk '{print $7}' ) | |
| destination_folder="${INPUT_FOLDER}/${filedate}" | |
| mkdir -p "${destination_folder}" | |
| printf "Moving %s in %s\n" "${filename}" "${destination_folder}" | |
| mv "${file}" "${destination_folder}/" | |
| done | |
| cd - | |
| echo "Sorting completed" | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment