我在製作bash腳本;如何找到不以特定擴展名結尾的文件?查找不以特定擴展名結尾的文件
#!/bin/bash
find . -type f -print | grep "\.\(?!psd\|xcf\).+$"
謝謝。
我在製作bash腳本;如何找到不以特定擴展名結尾的文件?查找不以特定擴展名結尾的文件
#!/bin/bash
find . -type f -print | grep "\.\(?!psd\|xcf\).+$"
謝謝。
您可以使用:
find . -regextype posix-egrep -type f ! -regex '.*\.(psd|xcf)$'
或者沒有正則表達式:關於使用找到的 - 而不是參數
find . -type f -not \(-name '*.psd' -o -name '*.xcf' \)
您可以使用grep的-v
PARAM這樣的:
find . -type f -print | grep -v "${NOT_PATTERN}"
所以,你的情況,你可以使用:
find . -type f -print | grep -v "\.\(psd|xcf\)$"
文檔
-v,--invert-匹配 反轉匹配的意義,選擇不匹配的行。
真的應該有一個像「'\。\(psd | xcf \)$」' – dawg
@dawg這樣的結尾處的錨,非常感謝評論,現在已經修復。 –
什麼? – JiriS