-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcleanorcadir
executable file
·41 lines (33 loc) · 1.08 KB
/
cleanorcadir
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
38
39
40
#!/usr/bin/bash
dry_run=false
patterns_to_keep=()
# Check for the "--dry-run" flag and remove it from the arguments if present
for arg in "$@"; do
if [ "$arg" == "--dry-run" ]; then
dry_run=true
else
patterns_to_keep+=("$arg")
fi
done
# Build the find command dynamically
find_command='find . -type f \( -name "*.gbw" -o -name "*.cpcm" -o -name "*.densities" -o -name "*.hostnames" -o -name "*job*" -o -name "*engrad" -o -name "*opt" -o -name "*smd*" \)'
# Add exclusion patterns based on user input
for pattern in "${patterns_to_keep[@]}"; do
find_command+=" ! -name \"*$pattern*\""
done
# Execute the dynamically constructed find command
files=$(eval $find_command)
# Check if any files were found
if [ -n "$files" ]; then
echo "The following files would be deleted:"
echo "$files"
# If it's not a dry run, delete the files
if [ "$dry_run" == false ]; then
echo "$files" | xargs rm
echo "Files deleted."
else
echo "Dry run: No files were deleted."
fi
else
echo "No files matching the criteria were found."
fi