Move each file into its parent directory in linux

nwarp

Question

Assuming I have

dir 1/dir 2/file 1
dir 3/dir 4/file 2

(spaces in directory and file names are intentional)

I want to end up with

dir 1/file 1
dir 3/file 2

Related but incomplete answers

This answer moves all the files into the current parent directory (instead of each file's parent directory)

find . -maxdepth 1 -exec mv {} .. \;

This answer prints out each parent directory but I'm not sure how to do the moving.

find . -name '.user.log' | xargs -I{} dirname {}
Kamil Maciorowski
find -type f -execdir mv "{}" ../ \;

The -execdir is like -exec but does its job in a directory where the particular file is, so the ../ part works as you need.

To get rid of empty dir2 and dir4 in your example you need another specialized command, but the main task is done.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Is there a way to move an element outside of its parent with jquery?

From Dev

RewriteRule for a file in a parent directory

From Dev

How to move file inside directory, using Linux (Bash)

From Dev

How to create a text file containing filenames in subdirectories of a directory, and prepend a parent directory name to each row?

From Dev

How to list only the file names and not its attributes in a directory( in Linux)?

From Dev

Move file to relative parent directory

From Dev

Move a div before its parent

From Dev

Move file to parent folder on FTP

From Dev

Move .git repo to parent directory

From Dev

gulp move files to parent directory

From Dev

How to compile each jasper file to its own directory?

From Dev

How to move some files to their parent directory?

From Dev

Move files to parent directory of current location

From Dev

How to move some files to their parent directory?

From Dev

How to move and overwrite subdirectories (and files) to parent directory?

From Dev

find files older than create its parent folder in a directory and move them there

From Dev

Move and rename files based on their parent's directory

From Dev

How to move files from subdirectories that have the same directory name to its relative upper/parent directory?

From Dev

Move directory to Grandpa directory and delete the parent directory

From Dev

Grunt.js: copy file without its parent directory

From Dev

Can a file be edited with the 'write' permission on it but not on its parent directory?

From Dev

Move every file that is not a directory

From Dev

Pythonic way to extract the file name and its parent directory from the full file path?

From Dev

Create file and its parent directory

From Dev

Move files to parent directory, prefixing file name with former subdirectory name

From Dev

gulp move files to parent directory

From Dev

Move File in parent directory

From Dev

Linux - Inherit file permissions from parent directory

From Dev

Rename a file to part of the name of parent directory in linux

Related Related

  1. 1

    Is there a way to move an element outside of its parent with jquery?

  2. 2

    RewriteRule for a file in a parent directory

  3. 3

    How to move file inside directory, using Linux (Bash)

  4. 4

    How to create a text file containing filenames in subdirectories of a directory, and prepend a parent directory name to each row?

  5. 5

    How to list only the file names and not its attributes in a directory( in Linux)?

  6. 6

    Move file to relative parent directory

  7. 7

    Move a div before its parent

  8. 8

    Move file to parent folder on FTP

  9. 9

    Move .git repo to parent directory

  10. 10

    gulp move files to parent directory

  11. 11

    How to compile each jasper file to its own directory?

  12. 12

    How to move some files to their parent directory?

  13. 13

    Move files to parent directory of current location

  14. 14

    How to move some files to their parent directory?

  15. 15

    How to move and overwrite subdirectories (and files) to parent directory?

  16. 16

    find files older than create its parent folder in a directory and move them there

  17. 17

    Move and rename files based on their parent's directory

  18. 18

    How to move files from subdirectories that have the same directory name to its relative upper/parent directory?

  19. 19

    Move directory to Grandpa directory and delete the parent directory

  20. 20

    Grunt.js: copy file without its parent directory

  21. 21

    Can a file be edited with the 'write' permission on it but not on its parent directory?

  22. 22

    Move every file that is not a directory

  23. 23

    Pythonic way to extract the file name and its parent directory from the full file path?

  24. 24

    Create file and its parent directory

  25. 25

    Move files to parent directory, prefixing file name with former subdirectory name

  26. 26

    gulp move files to parent directory

  27. 27

    Move File in parent directory

  28. 28

    Linux - Inherit file permissions from parent directory

  29. 29

    Rename a file to part of the name of parent directory in linux

HotTag

Archive