Regex 如何使用grep获取某些文件名?

Regex 如何使用grep获取某些文件名?,regex,bash,shell,unix,grep,Regex,Bash,Shell,Unix,Grep,我在某个目录中有这样的文件: my@unix:~/kys$ ls address_modified_20130312.txt customer_rows_full_20131202.txt customer_full_20131201.txt customer_rows_modified_20131202.txt customer_modified_20131201.txt my@unix:~/kys$ 我想使用grep获取某些以单词“customer”开头的文件名。我试过这个

我在某个目录中有这样的文件:

my@unix:~/kys$ ls
address_modified_20130312.txt   customer_rows_full_20131202.txt
customer_full_20131201.txt      customer_rows_modified_20131202.txt
customer_modified_20131201.txt
my@unix:~/kys$ 
我想使用grep获取某些以单词“customer”开头的文件名。我试过这个

my@unix:~/kys$ ls | grep customer.*
customer_full_20131201.txt
customer_modified_20131201.txt
customer_rows_full_20131202.txt
customer_rows_modified_20131202.txt
my@unix:~/kys$
但这给了我这些我不想要的customer_行。*文件。正确的结果集是

customer_full_20131201.txt
customer_modified_20131201.txt
如何实现这一点?

您可以尝试:

ls customer_[fm]*

您可以尝试:

ls customer_[fm]*

您可以尝试:

ls customer_[fm]*

您可以尝试:

ls customer_[fm]*


使用
grep-v
过滤掉你不想要的东西

ls customer* | grep -v '^customer_rows'

使用
grep-v
过滤掉你不想要的东西

ls customer* | grep -v '^customer_rows'

使用
grep-v
过滤掉你不想要的东西

ls customer* | grep -v '^customer_rows'

使用
grep-v
过滤掉你不想要的东西

ls customer* | grep -v '^customer_rows'

使用
grep

ls -1 | grep "^customer_[^r].*$"
使用
find
命令

find . \! -iname "customer_rows*"

使用
grep

ls -1 | grep "^customer_[^r].*$"
使用
find
命令

find . \! -iname "customer_rows*"

使用
grep

ls -1 | grep "^customer_[^r].*$"
使用
find
命令

find . \! -iname "customer_rows*"

使用
grep

ls -1 | grep "^customer_[^r].*$"
使用
find
命令

find . \! -iname "customer_rows*"

使用Bash扩展的globbing,您可以说

ls customer_!(rows)*
for f in customer_*; do
    case $f in customer_rows* ) continue ;; esac
    : something with "$f"
done
或者,更可能的是,类似于

for f in customer_!(rows)*; do
    : something with "$f"
done
对于POSIX shell或传统Bourne,您可以说

ls customer_!(rows)*
for f in customer_*; do
    case $f in customer_rows* ) continue ;; esac
    : something with "$f"
done

使用Bash扩展的globbing,您可以说

ls customer_!(rows)*
for f in customer_*; do
    case $f in customer_rows* ) continue ;; esac
    : something with "$f"
done
或者,更可能的是,类似于

for f in customer_!(rows)*; do
    : something with "$f"
done
对于POSIX shell或传统Bourne,您可以说

ls customer_!(rows)*
for f in customer_*; do
    case $f in customer_rows* ) continue ;; esac
    : something with "$f"
done

使用Bash扩展的globbing,您可以说

ls customer_!(rows)*
for f in customer_*; do
    case $f in customer_rows* ) continue ;; esac
    : something with "$f"
done
或者,更可能的是,类似于

for f in customer_!(rows)*; do
    : something with "$f"
done
对于POSIX shell或传统Bourne,您可以说

ls customer_!(rows)*
for f in customer_*; do
    case $f in customer_rows* ) continue ;; esac
    : something with "$f"
done

使用Bash扩展的globbing,您可以说

ls customer_!(rows)*
for f in customer_*; do
    case $f in customer_rows* ) continue ;; esac
    : something with "$f"
done
或者,更可能的是,类似于

for f in customer_!(rows)*; do
    : something with "$f"
done
对于POSIX shell或传统Bourne,您可以说

ls customer_!(rows)*
for f in customer_*; do
    case $f in customer_rows* ) continue ;; esac
    : something with "$f"
done