-3

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.

netDesign8
  • 77
  • 1
  • 8
  • 4
    why don't you investigate (search) for yourself? – KevinDTimm Jan 17 '13 at 19:48
  • 1
    Welcome to Stack Overflow. Please improve your question by posting some [properly formatted](http://stackoverflow.com/editing-help) output from your code and all **relevant** error messages exactly as they appear. Also, make sure to include some samples of what you're testing against. – Todd A. Jacobs Jan 17 '13 at 19:49
  • 1
    did you copy/paste that statement? bc the grep looks wrong. it looks like one of the single quotes is out of place. i'm thinking it should be `grep '[0-9]$'`, which would make Eevee's answer below correct. – nullrevolution Jan 17 '13 at 20:17
  • Yes - I think you are right - I will adjust it and check the results - it was the placement of the single quote that confused me - and led me to ask this question here... Thanks for the feedback – netDesign8 Jan 17 '13 at 20:20

1 Answers1

4

[0-9] means any character from 0 through 9. $ means the end of a line. So your grep will find any line (i.e., filename) that ends with a digit, and xargs will 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):

cp /localdir/**/*[0-9] /tftpboot

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 produce foobar.

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]$.

Eevee
  • 47,412
  • 11
  • 95
  • 127