2
mv public_html/*.??[g,f] public_html/images/

Could that work? So that all photos/images that have the extensions .jpg, .png, and .gif will be moved.

(I don't have Linux installed and I used an online terminal. Unfortunately, they don't have any photos in their files)

licrux
  • 21

2 Answers2

5

[g,f] matches on either g, , (comma) or f. You'd need [fg] for only f or g.

Now, technically.

mv public_html/*.??[gf] public_html/images/

Would also move a file called foo.x.f as ? also matches a ..

Also, if there was no file matching that pattern, then some shells like bash could move a file called literally *.??[gf] (a bug introduced by the Bourne shell, fixed again in zsh, you can work around it in bash with shopt -s failglob).

So, here for a 3 character extension that ends in f or g, that would be more, but still with that last caveat ([^.] instead of [!.] with some shells):

mv public_html/*.[!.][!.][fg] public_html/images/

For 3 letters:

mv public_html/*.[[:alpha:]][[:alpha:]][fg] public_html/images/

For with jpg, png or gif, with the zsh shell:

mv public_html/*.(jpg|gif|png) public_html/images/

Or with ksh or zsh -o kshglob or bash -O extglob:

mv public_html/*.@(jpg|gif|png) public_html/images/
Sam Denty
  • 103
4

Assuming bash or friends, you can use

mv public_html/*.??[gf] public_html/images/

or, to be more exact with matching

mv public_html/*.{jpg,png,gif} public_html/images/
nohillside
  • 3,251