Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

List only certain files in a directory matching the word BOZO and ending with either '123' or '456'

Tags:

grep

find

unix

ls

I'm trying to figure out how to get a list of file names for a file named BOZO but ending with ONLY 123 OR 456.

Files are:

BOZO12389,
BOZOand3
BOZOand456
BOZOand5
BOZOhello123

So the command should only display 'BOZOhello123' and 'BOZOand456'

I can't figure it out. I've tried all forms of LS and GREP that I can think of. The funny thing is, we tried to do it in class for about 10mins and no one could get it (including the instructor).

like image 483
Geordie Avatar asked Jun 14 '11 19:06

Geordie


2 Answers

I did the following and it worked

ls BOZO*456 BOZO*123
like image 121
dave Avatar answered Oct 25 '22 02:10

dave


Using shell's globs:

ls BOZO*{123,456}
like image 39
ninjalj Avatar answered Oct 25 '22 04:10

ninjalj