-
Notifications
You must be signed in to change notification settings - Fork 0
/
del-not-ext
executable file
·35 lines (27 loc) · 923 Bytes
/
del-not-ext
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
#!/bin/bash
#This bash script will delete files in a directory that don't have one
#of the extensions specified in the 2nd parameter.
#Sean Begley
#https://steamforge.net/wiki
#https://github.com/begleysm/ipcam-ftp-tools
#2019-07-17
#first parameter ($1) is the directory to work on
#second parameter ($2) is a comma delimited list of file extensions to NOT delete
#Example call: ./del-not-ext /path/to/directory jpg,mp4
#create list of extensions from $2
IFS=',' extensions=( $2 )
#only run if a working directory argument is supplied
if [ ! -z "$1" ]; then
#begin constructing our find command
command="find $1 -type f "
#create conditions from extension for the find command
for extension in "${extensions[@]}"
do
command+="! -name *.$extension "
done
#finish our find command
command+="-delete"
#delete any file that doesn't end in $extension
bash -c $command
fi