Help with Directory Structure Naming
I'm trying to copying my photo collection of thousands of photos that are in a folder structure into a single folder so that I can look at managing my collection via tagging rather than having a fixed folder structure. I have looked at several terminal commands and I'm getting to understand(!) what they mean. However, they all fall down with the folder names - I keep getting messages such as No such file or directory - so my naming must be wrong. I keep trying different things like /Home/Pictures/photos, or I cd to Pictures and try photos/ or /photos/ but I'm not getting it right. My latest failure is:
dad@dadubuntu:~$ find /Home/Pictures/photos -type f -exec cp {} /Home/Pictures/single folder/ \;
find: ‘/Home/Pictures/photos’: No such file or directory
dad@dadubuntu:~$
so in my Pictures folder I have my photo collection in a top level folder called photos. I'm trying to copy all the files into another folder in Pictures called single folder. Any help appreciated as I have too many photo files to copy and paste - this would truely help if I can get this naming convention right.
Re: Help with Directory Structure Naming
Re: Help with Directory Structure Naming
Still doesn't work.
dad@dadubuntu:~$ find /home/Pictures/photos -type f -exec cp {} /home Pictures/single folder/ \;
find: ‘/home/Pictures/photos’: No such file or directory
dad@dadubuntu:~$ sudo find /home/Pictures/photos -type f -exec cp {} /home Pictures/single folder/ \;
[sudo] password for dad:
find: ‘/home/Pictures/photos’: No such file or directory
dad@dadubuntu:~$
note. this is a test of only four sub folders and a small number of files within each in Picures/photos. If I can get this to work I will try on my actual collection.
Re: Help with Directory Structure Naming
You're missing your username, the full path should be:
Code:
/home/dad/Pictures/photos
or
~ is a shorthand way of writing your home directory.
Re: Help with Directory Structure Naming
That did it - many thanks.
Re: Help with Directory Structure Naming
For some reason I'm getting outputs with a lock and cross when I use this command:
sudo find /home/dad/Desktop/old -type f -exec cp {} /home/dad/Desktop/new \;
or
sudo find /home/dad/Desktop/old -type f -exec cp {} /home/dad/Desktop/new/ \;
see attached.
I can't understand while this is happening. Also, despite my efforts to get rid or rename duplicates before I execute this command some do get through. Is there a way to ammend this command so that if a duplicate file (they are photos) is found it is renamed reather than over written?
Re: Help with Directory Structure Naming
Its because you're using sudo when you don't have to.
Because you are using sudo then the file copy operation is being carried out by root, which is changing the ownership of the files accordingly. As you are only working with files in your own home folder there is no need to use sudo at all.
To change them back you can do:
Code:
sudo chown -R dad.dad /home/dad/Desktop/new
Re: Help with Directory Structure Naming
That did it - many thanks. Can you help on adding an additional element to my 'folder copying' command that will address the issue about duplicate file names? It is poosible for me to have duplicate file names in differenr sub folders that are different photos - so, if possible, I would rather not have duplicates over-written if found - but ideally renamed.
Re: Help with Directory Structure Naming
maybe not exactly what you want but a quick and dirty way to handle that might be to use the --backup parameter in cp
Code:
$ find . -type f -exec cp -v -t ./ --backup=numbered '{}' \;
`./dir2/file2' -> `./file2'
`./dir2/samefile' -> `./samefile'
`./dir1/file1' -> `./file1'
`./dir1/samefile' -> `./samefile' (backup: `./samefile.~1~')
i.e. it renames the 'old' file(s) rather than the 'new' file
Code:
$ ls -R
.:
dir1 dir2 file1 file2 samefile samefile.~1~
./dir1:
file1 samefile
./dir2:
file2 samefile
Re: Help with Directory Structure Naming
Sorry - I'm a newbie so need a bit of hand holding. Thanks for your help. In old I have 28 sub folders and probably that many again sub sub folders. In all, there are 6573 items - 99%+ of these are actual photos plus a few 'system' files inserted in various places by the Photo Applications like Picasa or Digikam. I can, sort of, work out what your first line is doing if I enter it into the Terminal (assume I cd to the old directory).
find . -type f -exec cp -v -t ./ --backup=numbered '{}' \;
But I'm not sure where these lines fit in. I think I have too many directories.
`./dir2/file2' -> `./file2'
`./dir2/samefile' -> `./samefile'
`./dir1/file1' -> `./file1'
`./dir1/samefile' -> `./samefile' (backup: `./samefile.~1~')