LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 08-23-2012, 02:51 AM   #1
prasanth.george
LQ Newbie
 
Registered: Jan 2011
Location: bangalore
Distribution: rhel,ubuntu,centos
Posts: 27

Rep: Reputation: 0
List all files containing a particular number in it


Goodmorning friends,

i looking for the command to list all the files in a partiuclar location which is having a specific number , eg:5678.could you help me?
 
Old 08-23-2012, 02:59 AM   #2
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and Scientific Linux
Posts: 5,753

Rep: Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288
Hi,

this sounds like a job for grep. Eg to check all the files in the current directory:
Code:
grep -l 5678 *
Evo2.
 
Old 08-23-2012, 02:59 AM   #3
rosehosting.com
Member
 
Registered: Jun 2012
Posts: 222

Rep: Reputation: 62
Quote:
Originally Posted by prasanth.george View Post
Goodmorning friends,

i looking for the command to list all the files in a partiuclar location which is having a specific number , eg:5678.could you help me?

hi,

you can use

Code:
grep -rwl '5678' /path/to/dir/
 
Old 08-23-2012, 03:04 AM   #4
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
Quote:
Originally Posted by prasanth.george View Post
Goodmorning friends,

i looking for the command to list all the files in a partiuclar location which is having a specific number , eg:5678.could you help me?
Do you mean that the number is in the content or in the filename?
 
Old 08-23-2012, 03:07 AM   #5
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and Scientific Linux
Posts: 5,753

Rep: Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288
Hi,

pixellany has a good point. If it is the file name you are interested in:
Code:
echo *5678*
Evo2.
 
Old 08-23-2012, 04:56 AM   #6
Mr. Alex
Senior Member
 
Registered: May 2010
Distribution: No more Linux. Done with it.
Posts: 1,238

Rep: Reputation: Disabled
Code:
ls -lha /some/dir *5678*
 
Old 08-23-2012, 02:25 PM   #7
kaldrouby
LQ Newbie
 
Registered: May 2012
Distribution: RHEL 5
Posts: 6

Rep: Reputation: Disabled
i would use this :
ls * | grep 5678*
 
Old 08-23-2012, 05:38 PM   #8
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957
Quote:
Originally Posted by Mr. Alex View Post
Code:
ls -lha /some/dir *5678*
Since globbing patterns are expanded by the shell before the command is executed, ls doesn't do any of the locating work here. The only reason to use it at all is if you want the long-form output. For a simple list, echo is all that's needed.

Use printf to output the files one per line, or with other fancy formatting.


The '-a' option has no meaning here either, since dotfiles aren't expanded by the globbing pattern by default. To get hidden files in your output, enable the dotglob option.

http://mywiki.wooledge.org/glob

Quote:
Originally Posted by kaldrouby
Code:
i would use this :
ls * | grep 5678*
Since ls defaults to all files in the current directory anyway, the "*" is unneeded. And in order to be read properly by grep, you'd need to use the "-1" ("one", not "el") option to print one file per line (and even that would fail if the filenames themselves had newlines in them).

You also have the grep pattern wrong, since it uses regular expressions, not globbing (which, incidentally you would have to quote first to protect from shell expansion anyway). You only need to use "grep 5678".

But why bother with all this anyway, when globbing is easier, safer, and lighter (no external commands needed, and unusual characters can't mess it up)?
 
1 members found this post helpful.
Old 08-24-2012, 12:45 AM   #9
prasanth.george
LQ Newbie
 
Registered: Jan 2011
Location: bangalore
Distribution: rhel,ubuntu,centos
Posts: 27

Original Poster
Rep: Reputation: 0
Thanks buddy, it really worked.........Excellent help.

i think my question was not that clear to everyone ,iam really sorry for that.
Appreciate you for understanding my actual requirement.





Quote:
Originally Posted by rosehosting.com View Post
hi,

you can use

Code:
grep -rwl '5678' /path/to/dir/
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] subtraction a list of number mmhs Linux - Newbie 8 03-18-2012 12:53 AM
List directories and number of files inside them. arizonagroovejet Linux - General 4 03-20-2011 11:33 AM
[SOLVED] How to list folder size, and number of files and folders in folder steven.c.banks Linux - General 3 11-24-2010 07:24 AM
how to list the number of files in serveral sub-directories cy163 Linux - Newbie 2 05-16-2009 12:29 PM
Command to list total number of files. WillieB_72 Linux - General 3 01-29-2003 10:25 PM


All times are GMT -5. The time now is 01:04 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration