LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
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 04-22-2009, 08:47 PM   #1
visitnag
Member
 
Registered: Mar 2008
Posts: 147

Rep: Reputation: 15
searching a file in subdirectories with ls


I want to search a file in subdirectories with the command ls -ltr..

i gave the command like ls -ltr filename/* but it did not give any results. What must be the error..
 
Old 04-22-2009, 08:52 PM   #2
billymayday
Guru
 
Registered: Mar 2006
Location: Sydney, Australia
Distribution: Fedora, CentOS, OpenSuse, Slack, Gentoo, Debian, Arch, PCBSD
Posts: 6,678

Rep: Reputation: 122Reputation: 122
That's trying to do an ls on a directory in the current directory called filename.

Are you trying to find a file called filename?

If so, try "find ./ -type f -name filename"
 
Old 04-22-2009, 09:50 PM   #3
visitnag
Member
 
Registered: Mar 2008
Posts: 147

Original Poster
Rep: Reputation: 15
I can do it with find...but somewhere i saw listing required files in subdirectories with ls command...but i failed to recollect that command....
 
Old 04-22-2009, 09:55 PM   #4
billymayday
Guru
 
Registered: Mar 2006
Location: Sydney, Australia
Distribution: Fedora, CentOS, OpenSuse, Slack, Gentoo, Debian, Arch, PCBSD
Posts: 6,678

Rep: Reputation: 122Reputation: 122
Maybe you meant ls -lRt rather than ls -lrt
 
Old 04-23-2009, 12:45 PM   #5
visitnag
Member
 
Registered: Mar 2008
Posts: 147

Original Poster
Rep: Reputation: 15
Nope!! nope!!!

I got it.... if you have some 20 subdirectories under user directory and you know that file1 is created in some of these 20 directories, but you dont know who created... To find this file general methods are...
1 using find command
2 using locate command after updating db

But the simple one is ..... go to the user directory... and type
ls -ltr */file1
this will search all the 20 directories and get the file....

if you have some more subdirectories under 20 directories and the file1 is in these directories..

then type

ls -ltr */*/file1 and so on...
 
  


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
awk searching a string from a file within another file changcheh Linux - Software 7 12-29-2006 10:18 AM
Run script on every file contained within a parent directory and its subdirectories General Programming 4 05-15-2006 03:12 AM
copy a file to all subdirectories in a folder raj000 Linux - General 6 03-24-2006 04:55 AM
How to copy 1 file in 100's of subdirectories oadvantage Linux - Newbie 3 03-15-2006 05:48 PM
monitoring file added to a directory / subdirectories abhi_abhijith Programming 4 02-13-2006 08:25 AM


All times are GMT -5. The time now is 11:09 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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration