.. I have a Bash script meant to look for backup files (suffixed with .bak or ~). I also have an if..then routine (?) to write the names of the files found with those suffixes to a text file.
The text of the script is as follows:
I had a previous draft of the script that used a "find / xargs exec " routine, but adapting it to print the items found to a text file failed to work. In changing it to use just find, it fails to find all files matching the criteria ant thus I have to run it multiple times to remove all the matching files.
Help!
Carver
Edit: My Linux is Kubuntu, version 17.04 but I plan an upgrade in the next month or so.
My hardware is a Dell Inspiron 1720, 200GB HDD, 2GB Ram
The text of the script is as follows:
Code:
#!/bin/bash
files1=$(find . -type f -name "*bak*")
if [ -e "$files1" ];
then
/bin/rm -v "$files1" 2>/dev/null
echo -e "All backup files ending in *bak removed.\nNames written to log file."
echo "$files1" >> cleanback.log
fi
files2=(*~)
if [ -e "$files2" ];
then
/bin/rm -v "$files2"
echo -e "All backup files ending in ~ removed.\nNames written to log file"
echo "$files2" >> cleanback.log
fi
I had a previous draft of the script that used a "find / xargs exec " routine, but adapting it to print the items found to a text file failed to work. In changing it to use just find, it fails to find all files matching the criteria ant thus I have to run it multiple times to remove all the matching files.
Help!
Carver
Edit: My Linux is Kubuntu, version 17.04 but I plan an upgrade in the next month or so.
My hardware is a Dell Inspiron 1720, 200GB HDD, 2GB Ram