0

I'm using the below command but it is not working

find . PYRLLPS_GL_201610D2* -maxdepth 1 -mtime -30

I get the below error

find: bad option -maxdepth
find: [-H | -L] path-list predicate-list
Dhivya
  • 21
  • Btw. you may want to use find . -name 'PYRLLPS_GL_201610D2*' … instead. Without -name the shell has to read the current directory, expand the glob expression, pass all results to find, which in turn will filter for modification time. With -name, find will take care of everything, and no potentially large argument list needs to be passed around. – johnLate Apr 20 '16 at 14:49

2 Answers2

0

-maxdepth is not specified by POSIX. It appears your version of find doesn't support that primary.

Ways to accomplish the same effect using only POSIX options are discussed here:


Also, it's unclear what you're trying to do but you may have the usage of find itself confused:

If you are trying to find all files with names that start with PYRLLPS_GL_201610D2, you should be using the -name operator, and protecting the pattern itself from expansion (shell globbing) so that find sees the pattern itself, rather than the pattern being expanded by the shell.

Something like so:

find . -path '*/*/*' -prune -o -name PYRLLPS_GL_201610D2\* -mtime -30 -print

If you are trying to find all files with -mtime -30 that are directly within either the current directory or within one of the PYRLLPS_GL_201610D2* directories in the current directory, then you have the right idea and are just missing the -maxdepth workaround linked above.

Wildcard
  • 36,499
  • I used find . -name PYRLLPS_GL_201610D2* -mtime -60 -print but it lists only one file whereas i have more than one file. I want all the files created or modified in the last 30 days. when i used -30 no output was provided, but i have files in the last 30 days – Dhivya Apr 19 '16 at 08:09
  • @DhivyaBalaPalanisamy, put some `backticks` around your inline code, please. I take it you included the backslash before the *? That part is important. – Wildcard Apr 19 '16 at 08:12
  • Anyway, if you are getting a new error, please edit your question to include the new information. My answer as currently written does explain the error in your original post, and the solution for it. – Wildcard Apr 19 '16 at 08:14
0
find . -maxdepth 1 -name PYRLLPS_GL_201610D2*  -mtime -30

If you want to find file named like PYRLLPS_GL_201610D2AAAA ,you need the code:

find . -maxdepth 1 -name 'PYRLLPS_GL_201610D2*'  -mtime -30
user164825
  • 3,636