Lin Chen
Lin Chen

Reputation: 173

How to mv all files under a folder exclude some specify files

I'm using MACOS and want to use mv command to move all *.csv file from folder /Users/abc/Downloads/ to /Users/abc/idea-workspace/tofolder/csvfiles. But I need to exclude any file name contains "(" such as "filename(1).csv". These files are duplicate download files. So I don't like to move them into /tofolder/csvfiles. My question is how to exclude these file contains "(". thanks

I try to use "!()" to exclude these files but not work.Even I have used command before.

shopt -s extglob
mv -f /Users/abc/Downloads/*.csv /Users/abc/idea-workspace/tofolder/csvfiles

Upvotes: 0

Views: 637

Answers (1)

Charles Duffy
Charles Duffy

Reputation: 295726

Demonstrating an extglob that does work:

mkdir -p "/tmp/$$" && cd "/tmp/$$"
touch {foo,bar}{'(1)',}.csv
shopt -s extglob
printf '%q\n' !(*[()]*).csv

...properly emits:

bar.csv
foo.csv

Because you didn't show the extglob that didn't work, we can't speak to why.

Upvotes: 2

Related Questions