-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclean_up.sh
More file actions
37 lines (29 loc) · 845 Bytes
/
clean_up.sh
File metadata and controls
37 lines (29 loc) · 845 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
33
34
35
36
37
#!/bin/bash
# Get the directory to organize; default to the current directory if not provided
directory="/home/user/cp_temp/"
# Check if the directory exists
if [ ! -d "$directory" ]; then
echo "Error: Directory '$directory' does not exist."
exit 1
fi
# Loop through all files in the directory
for file in "$directory"/*; do
# Skip if it's not a file
if [ ! -f "$file" ]; then
continue
fi
# Extract the file extension
extension="${file##*.}"
# Skip files without an extension
if [ "$file" == "$extension" ]; then
continue
fi
# Create the folder if it doesn't exist
folder="$directory/$extension"
if [ ! -d "$folder" ]; then
mkdir "$folder"
fi
# Move the file into the folder
mv "$file" "$folder/"
done
echo "Files have been organized by extension."