BASH mv *.nii all but 1999.nii ??
So Lets say I have this files in a folder:
123.nii 132.nii 343.nii 454.nii 666.nii 767.nii . . . I want to move all the one in *.nii to a different folder but 666.nii ? mv ./*.nii /<OTHER LOCATION> but 666.nii?? How do I do it? |
I'm sure there's a single command that could do this with ease, probably using some combination of find with "! -name", but whenever I need to do this I just go the simple route
Code:
mkdir temp |
for f in *.nii;do [ "${f}" != "666.nii" ] && mv ${f} <destination>;done
Proof of concept, using rm instead of mv: Code:
$ for ((i=1;i<10;++i)) do touch ${i}${i}${i}.nii;done Warning: The code above assumes that none of the .nii file names contain any character listed in ${IFS}. (e.g., blank, etc.) <edit> This should also work: find ./ -maxdepth 1 -name '*.nii" ! -name '666.nii' -exec mv '{}' <destination> ';' and, by removing the -maxdepth 1 directive, you could apply the logic to your current directory and all subdirectories of it. </edit> <edit2> Another thought: If your directory only contains *.nii files, you could rename the directory (mv can do that), and then recreate the directory and move the file(s) you want back into it. </edit> |
Code:
shopt -s extglob |
Looking for the single command...but thanks for your suggestions :)
, shopt -s extglob? What is that? |
enabling extended globing support. shopt allows changing the default options. It happens to be a built in command to bash.
|
Quote:
Code:
setopt extendedglob |
All times are GMT -5. The time now is 10:31 PM. |