Last active
February 16, 2022 22:10
-
-
Save talesmm14/fd1bd83efeb4a46d9527ca734a93a9cf to your computer and use it in GitHub Desktop.
Script to organize files into folders (SHELL SCRIPT)
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
#!/bin/bash | |
# Information: Script to organize files into folders | |
# Version: 0.0.1 | |
# Date: 20220216 | |
# Autor: Tales Monteiro Melquiades - talesmelquiades@hotmail.com | |
# Github: https://github.com/talesmm14 | |
EXCLUSIVE=0 | |
COUNT=0 | |
# Colors | |
RED='\033[0;31m' # Red | |
GREEN='\033[0;32m' # Green | |
YELLOW='\033[0;33m' # Yellow | |
# Background | |
ON_BLUE='\033[44m' # Blue | |
ON_PURPLE='\033[45m' # Purple | |
NC='\033[0m' # No Color | |
shopt -s nullglob | |
organizing() { | |
if [ -n "$(echo *$1)" ]; then | |
if [ ! -d $2 ]; then | |
mkdir $2 | |
fi | |
for f in ./*$1 ; do mv "$f" $2 && ((COUNT++)) ; done ; | |
echo -e "${ON_BLUE}$1${NC} ${RED}files moved to${NC} ${ON_PURPLE}$2${NC}${RED}!!!${NC}" | |
fi | |
} | |
display_help() { | |
echo | |
echo "+--------------------------------------------------------------------+" | |
echo -e "| ${RED}SCRIPT TO ORGANIZE FILES INTO FOLDERS${NC} |" | |
echo "+--------------------------------------------------------------------+" | |
echo "| |" | |
echo -e "| Usage ${RED}to organize all files${NC}: $0 |" >&2 | |
echo "| |" | |
echo -e "| Usage: $0 ${RED}-t${NC} ${ON_BLUE}.file_type${NC} ${RED}-d${NC} ${ON_PURPLE}dir_name${NC}" " |" >&2 | |
echo "| |" | |
echo -e "| ${YELLOW}Ex: bash $0 .sh SHs${NC} |" | |
echo "| |" | |
echo "| -h, -help help for commands |" | |
echo "| -e exclusive command |" | |
echo "| |" | |
echo -e "| ${GREEN}Version: 0.0.1 ${NC} |" | |
echo -e "| ${GREEN}Date: 20220216 ${NC} |" | |
echo -e "| ${GREEN}Autor: Tales Monteiro Melquiades - talesmelquiades@hotmail.com${NC} |" | |
echo -e "| ${GREEN}Github: https://github.com/talesmm14 ${NC} |" | |
echo "| |" | |
echo "+--------------------------------------------------------------------+" | |
echo | |
exit 1 | |
} | |
if [ "$1" == "-h" ] || [ "$1" == "-help" ]; then | |
display_help | |
fi | |
while getopts t:d:e flag; do | |
case "${flag}" in | |
t) FILE_TYPE=${OPTARG} ;; | |
d) DIR_NAME=${OPTARG} ;; | |
e) EXCLUSIVE=1 ;; | |
*) echo "top" ;; | |
esac | |
done | |
if [ $FILE_TYPE ]; then | |
if [ $DIR_NAME ]; then | |
organizing $FILE_TYPE $DIR_NAME | |
else | |
echo -e "${RED}Specify the directory!${NC}" | |
echo -e "${YELLOW}-h, -help for more details${NC}" | |
fi | |
fi | |
if [ $EXCLUSIVE -eq '0' ]; then | |
# Organizing pdfs | |
organizing ".pdf" "PDFs" | |
# Organizing docs | |
organizing ".docx" "DOCXs" | |
organizing ".word" "DOCXs" | |
organizing ".txt" "DOCXs" | |
# Organizing images | |
organizing ".png" "IMGs" | |
organizing ".jpg" "IMGs" | |
organizing ".jpeg" "IMGs" | |
organizing ".gif" "IMGs" | |
organizing ".tif" "IMGs" | |
organizing ".tiff" "IMGs" | |
organizing ".bmp" "IMGs" | |
organizing ".eps" "IMGs" | |
organizing ".raw" "IMGs" | |
organizing ".cr2" "IMGs" | |
organizing ".nef" "IMGs" | |
organizing ".orf" "IMGs" | |
# Organizing compressed | |
organizing ".gz" "ZIPs" | |
organizing ".Z" "ZIPs" | |
organizing ".zip" "ZIPs" | |
organizing ".rar" "ZIPs" | |
organizing ".tar" "ZIPs" | |
organizing ".tgz" "ZIPs" | |
organizing ".tar.tz" "ZIPs" | |
# Organizing worksheets | |
organizing ".xls" "WORKSHEETs" | |
organizing ".csv" "WORKSHEETs" | |
organizing ".xlsx" "WORKSHEETs" | |
fi | |
echo | |
echo -e "${ON_BLUE}$COUNT${NC}${RED} files moved!!${NC}" |
You can add the LibreOffice extensions (at least .odt and .ods) and also .tsv (since separating fields with tabs is usually a superior solution than using commas).
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Download the file, put it in the folder where you want to run it, and open the terminal and run the following command:
bash organizing.sh -h
I appreciate any feedback, thanks!