Command to move a file to a directory even if the directory is not present

AbhishekGowda28

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

Rinzwind

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.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Batch file get present working directory after cd command

From Dev

Move every file that is not a directory

From Dev

Move File in parent directory

From Dev

make/cc not finding header file even though its directory is present in PATH variable

From Dev

ClassNotFoundException Error even though jar file is present in WEB-INF/lib directory

From Dev

make/cc not finding header file even though its directory is present in PATH variable

From Dev

Move file to relative parent directory

From Dev

How to execute a binary file present in different directory?

From Dev

Delete file in target directory only if not present in source directory

From Dev

OSX Terminal command to move all files in directory

From Dev

How to move output of find command to another directory?

From Dev

Getting 'no such file or directory' even though the file is clearly there

From Dev

"bash: No such file or directory" even though file exists

From Dev

No such file or directory error even the file exists in Java

From Dev

Move directory to

From Dev

move_uploaded_file / No such file or directory in PHP

From Dev

ls command thinks directory is file

From Dev

Run command for every file in directory

From Dev

Command to copy a file to another directory

From Dev

Find command get file or directory

From Dev

Command to copy a file to another directory?

From Dev

Run command for every file in directory

From Dev

How to move file from directory A to directory B in remote server?

From Dev

How to move file from directory A to directory B in remote server?

From Dev

Shell Script to move oldest file from one directory to another directory

From Dev

Open failed: ENOENT (No such file or directory) even with permissions

From Dev

File not found, even though the directory is correct

From Dev

File not found, even though the directory is correct

From Dev

Move a file to another Ftp directory and rename it

Related Related

  1. 1

    Batch file get present working directory after cd command

  2. 2

    Move every file that is not a directory

  3. 3

    Move File in parent directory

  4. 4

    make/cc not finding header file even though its directory is present in PATH variable

  5. 5

    ClassNotFoundException Error even though jar file is present in WEB-INF/lib directory

  6. 6

    make/cc not finding header file even though its directory is present in PATH variable

  7. 7

    Move file to relative parent directory

  8. 8

    How to execute a binary file present in different directory?

  9. 9

    Delete file in target directory only if not present in source directory

  10. 10

    OSX Terminal command to move all files in directory

  11. 11

    How to move output of find command to another directory?

  12. 12

    Getting 'no such file or directory' even though the file is clearly there

  13. 13

    "bash: No such file or directory" even though file exists

  14. 14

    No such file or directory error even the file exists in Java

  15. 15

    Move directory to

  16. 16

    move_uploaded_file / No such file or directory in PHP

  17. 17

    ls command thinks directory is file

  18. 18

    Run command for every file in directory

  19. 19

    Command to copy a file to another directory

  20. 20

    Find command get file or directory

  21. 21

    Command to copy a file to another directory?

  22. 22

    Run command for every file in directory

  23. 23

    How to move file from directory A to directory B in remote server?

  24. 24

    How to move file from directory A to directory B in remote server?

  25. 25

    Shell Script to move oldest file from one directory to another directory

  26. 26

    Open failed: ENOENT (No such file or directory) even with permissions

  27. 27

    File not found, even though the directory is correct

  28. 28

    File not found, even though the directory is correct

  29. 29

    Move a file to another Ftp directory and rename it

HotTag

Archive