So I want to call the mv command on a list of filtered ls results of a directory:
print -l $(ls) | awk '$1 !~ /^A.*/ {print $0}'
Here every filename in my directory not starting with a capital "A" is returned...
Now I want the mv command to be called upon every one of these in order to move them in a directory ./Strings.
My take was adding xargs:
...| xargs -0 mv ./Strings
But this instead ended up in renaming my "Strings"-directory to a combination of every returned filename separated with question marks ("?") - an effect of the -0 null character flag for the xargs command I suppose...
Funnily enough, the wiki on the xargs command (link to the german site here: https://wiki.ubuntuusers.de/xargs/) offers an example-code-snippet to pretty much my question (very similar to my try), but needless to say doesn't solve my problem.
find . -uid 1001 -print | xargs -i mv {} /tmp/Klaus/test
Here it complains about "xargs: illegal option -- i" when I try that in my context:
find . -regex '^[^A].*' -print | xargs -i mv {} ./Strings
I have done some research on my question and what usually pops up is "why can't I pipe find result to ...".
That's why I did not want to leave a suggestion for a solution with the find command and -exec flag, though that didn't lead to my desired result either, unfortunately...:
find . -regex '^[^A].*' -exec mv {} ./Strings +
It's much easier to just do this:
.zshrc
file, add
setopt extendedglob
then restart your shell.^
operator:
mv ^A*(-.) Strings
(-.)
matches plain files or symlinks pointing to plain files. If you don't want the symlinks included, use (.)
instead.⚠️ Note that extended glob syntax is similar to but not exactly the same as regular expression syntax!