-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFS_recursive_deep_search.sh
61 lines (54 loc) · 1.09 KB
/
FS_recursive_deep_search.sh
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/bin/bash
### Recursively iterates over a filesystem structure and performs some action (defined in action() ) on it
### Debug switch
debug=false
### Useful variables for use in action()
#targetPath=/PATH/TO/DIRECTORY/
#targetFile=/PATH/TO/FILE
#
### Action on file is defined within this function
# $file contains the complete path to the current file the action acts on
action() {
### Examples:
# echo $file
# rsync -arv $file $targetPath --progress
# mv "$file" "$file.pdf"
# cat $file >> $targetFile
}
checkiffile() {
pFile=$1
if [ -d "${pFile}" ] ; then
if $debug; then
echo "${pFile} is a directory!";
fi
exit 1
else
if [ -f "${pFile}" ]; then
if $debug; then
echo "${pFile} is a regular file!";
fi
exit 0
else
if $debug; then
echo "${pFile} is neither a directory nor a regular file!";
fi
exit 2
fi
fi
}
recursivesearch() {
#echo $(realpath $1)
for f in $1/*;
do
if $(checkiffile $f) ;
then
file=$(realpath $f)
action
else
#echo "$f"
#echo "directory"
recursivesearch $(realpath $f)
fi
done
}
recursivesearch $(realpath ./)