Sasi Kathimanda
Sasi Kathimanda

Reputation: 1806

exclude files with specific starting characters bash using regex

"/home/shell/DELETE-ME-*" which includes all the files that starts with DELETE-ME- in shell directory.

In the same fashion, would like to excludes all the files that starts with DELETE-ME- tried ^[DELETE-ME-] ,^[DELETE-ME-*] , but haven't worked.

Upvotes: 2

Views: 118

Answers (2)

anishsane
anishsane

Reputation: 20970

Looks like a job for extglob

shopt -s extglob
echo !(DELETE-ME-*) # change echo to your actual command...
shopt -u extglob

Upvotes: 0

anubhava
anubhava

Reputation: 784898

How about using grep -v:

printf "%s\n" /home/shell/* | grep -v '/DELETE-ME-'

OR using find:

find /home/shell  -maxdepth 1 -type f ! -name "DELETE-ME-*"

Upvotes: 1

Related Questions