0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

find: warning: you have specified the -maxdepth option after a non-option argument -type, but options are not positionalとなった時の対応方法

Posted at
  • 環境
    • CentOS Linux release 7.6.1810 (Core)
    • find (GNU findutils) 4.5.11

事象 : findに-maxdepthオプションをつけたらなんか注意された

$ find -type d -maxdepth 2
find: warning: you have specified the -maxdepth option after a non-option argument -type, but options are not positional (-maxdepth affects tests specified before it as well as those specified after it).  Please specify options before other arguments.

.
./.settings
./src
./src/main
./src/test
./target
./target/classes
$

原因 : オプションの指定順序を間違えているから

注意文を訳してみた。やりたい気持ちの強い順にオプションを指定すればいいわけではない。

find:警告:オプションではない引数-typeの後に-maxdepthオプションを指定しましたが、オプションの位置が正しくありません(-maxdepthは、前に指定されたテストと後に指定されたテストに影響します。)。他の引数の前にオプションを指定してください。

使い方を見てみるとちゃんと「他の式の前に指定」って書いてある。

$ find --help
Usage: find [-H] [-L] [-P] [-Olevel] [-D help|tree|search|stat|rates|opt|exec] [path...] [expression]
...省略...
# normal options (always true, (訳)他の式の前に指定):
normal options (always true, specified before other expressions):
      -depth --help -maxdepth LEVELS -mindepth LEVELS -mount -noleaf
      --version -xautofs -xdev -ignore_readdir_race -noignore_readdir_race

tests (N can be +N or -N or N): -amin N -anewer FILE -atime N -cmin N
      -cnewer FILE -ctime N -empty -false -fstype TYPE -gid N -group NAME
      -ilname PATTERN -iname PATTERN -inum N -iwholename PATTERN -iregex PATTERN
      -links N -lname PATTERN -mmin N -mtime N -name PATTERN -newer FILE
      -nouser -nogroup -path PATTERN -perm [-/]MODE -regex PATTERN
      -readable -writable -executable
      -wholename PATTERN -size N[bcwkMG] -true -type [bcdpflsD] -uid N
...省略...

対応 : -typeの前に-maxdepthを指定する

注意されなくなった
$ find -maxdepth 2 -type d
.
./.settings
./src
./src/main
./src/test
./target
./target/classes
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?