Here is the line:
find /localdir/ | grep '[0-9']$ | xargs -i% cp % /tftpboot
I specifically want to know what grep is looking for exactly here.
Can anyone translate it for me please ?
I am also kind of interested in what the xargs cmd is going to look like…
Thanks in advance.
[0-9]means any character from0through9.$means the end of a line. So yourgrepwill find any line (i.e., filename) that ends with a digit, andxargswill copy them each to/tftpboot.Of course, you’ll have some surprises if any of those filenames contain spaces. You can do this entirely within the shell in zsh (and I think in recent versions of bash):
addendum: If you’re asking about the funny quoting, that will work, though it’s not very human-friendly.
The key is that you can have quoted strings and non-quoted strings right next to each other in shell, and they’ll become a single string;
echo "fo"ob'ar'will producefoobar.The first part is quoted because
[is special to bash.]is also special, but since bash never saw a special (unquoted)[, it leaves the]alone.$would normally substitute a variable, but nothing comes after it, so bash leaves that alone too.The string that actually gets passed to grep is still
[0-9]$.