0

I have a large directory 'Pictures' that has a lot of individual sub directories, each with varying number of image files in them. I want to move every file that is in sub directories into a single, consolidated directory.

One challenge to overcome is that there are many files with the same name in various sub directories. i.e. Pictures/Subdir1/dsc_001.jpg, Pictures/Subdir15/dsc_001.jpg, Pictures/Subdir120/dsc_001.jpg

Since I want to keep both, I attempted to use the backup flag in a find one-liner, like so:

find . -type f -exec mv --backup=t '{}' /media/DATA-HDD/AllImages \;

However, upon testing, all source files move, but no renaming happens. I just have a single file which happens to be whichever file was moved last. I also tried using cp in the same manner, but same results.

Running Ubuntu 20.04 on this VM.

I have checked the man for coreutils and this is what it says to do, so not sure why it isn't working as planned.

5
  • works fine to me, files end up with .~1~ suffix
    – alecxs
    Aug 15, 2020 at 8:23
  • Right, I know losing the subdirs is going to happen, it is what I'm trying to do by consolidating. Interesting you are getting the proper result as expected but I'm most assuredly not. I have ran it multiple times. I guess if it is confirmed it works for you, then I need to figure out why mine is not working. All that I end up with is a single file in destination. Thanks for confirming it works anyhow.
    – shelzmike
    Aug 15, 2020 at 15:57
  • check mv --help
    – alecxs
    Aug 15, 2020 at 16:40
  • I had checked mv --help and coreutils man before posting as I have been around long enough to know that if you don't around here you get railed and put down quite readily. That being said, I checked again. As before, it showed my syntax was correct; however, the issue is that I was looking in the GUI for the files but hidden files was turned off! They have been there all along. I didn't realize until your example that they were hidden files.
    – shelzmike
    Aug 15, 2020 at 17:41
  • check mv --help will expose which mv is installed. for example on my android busybox mv doesn't support that --backup flag (so man page doesn't always fit your environment)
    – alecxs
    Aug 15, 2020 at 18:13

1 Answer 1

-1

As it turns out, the command one-liner is indeed exactly what I needed and has been working the whole time. What I failed to understand initially is that the output/backed up file is actually a hidden file. Wasn't sure that was the format. I was not listing the directory in terminal, but was instead only looking in the GUI and didn't have view hidden files turned on. Once I ran an ls -l, I saw the files have been there all along.

-rw-rw-r-- 1 mike mike     140302 Jan 11  2020  test.JPG
-rw-rw-r-- 1 mike mike     140302 Jan 11  2020  test.JPG.~1~
-rw-rw-r-- 1 mike mike     140302 Jan 11  2020  test.JPG.~2~
-rw-rw-r-- 1 mike mike          0 Aug 15 02:34  test.txt
-rw-rw-r-- 1 mike mike          0 Aug 15 02:34  test.txt.~1~
-rw-rw-r-- 1 mike mike          0 Aug 15 02:32  test.txt.~2~
-rw-rw-r-- 1 mike mike          0 Aug 15 02:34  test.txt.~3~
-rw-rw-r-- 1 mike mike          0 Aug 15 02:34  test.txt.~4~
-rw-rw-r-- 1 mike mike          0 Aug 15 02:43  test.txt.~5~
-rw-rw-r-- 1 mike mike          0 Aug 15 02:43  test.txt.~6~
-rw-rw-r-- 1 mike mike          0 Aug 15 02:34  test.txt.~7~
-rw-rw-r-- 1 mike mike          0 Aug 15 02:34  test.txt.~8~

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .