-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdir_clean
More file actions
executable file
·33 lines (28 loc) · 815 Bytes
/
dir_clean
File metadata and controls
executable file
·33 lines (28 loc) · 815 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/env bash
# a Bash script that cleans up a directory by organizing
#+ files into subdirectories based on their file extensions.
# with dynamical directory creation
# read input from user
read -rp "Input Directory Path: " parent_dir
echo "$parent_dir"
if [ ! -d "$parent_dir" ];then
echo "Not a valid Directory"
else
for file in "$parent_dir"/*;do
echo "$file"
if [ -f "$file" ] && [ ! -x "$file" ];then
if [ -s $file ]; then
extension=$(file -mime-type "$file" | cut -d '/' -f2)
else
extension=${file##*.}
fi
echo "$extension"
dir="$parent_dir/$extension"
if [ ! -d "$dir" ];then
mkdir -p "$dir"
fi
mv "$file" "$dir/"
fi
done
echo "Directory succesfully cleaned!!"
fi