What is the command to move the all files to target directory except *.trg files?
Tried the below command but it's not working:
mv !(*.trg) tgtdir
What is the command to move the all files to target directory except *.trg files?
Tried the below command but it's not working:
mv !(*.trg) tgtdir
You have an extended glob pattern, !(*.trg), which will only work if the extglob shell option is enabled.
As the output of shopt extglob shows:
extglob off
you don't have the option enabled.
So you need to enable extglob by:
shopt -s extglob
Then your command should work.
Also, your command can be made more compact by:
mv -t tgtdir !(*.trg|tgtdir)
mv: illegal option -- t Usage: mv [-f] [-i] f1 f2 mv [-f] [-i] f1 ... fn d1 mv [-f] [-i] d1 d2
– Prasath May 30 '16 at 07:16Use find with a negated -name argument:
find . ! -name '*.trg' ! -name . -maxdepth 1 -exec mv {} <tgtdir> \;
! -name . excludes current directory and -maxdepth 1 assures only files and directories in the current one will be in the search results.
Just like with plain mv, depending on where your tgtdir exists you might need to exclude it too.
extglobenabled? Whats the output ofshopt extglob? – heemayl May 30 '16 at 06:43extglob off
– Prasath May 30 '16 at 07:03