I am about as new to bash scripts as it gets, so probably quite the stupid question, but here it goes.
The idea is as follows: save basename of a file in a log–> move file–> use log to move back to original location.
basename $filename >> /directory/log
mv $filename /directory
So far so good, but I am quite confused as to how to use that log file to get file back. Is basename even the right thing to use? Idea I had was using grep to find filename in the log, but how do I go about getting that output at the end of mv ?
mv $filename ???
Am I on the right track? Screwing up something very basic?
Lets take the file
httpd.confas an example, it’s location is in directory/etc/httpd/conf/The command
basenamestrips the path of the file and just returns the filename (and extension).So when you do:
You are creating a log file that contains only file names, you will not be able to use
/directory/logto move the file back to it’s original location because you stripped that information with thebasenamecommand.You would want to do something like this:
So that now
/directoryis the new location of the file and/directory/logcontains the original location of the file.