LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
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, 01: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, 01:59 AM   #2
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and CentOS
Posts: 6,724

Rep: Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705
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, 01:59 AM   #3
rosehosting.com
Member
 
Registered: Jun 2012
Location: Missouri, USA
Posts: 236

Rep: Reputation: 64
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, 02:04 AM   #4
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
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, 02:07 AM   #5
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and CentOS
Posts: 6,724

Rep: Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705
Hi,

pixellany has a good point. If it is the file name you are interested in:
Code:
echo *5678*
Evo2.
 
Old 08-23-2012, 03: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, 01: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, 04:38 PM   #8
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
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-23-2012, 11:45 PM   #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



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-17-2012 11:53 PM
List directories and number of files inside them. arizonagroovejet Linux - General 4 03-20-2011 10: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 06:24 AM
how to list the number of files in serveral sub-directories cy163 Linux - Newbie 2 05-16-2009 11:29 AM
Command to list total number of files. WillieB_72 Linux - General 3 01-29-2003 09:25 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:17 AM.

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
Open Source Consulting | Domain Registration