Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Performing an interactive move of files....

Status
Not open for further replies.

chippymike

Technical User
Apr 16, 2003
22
GB
Hi,

I need to write a script that will prompt the user, through a menu, to move all files which match a particular search string (*.abc*) within a directory to a target directory.
I need the user to be prompted for every file, not just files which already exist in the target directory (mv -i is therefore not an option).
Creating the menu option is no problem but the syntax of the script which will give it its functionality has got me pulling my hair out!

I have the following so far;

for file in `find /dir_path -name "*.abc*" -print`
do
mv -i $file /target_path
done

I know I'm probably quite far off the mark so any help is greatly appreciated!

Cheers

 
Just a quick effort, but hope it gives you some ideas:

find /dir_path -name "*.abc*" -print > filelist
for name in `cat filelist`
do
echo "Is $name to be moved? "
read answer
if [ $answer = "y" ]
then
mv $name <destination_dir>/$name
else
echo &quot;You chose not to move $name.&quot;
fi
done

Note that this is untested, but should work with a bit of tweaking. Good luck.

 
Maybe something like...

for file in /dir_path/*.abc*
do
echo &quot;Move $file ? (y/n) : \\c&quot;
read REPLY
case $REPLY in
Y*|y*) mv $file /dest_dir ;;
*) echo $file not moved ;;
esac
done
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top