Skip to main content
added 1033 characters in body; added 2 characters in body
Source Link
Stilez
  • 1.3k
  • 19
  • 32

I'm using find with the -exec option in console, on FreeBSD (for example, find . -exec sha1 {} \;).

  1. How do I correctly place (and if needed, escape) redirect and other execution control symbols that could syntactically apply to either of the exec command or the find command, such as > >> | and &, where I might want the symbol to apply to the find or the exec commands on different occasions?

  2. On the same theme, what is the syntax if I want to use tee to view the output of the -exec commands on the console (to watch progress) and also appended to a file (for later use)?

(I know shells vary but hopefully the most used shells such as sh/csh are quite similar?)

Update:

In part, I want to learn if nested find -exec can be done without scripting, as a simple command. Here is the use-case that prompted the questio :

  • outer find: find all subdirs matching DIR_MATCH_TEXT in DIR1
  • inner find: for each matching subdir found in the outer loop (call it DIR2), execute the command
    find DIR2 -name "FILE_MATCH_TEXT" -exec sha1 {} \; >> DIR1/DIR2_hashes.txt

The aim being to create a set of files, one for each matching subdir, containing the output of some find -exec action on that subdir.

By this I mean that, if /backups contains /jan2017 and /feb2017, the result will be two files at /backups/jan2017_hashes.txt and /backups/feb2017_hashes.txt, with jan2017_hashes.txt containing the output from sha1 for (say) all .pdf files in /backups/jan2017, and feb2017_hashes.txt containing the output from sha1 for all .pdf files in /backups/feb2017.

From replies so far I gather the outer find would have to use a shell call as the argument to -exec?

I'm using find with the -exec option in console, on FreeBSD (for example, find . -exec sha1 {} \;).

  1. How do I correctly place (and if needed, escape) redirect and other execution control symbols that could syntactically apply to either of the exec command or the find command, such as > >> | and &, where I might want the symbol to apply to the find or the exec commands on different occasions?

  2. On the same theme, what is the syntax if I want to use tee to view the output of the -exec commands on the console (to watch progress) and also appended to a file (for later use)?

(I know shells vary but hopefully the most used shells such as sh/csh are quite similar?)

I'm using find with the -exec option in console, on FreeBSD (for example, find . -exec sha1 {} \;).

  1. How do I correctly place (and if needed, escape) redirect and other execution control symbols that could syntactically apply to either of the exec command or the find command, such as > >> | and &, where I might want the symbol to apply to the find or the exec commands on different occasions?

  2. On the same theme, what is the syntax if I want to use tee to view the output of the -exec commands on the console (to watch progress) and also appended to a file (for later use)?

(I know shells vary but hopefully the most used shells such as sh/csh are quite similar?)

Update:

In part, I want to learn if nested find -exec can be done without scripting, as a simple command. Here is the use-case that prompted the questio :

  • outer find: find all subdirs matching DIR_MATCH_TEXT in DIR1
  • inner find: for each matching subdir found in the outer loop (call it DIR2), execute the command
    find DIR2 -name "FILE_MATCH_TEXT" -exec sha1 {} \; >> DIR1/DIR2_hashes.txt

The aim being to create a set of files, one for each matching subdir, containing the output of some find -exec action on that subdir.

By this I mean that, if /backups contains /jan2017 and /feb2017, the result will be two files at /backups/jan2017_hashes.txt and /backups/feb2017_hashes.txt, with jan2017_hashes.txt containing the output from sha1 for (say) all .pdf files in /backups/jan2017, and feb2017_hashes.txt containing the output from sha1 for all .pdf files in /backups/feb2017.

From replies so far I gather the outer find would have to use a shell call as the argument to -exec?

added 56 characters in body
Source Link
Stilez
  • 1.3k
  • 19
  • 32

I'm using find with the -exec option in console, on FreeBSD (for example, find . -exec sha1 {} \;).

  1. How do I correctly place (and if needed, escape) redirect and other execution control symbols that could syntactically apply to either of the exec command or the find command, such as > >> | and which&, where I might want the symbol to apply to onethe find or the other, such as > >> | and & exec commands on different occasions?

  2. On the same theme, what is the syntax if I want to use tee to view the output of the -exec commands on the console (to watch progress) and also appended to a file (for later use)?

(I know shells vary but hopefully the most used shells such as sh/csh are quite similar?)

I'm using find with the -exec option in console, on FreeBSD (for example, find . -exec sha1 {} \;).

  1. How do I correctly place (and if needed, escape) redirect and other execution control symbols that could syntactically apply to the exec command or the find command, and which I might want to apply to one or the other, such as > >> | and & ?

  2. On the same theme, what is the syntax if I want to use tee to view the output of the -exec commands on the console (to watch progress) and also appended to a file (for later use)?

(I know shells vary but hopefully the most used shells such as sh/csh are quite similar?)

I'm using find with the -exec option in console, on FreeBSD (for example, find . -exec sha1 {} \;).

  1. How do I correctly place (and if needed, escape) redirect and other execution control symbols that could syntactically apply to either of the exec command or the find command, such as > >> | and &, where I might want the symbol to apply to the find or the exec commands on different occasions?

  2. On the same theme, what is the syntax if I want to use tee to view the output of the -exec commands on the console (to watch progress) and also appended to a file (for later use)?

(I know shells vary but hopefully the most used shells such as sh/csh are quite similar?)

Source Link
Stilez
  • 1.3k
  • 19
  • 32

Correct location for piping and redirecting output in find -exec?

I'm using find with the -exec option in console, on FreeBSD (for example, find . -exec sha1 {} \;).

  1. How do I correctly place (and if needed, escape) redirect and other execution control symbols that could syntactically apply to the exec command or the find command, and which I might want to apply to one or the other, such as > >> | and & ?

  2. On the same theme, what is the syntax if I want to use tee to view the output of the -exec commands on the console (to watch progress) and also appended to a file (for later use)?

(I know shells vary but hopefully the most used shells such as sh/csh are quite similar?)