Skip to main content
Added -- to prevents ACE vulnerabilities as suggested by Stéphane
Source Link
raf
  • 170
  • 1
  • 8

Disclaimer: I'm the current author of rawhide (rh) (see github.com/raforg/rawhide).

With rawhide (rh) you can do:

rh /movies 'd && !empty && "[ -n \"$(rh -ref -- %S)\" ]".sh' 

/movies is a path to search.

The rest is the search criteria:

d means it's a directory.

!empty means it's not empty. This isn't needed but it makes it faster by reducing the number of shell processes created by the next bit.

"[ -n \"$(rh -ref -- %S)\" ]".sh runs the shell command [ -n "$(rh -ref -- %S)" ] which checks if there are any regular files in the candidate directory (with a nested use of rh).

rh -ref -- %S is short for rh -r -e f -- %S.

The -r is like find's -mindepth 1 -maxdepth 1 to only search one level down.

The -e f specifies the search criteria expression f which matches regular files.

The -- stops command line option parsing so as to prevent any malicious filenames from being interpreted as options to rh (e.g. -xreboot) (thanks Stéphane).

The %S is the name of the current candidate directory that the nested rh needs to search.

The [ -n ... ] tests that the nested rh command produced some output (i.e., that it found some regular files in the candidate directory).

Disclaimer: I'm the current author of rawhide (rh) (see github.com/raforg/rawhide).

With rawhide (rh) you can do:

rh /movies 'd && !empty && "[ -n \"$(rh -ref %S)\" ]".sh' 

/movies is a path to search.

The rest is the search criteria:

d means it's a directory.

!empty means it's not empty. This isn't needed but it makes it faster by reducing the number of shell processes created by the next bit.

"[ -n \"$(rh -ref %S)\" ]".sh runs the shell command [ -n "$(rh -ref %S)" ] which checks if there are any regular files in the candidate directory (with a nested use of rh).

rh -ref %S is short for rh -r -e f %S.

The -r is like find's -mindepth 1 -maxdepth 1 to only search one level down.

The -e f specifies the search criteria expression f which matches regular files.

The %S is the name of the current candidate directory that the nested rh needs to search.

The [ -n ... ] tests that the nested rh command produced some output (i.e., that it found some regular files in the candidate directory).

Disclaimer: I'm the current author of rawhide (rh) (see github.com/raforg/rawhide).

With rawhide (rh) you can do:

rh /movies 'd && !empty && "[ -n \"$(rh -ref -- %S)\" ]".sh' 

/movies is a path to search.

The rest is the search criteria:

d means it's a directory.

!empty means it's not empty. This isn't needed but it makes it faster by reducing the number of shell processes created by the next bit.

"[ -n \"$(rh -ref -- %S)\" ]".sh runs the shell command [ -n "$(rh -ref -- %S)" ] which checks if there are any regular files in the candidate directory (with a nested use of rh).

rh -ref -- %S is short for rh -r -e f -- %S.

The -r is like find's -mindepth 1 -maxdepth 1 to only search one level down.

The -e f specifies the search criteria expression f which matches regular files.

The -- stops command line option parsing so as to prevent any malicious filenames from being interpreted as options to rh (e.g. -xreboot) (thanks Stéphane).

The %S is the name of the current candidate directory that the nested rh needs to search.

The [ -n ... ] tests that the nested rh command produced some output (i.e., that it found some regular files in the candidate directory).

Replace `cmd` with $(cmd)
Source Link
raf
  • 170
  • 1
  • 8

Disclaimer: I'm the current author of rawhide (rh) (see github.com/raforg/rawhide).

With rawhide (rh) you can do:

rh /movies 'd && !empty && "[ -n \"`rh\"$(rh -ref %S`\"%S)\" ]".sh' 

/movies is a path to search.

The rest is the search criteria:

d means it's a directory.

!empty means it's not empty. This isn't needed but it makes it faster by reducing the number of shell processes created by the next bit.

"[ -n \"`rh\"$(rh -ref %S`\"%S)\" ]".sh runs the shell command [ -n "`rh"$(rh -ref %S`"%S)" ] which checks if there are any regular files in the candidate directory (with a nested use of rh).

rh -ref %S is short for rh -r -e f %S.

The -r is like find's -mindepth 1 -maxdepth 1 to only search one level down.

The -e f specifies the search criteria expression f which matches regular files.

The %S is the name of the current candidate directory that the nested rh needs to search.

The [ -n ... ] tests that the nested rh command produced some output (i.e., that it found some regular files in the candidate directory).

Disclaimer: I'm the current author of rawhide (rh) (see github.com/raforg/rawhide).

With rawhide (rh) you can do:

rh /movies 'd && !empty && "[ -n \"`rh -ref %S`\" ]".sh' 

/movies is a path to search.

The rest is the search criteria:

d means it's a directory.

!empty means it's not empty. This isn't needed but it makes it faster by reducing the number of shell processes created by the next bit.

"[ -n \"`rh -ref %S`\" ]".sh runs the shell command [ -n "`rh -ref %S`" ] which checks if there are any regular files in the candidate directory (with a nested use of rh).

rh -ref %S is short for rh -r -e f %S.

The -r is like find's -mindepth 1 -maxdepth 1 to only search one level down.

The -e f specifies the search criteria expression f which matches regular files.

The %S is the name of the current candidate directory that the nested rh needs to search.

The [ -n ... ] tests that the nested rh command produced some output (i.e., that it found some regular files in the candidate directory).

Disclaimer: I'm the current author of rawhide (rh) (see github.com/raforg/rawhide).

With rawhide (rh) you can do:

rh /movies 'd && !empty && "[ -n \"$(rh -ref %S)\" ]".sh' 

/movies is a path to search.

The rest is the search criteria:

d means it's a directory.

!empty means it's not empty. This isn't needed but it makes it faster by reducing the number of shell processes created by the next bit.

"[ -n \"$(rh -ref %S)\" ]".sh runs the shell command [ -n "$(rh -ref %S)" ] which checks if there are any regular files in the candidate directory (with a nested use of rh).

rh -ref %S is short for rh -r -e f %S.

The -r is like find's -mindepth 1 -maxdepth 1 to only search one level down.

The -e f specifies the search criteria expression f which matches regular files.

The %S is the name of the current candidate directory that the nested rh needs to search.

The [ -n ... ] tests that the nested rh command produced some output (i.e., that it found some regular files in the candidate directory).

Source Link
raf
  • 170
  • 1
  • 8

Disclaimer: I'm the current author of rawhide (rh) (see github.com/raforg/rawhide).

With rawhide (rh) you can do:

rh /movies 'd && !empty && "[ -n \"`rh -ref %S`\" ]".sh' 

/movies is a path to search.

The rest is the search criteria:

d means it's a directory.

!empty means it's not empty. This isn't needed but it makes it faster by reducing the number of shell processes created by the next bit.

"[ -n \"`rh -ref %S`\" ]".sh runs the shell command [ -n "`rh -ref %S`" ] which checks if there are any regular files in the candidate directory (with a nested use of rh).

rh -ref %S is short for rh -r -e f %S.

The -r is like find's -mindepth 1 -maxdepth 1 to only search one level down.

The -e f specifies the search criteria expression f which matches regular files.

The %S is the name of the current candidate directory that the nested rh needs to search.

The [ -n ... ] tests that the nested rh command produced some output (i.e., that it found some regular files in the candidate directory).