points about the 'mv' command
I want to copy a file from an old directory to a new directory and ideally I would like that the 'mv' command itself could create the directory for me in one step...
That is to say that the directory would not exist until 'mv' has been called as in: Code:
mv olddirectory/file.dat newdirectory/file.dat I am not sure if this is possible however, that is to say I think it may be necessary that the directory 'newdirectory' already exists before I make the above call to mv, as when I make try the above call when 'newdirectory' doesn't exist I get the following error: Quote:
is there some paramater for 'mv' that I can change so that it will create the new directory as well as copy the file and if not, are there other commands that might do this? |
Hello AndrewJS,
mv doesn't rename directories! (Edit: it can rename but not rename and move simultaneously) I'd recommend for such often used commands like mv, read the manpage. Code:
man mv Markus |
You can use mv to rename directories, but only if they are the most specific part of the filespec.
Perhaps this bit of shell script provides somewhat of a solution, as well as an illumination of the problem that mv simply avoids (this has undergone only cursory testing. If you use it for real, test thoroughly, and then remove the 'echo' commands to 'go live') Code:
#! /bin/bash |
As far as I know,
Code:
mkdir Code:
mv You could probably write a script to allow you to have one command to create the directory and move the file, you'd still have to supply the new directory and file names, but if you're only doing it once, why bother? Play Bonny! :hattip: |
All times are GMT -5. The time now is 03:06 PM. |