shell - bash script to remove files matching those in another directory -
i'm trying create script retrieves files (including subfolders) cvs , stores them temporary directory /tmp/projectdir/ (ok), removes copies of files project directory /home/projectdir/ (not ok) without touching other files in project directory or folder structure itself.
i've been attempting 2 methods, i'm running problems both. here's script far:
#!/usr/bin/bash cd /tmp/ echo "removing /tmp/projectdir/" rm -rf /tmp/projectdir # cvs login goes here, code redacted # export files /tmp/projectdir/dir_1/file_1 etc cvs export -kv -r $1 projectdir # method 1 file in /tmp/projectdir/* # check zero-length string if [-n "$file"]; echo "removing $file" rm /home/projectdir/"$file" fi done # method 2 find /tmp/projectdir/ -exec rm -i /home/projectdir/{} \;
neither method works intended, because need way of stripping /tmp/projectdir/ filename (to replaced /home/projectdir/) , prevent them executing rm /home/projectdir/dir_1 (i.e. directory , not specific file), i'm not sure how achieve this.
(in case wondering, zero-length string bit attempt avoid rm'ing directory, before realised /tmp/projectdir/ part of string)
you can use:
cd /tmp/projectdir/ find . -type f -exec rm -i /home/projectdir/{} \;
Comments
Post a Comment