I'm totally new to Linux and trying to do a simple move with user input like this:

echo "where do you want to move the file to?"
read location
mv ~/my-applications/bin/trash/* $location

This works great, however, I wish to move a specified file specified by user input. For example, I wish to move test from trash but there is another file called dontmoveme. My script moves everything.


You can specify the file by adding another read:

echo "what do you want to move?"
read file
echo "where do you want to put it?"
read location
mv -v -- "$file" "$location"

If the script is just to move things from a particular location then you can of course give the path...

mv -v -- ~/my-applications/bin/trash/"$file" "$location"

I added -v so mv will tell you what it is doing - remove if preferred. I also added -- to tell mv not to interpret any following input as options, just to avoid any weird behaviour if someone enters any text beginning with -

  • Thank You. That does exactly what I was asking for..your a Star :) – Yunus1979 Nov 26 '16 at 23:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.