0

私はこのファイル構造を持っています

user@laptop:/my/folder$ ls
control       changelog  patches   postrm  source
copyright.in  mime       postinst  rules

名前にドットを含まないすべてのファイルをリストしたい。grep を使用したくありません。逆は次のようになります。

user@laptop:/my/folder$ ls *[.]*
copyright.in

しかし、目標を達成するために否定 (^ または !) を追加しようとすると、うまくいきません。

user@laptop:/my/folder$ ls *[^.]*
control  copyright.in  changelog  mime  postinst  postrm  rules

patches:
series                                      03-include-unistd-for-kfreebsd
01-manpages-in-section-1-not-in-section-1l  04-unzip60-alt-iconv-utf8
02-branding-patch-this-is-debian-unzip      04-unzip60-alt-iconv-utf8~

source:
format

出力には copyright.in がリストされていますが、これは私が望むものではありません。私が書くときは?? * の代わりに動作します。

user@laptop:/my/folder$ ls *[^.]??
control  changelog  mime  postinst  postrm  rules

patches:
series                                      03-include-unistd-for-kfreebsd
01-manpages-in-section-1-not-in-section-1l  04-unzip60-alt-iconv-utf8
02-branding-patch-this-is-debian-unzip      04-unzip60-alt-iconv-utf8~

source:
format

グロビングを使用して、名前にドットを付けずにディレクトリ内のファイルのリストを作成する方法を知っている人はいますか?

4

1 に答える 1

2

(最後の回答で申し訳ありません、私は質問を完全に読み違えました。)

使用できますgrep

[me@localhost ~]$ ls | grep -v '\.'

またはfind:

[me@localhost ~]$ find . -maxdepth 1 -not -name '*\.*' -printf '%f\n'

またはさらにls

[me@localhost ~]$ ls -1I '*.*'

すべてが同じ出力を生成します。( -1inlsは必要ありません。出力が他の 2 つのコマンドと同じになるように、1 行に 1 つのファイル名を強制するだけです。)

于 2014-03-04T16:18:23.277 に答える