Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I think this command tells cp to search in all sub-sequent folders of "old-hdd1/" but it never copies any pictures, even though I KNOW for certain that there are enough, especially .jpg ones that I included in the cp command.
Did I phrase the command wrongly or is something wrong with the system?
However before doing the -exec portion, I'd see what the find, would find, by not having the -exec term. Note you can also use the search spec "*.jp*" to find both jpg and jpeg extensions.
So, the command is actually looking for pictures immediately under /mnt/old-hdd1/ instead of recursively. Normally, the "-R" argument is used when copying entire directories and any subdirectories along. When you are looking for specific files or types of files, it is better to do a search first, like what rtmistler suggested with the find command. I invite you to read the man page for the find command. It is a very powerful command and will surely be useful in the future.
I guess the files are in some subfolders below /mnt/old-hdd1/. With the command above you only hit the files that are directly in /mnt/old-hdd1/. For instance /mnt/old-hdd1/bold/beng.jpg does not match /mnt/old-hdd1/*.jpg but is does match /mnt/old-hdd1/bold/*.jpg .
Thank you for extensive explanation, I understand now. Well, first of all I really wanted to copy the files and not only search. I guess I didn't make it clear enough since I used the word "search" in connection with the cp command. Secondly, this was my thought:
1. cp -R /one/pc/dir/ copies recursively
2. {*.png,*.etc} copies different file types
1. + 2. = 3. copies different file types recursively.
But I understand now that it obviously works differently when combining these two.
Thank you for extensive explanation, I understand now. Well, first of all I really wanted to copy the files and not only search. I guess I didn't make it clear enough since I used the word "search" in connection with the cp command. Secondly, this was my thought:
1. cp -R /one/pc/dir/ copies recursively
2. {*.png,*.etc} copies different file types
1. + 2. = 3. copies different file types recursively.
But I understand now that it obviously works differently when combining these two.
I agree with your starting philosophy and in fact had that perception once myself.
I've learned over time that I really do wish to search in advance to know what it will find and copy, or do some other operation I'm working on.
Per aragorn2101's and syg00's points. The man pages are both, "very helpful and usually 100% correct", and also "sometimes elusive or difficult to read/interpret".
I learned find incrementally. First how to find a file from the current working directory of a certain pattern name (regular expression I believe applies here). Then I learned how to do the -exec portion. That's about it, find may have tons more properties, but that seems to have served me well.
On the other side, I absolutely moved away from cp -R for when I did not wish to copy an entire tree unconditionally. I would use that, or the -a flag to copy an entire tree. But to locate only certain pattern filenames and do something with them, I stick with find.
I've learned over time that I really do wish to search in advance to know what it will find and copy, or do some other operation I'm working on.
Actually I already did search for all files on the drive including picture, that's also why I certainly know that there are pictures of these types. But it doesn't help me, because I obviously can't just copy paste the output of ls into a cp command.
You need to put "-or" between each off your filename conditions. Otherwise it looks for files that fulfill all these conditions, e.g. files that end with .jpg and .jpeg and so forth which is a contradiction.
As next step, try the -exec part in rtmistler answer. The syntax of find is akward here but it will work. Alternatively you may pass finds output to the cp cmd as follows.
you got a be in the working dir to run it. or you can replace the dot . with an absolute (search) path or two or three or four just add them in series using spaces between paths.
Code:
find /usr/local /etc /usr/bin -type f -name "*.goBa"
that will cause it to traverse through all of the paths one at a time
if you need to add more file types just repeat the pattern. -o -name "*.gif" etc..
The find-cmd as suggested by rtmistler is nontheless best way for you though a bit steep.
You need to put "-or" between each off your filename conditions. Otherwise it looks for files that fulfill all these conditions, e.g. files that end with .jpg and .jpeg and so forth which is a contradiction.
As next step, try the -exec part in rtmistler answer. The syntax of find is akward here but it will work. Alternatively you may pass finds output to the cp cmd as follows.
I read it implies the "-and" if I don't specificy anything. I assumed a different meaning there. Also the man page says that -exec is highly "insecure" and one should use -execdir instead.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.