move files with specific name

NewtonianB
NewtonianB used Ask the Experts™
on
How do I execute a one line command to move all files in the current directory (that have only numbers in their names) to another directory?

1244.pdf
2311.pdf
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2007
Commented:
If the files have 4 digits, then

mv [0-9][0-9[0-9][0-9].pdf /some/other/directory

Author

Commented:
nice, how can I make it dynamic though so it works with both any number of digits?
Top Expert 2007
Commented:
ls | grep -E "[0-9][0-9]*[0-9]" | xargs -i mv {} /some/other/directory
Top Expert 2007

Commented:
or you can do

mv [0-9]*[0-9].pdf /some/other/directory

if you *don't* have filenames like

123abc456.pdf

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial