Skip to main content
added 104 characters in body
Source Link
yoshiserry
  • 293
  • 1
  • 4
  • 6

I've learned to use the find command by itself to find files and directories however when it comes to doing something with the files/folders I'm confused.

Given the following command:

find . -type f -iname "*.cr2" 

If I want to copy those files found above to a new directory I would naturally think use copy (cp) and pipe |.

find . -type f -iname "*.cr2" | cp \destination_directory

And to me this would get all my photos across an entire drive and nested in levels of sub folders into a single folder ready to start organising.

However people keep telling me to use the -exec parameter, so my question is how do you know when to pipe | and when to use -exec command as below?

 find . -name "*.pdf" -type f -exec cp {} ./pdfsfolder \;

EDIT

The suggested solution (below) only copies files where the file names are unique. and it says cp will not copy file.txt and replace with file.txt. In the instance you copy a lot of files, and don't know if there will be files of the same name, how do you copy something and say rename it if the filename exists?

Suggested solution "find . -type f -iname "*

find . -type f -iname "*.txt" -print0 | xargs -0 cp -t /home/josh/Documents/copy/

/home/josh/documents/copy being the directory I want to move stuff to.txt" | cp \destination_directory"

I've learned to use the find command by itself to find files and directories however when it comes to doing something with the files/folders I'm confused.

Given the following command:

find . -type f -iname "*.cr2" 

If I want to copy those files found above to a new directory I would naturally think use copy (cp) and pipe |.

find . -type f -iname "*.cr2" | cp \destination_directory

And to me this would get all my photos across an entire drive and nested in levels of sub folders into a single folder ready to start organising.

However people keep telling me to use the -exec parameter, so my question is how do you know when to pipe | and when to use -exec command as below?

 find . -name "*.pdf" -type f -exec cp {} ./pdfsfolder \;

EDIT

The suggested solution (below) only copies files where the file names are unique. and it says cp will not copy file.txt and replace with file.txt. In the instance you copy a lot of files, and don't know if there will be files of the same name, how do you copy something and say rename it if the filename exists?

Suggested solution "find . -type f -iname "*.txt" | cp \destination_directory"

I've learned to use the find command by itself to find files and directories however when it comes to doing something with the files/folders I'm confused.

Given the following command:

find . -type f -iname "*.cr2" 

If I want to copy those files found above to a new directory I would naturally think use copy (cp) and pipe |.

find . -type f -iname "*.cr2" | cp \destination_directory

And to me this would get all my photos across an entire drive and nested in levels of sub folders into a single folder ready to start organising.

However people keep telling me to use the -exec parameter, so my question is how do you know when to pipe | and when to use -exec command as below?

 find . -name "*.pdf" -type f -exec cp {} ./pdfsfolder \;

EDIT

The suggested solution (below) only copies files where the file names are unique. and it says cp will not copy file.txt and replace with file.txt. In the instance you copy a lot of files, and don't know if there will be files of the same name, how do you copy something and say rename it if the filename exists?

Suggested solution

find . -type f -iname "*.txt" -print0 | xargs -0 cp -t /home/josh/Documents/copy/

/home/josh/documents/copy being the directory I want to move stuff to.

find out how to copy and rename files of the same name
Source Link
yoshiserry
  • 293
  • 1
  • 4
  • 6

I've learned to use the find command by itself to find files and directories however when it comes to doing something with the files/folders I'm confused.

Given the following command:

find . -type f -iname "*.cr2" 

If I want to copy those files found above to a new directory I would naturally think use copy (cp) and pipe |.

find . -type f -iname "*.cr2" | cp \destination_directory

And to me this would get all my photos across an entire drive and nested in levels of sub folders into a single folder ready to start organising.

However people keep telling me to use the -exec parameter, so my question is how do you know when to pipe | and when to use -exec command as below?

 find . -name "*.pdf" -type f -exec cp {} ./pdfsfolder \;

EDIT

The suggested solution (below) only copies files where the file names are unique. and it says cp will not copy file.txt and replace with file.txt. In the instance you copy a lot of files, and don't know if there will be files of the same name, how do you copy something and say rename it if the filename exists?

Suggested solution "find . -type f -iname "*.txt" | cp \destination_directory"

I've learned to use the find command by itself to find files and directories however when it comes to doing something with the files/folders I'm confused.

Given the following command:

find . -type f -iname "*.cr2" 

If I want to copy those files found above to a new directory I would naturally think use copy (cp) and pipe |.

find . -type f -iname "*.cr2" | cp \destination_directory

And to me this would get all my photos across an entire drive and nested in levels of sub folders into a single folder ready to start organising.

However people keep telling me to use the -exec parameter, so my question is how do you know when to pipe | and when to use -exec command as below?

 find . -name "*.pdf" -type f -exec cp {} ./pdfsfolder \;

I've learned to use the find command by itself to find files and directories however when it comes to doing something with the files/folders I'm confused.

Given the following command:

find . -type f -iname "*.cr2" 

If I want to copy those files found above to a new directory I would naturally think use copy (cp) and pipe |.

find . -type f -iname "*.cr2" | cp \destination_directory

And to me this would get all my photos across an entire drive and nested in levels of sub folders into a single folder ready to start organising.

However people keep telling me to use the -exec parameter, so my question is how do you know when to pipe | and when to use -exec command as below?

 find . -name "*.pdf" -type f -exec cp {} ./pdfsfolder \;

EDIT

The suggested solution (below) only copies files where the file names are unique. and it says cp will not copy file.txt and replace with file.txt. In the instance you copy a lot of files, and don't know if there will be files of the same name, how do you copy something and say rename it if the filename exists?

Suggested solution "find . -type f -iname "*.txt" | cp \destination_directory"

Post Closed as "Duplicate" by jasonwryan, slm
edited tags
Source Link
Gilles 'SO- stop being evil'
  • 865.4k
  • 205
  • 1.8k
  • 2.3k

combining FINDfind with other commands: when to use -exec and when to use pipe?

I've learned to use the find command by itself to find files and directories however when it comes to doing something with the files/folders I'm confused.

Given the following command:

find . -type f -iname "*.cr2" 

ifIf I want to copy those files found above to a new directory I would naturally think use copy (cpcp) and pipe ||.

find . -type f -iname "*.cr2" | cp \destination_directory

And to me this would get all my photos across an entire drive and nested in levels of sub folders into a single folder ready to start organising.

However people keep telling me to use the -exec-exec parameter, so my question is how do you know when to pipe || and when to use -exec-exec command as below?

 find . -name "*.pdf" -type f -exec cp {} ./pdfsfolder \;

combining FIND with other commands when to use -exec and when to use pipe?

I've learned to use the find command by itself to find files and directories however when it comes to doing something with the files/folders I'm confused.

Given the following command:

find . -type f -iname "*.cr2" 

if I want to copy those files found above to a new directory I would naturally think use copy (cp) and pipe |.

find . -type f -iname "*.cr2" | cp \destination_directory

And to me this would get all my photos across an entire drive and nested in levels of sub folders into a single folder ready to start organising.

However people keep telling me to use the -exec parameter, so my question is how do you know when to pipe | and when to use -exec command as below?

 find . -name "*.pdf" -type f -exec cp {} ./pdfsfolder \;

combining find with other commands: when to use -exec and when to use pipe?

I've learned to use the find command by itself to find files and directories however when it comes to doing something with the files/folders I'm confused.

Given the following command:

find . -type f -iname "*.cr2" 

If I want to copy those files found above to a new directory I would naturally think use copy (cp) and pipe |.

find . -type f -iname "*.cr2" | cp \destination_directory

And to me this would get all my photos across an entire drive and nested in levels of sub folders into a single folder ready to start organising.

However people keep telling me to use the -exec parameter, so my question is how do you know when to pipe | and when to use -exec command as below?

 find . -name "*.pdf" -type f -exec cp {} ./pdfsfolder \;
Tweeted twitter.com/#!/StackUnix/status/519518466672304128
added 6 characters in body
Source Link
Anthon
  • 81.4k
  • 42
  • 174
  • 228
Loading
Source Link
yoshiserry
  • 293
  • 1
  • 4
  • 6
Loading