Is there a way to move file to a new directory without explicitly creating the directory using mkdir
command and then move the file using mv
The traditional method would be
mkdir -p
will create all elements of the path that do not exist.
You can change it with && mv
Example:
mkdir -p /tmp/1/2/3/ && mv /tmp/file /tmp/1/2/3/
The /tmp/1/2/3/ can be a variable that you can reuse.
It can also be done with tar
but then you need to make it with the directory structure already there. Untarring it elsewhere will create the paths that do not exist.
You can also use rsync
. If the destination does not exist it will create it for you. Example
rsync -a --relative /new/dir/1/2/3/ /old/dir/
That last one seems to the best method to me. rsync is an amazing tool for transferring files. Local and remote.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments