LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training 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 05-07-2013, 12:59 AM   #1
computergirl121
LQ Newbie
 
Registered: May 2013
Posts: 24

Rep: Reputation: Disabled
If I don't know what directory a file is located how would I write the command


I am now trying to learn file location and have been watching videos on youtube but I have decided this is not a good idea because I am learning but some of the videos have people that have less knowledge than me. I have learned about a find command that would directly find a file but lets say I have a file that I have no clue what directory it is in how would I locate it? I am not talking about a specific file just any in general file.
Thanks
 
Old 05-07-2013, 01:07 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,

you can still use find: just specify the path as "/". Eg
Code:
find / -name foo.txt
Or use locate (if you have and updatedb run by cron). Eg
Code:
locate foo.txt
Evo2.
 
Old 05-07-2013, 01:11 AM   #3
computergirl121
LQ Newbie
 
Registered: May 2013
Posts: 24

Original Poster
Rep: Reputation: Disabled
What is foo?
 
Old 05-07-2013, 01:16 AM   #4
computergirl121
LQ Newbie
 
Registered: May 2013
Posts: 24

Original Poster
Rep: Reputation: Disabled
OH I am using Fedora. I have Ubuntu on my computer also but I am trying to learn fedora first.
 
Old 05-07-2013, 01:22 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,
Quote:
Originally Posted by computergirl121 View Post
What is foo?
"foo" is a generic placeholder word [1]. "foo.txt" is the file you are looking for in the example.

Evo2.

1. https://en.wikipedia.org/wiki/Foobar
 
Old 05-07-2013, 01:31 AM   #6
computergirl121
LQ Newbie
 
Registered: May 2013
Posts: 24

Original Poster
Rep: Reputation: Disabled
LOL so if I wanted to find a file named hollysdog and I didn't know what directory it was located in I would type find / -hollysdog foo.txt
Then I could find the directory this file is located in? I know this is basic but I have to crawl before I can walk so please bear with me.
 
Old 05-07-2013, 01:45 AM   #7
linux555
LQ Newbie
 
Registered: May 2013
Posts: 14

Rep: Reputation: Disabled
Here are some basics

Code:
find / -iname hollysdog
This will find a file or directory named hollysdog regardless of case. It will match hollysdog whether iit is all lowercase, upper or in between.

Code:
find / -iname "*hollysdog*"
Same as above but it will list all instances of hollysdog. The * is a wildcard for any character(s) before and after hollysdog

If you're looking for file(s) only and want to skip directories add -type f

If you're looking for directories only add -type d

PS: You can start a search from any directory. Just replace / for the desired directory or you can use a (.) period to search from a current directory.

Examples
find /usr/ -iname pattern
find . -iname pattern

Last edited by linux555; 05-07-2013 at 01:52 AM.
 
Old 05-07-2013, 01:46 AM   #8
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,

no, you would do:
Code:
find / -name hollysdog
Evo2.
 
Old 05-07-2013, 01:56 AM   #9
linux555
LQ Newbie
 
Registered: May 2013
Posts: 14

Rep: Reputation: Disabled
@evo2

You are correct and that will find the exact match.

But I use -iname in this example and this will do a case insensitive search of the pattern in case hollysdog is a mixed case of lowercase and uppercase characters

Last edited by linux555; 05-07-2013 at 01:58 AM.
 
Old 05-07-2013, 02:08 AM   #10
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
Quote:
Originally Posted by linux555 View Post
@evo2
You are correct and that will find the exact match.
Gee, thanks... I wrote it assuming I was wrong.

Evo2.
 
Old 05-07-2013, 02:22 AM   #11
linux555
LQ Newbie
 
Registered: May 2013
Posts: 14

Rep: Reputation: Disabled
Well we're both right. If the OP uses -name for exact match search and doesn't yield no results he can then use -iname for case insensitive search. I personally use both where appropriate.

 
Old 05-07-2013, 02:28 AM   #12
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,
Quote:
Originally Posted by linux555 View Post
Well we're both right.
Yes, but so what? I was answering a question from the OP, and then you felt the need to tell me that what I said was correct while sliding in the implication that your answer was superior. You're new to LQ so I'll leave it at that.

Evo2.
 
Old 05-07-2013, 02:42 AM   #13
linux555
LQ Newbie
 
Registered: May 2013
Posts: 14

Rep: Reputation: Disabled
.......

Last edited by linux555; 05-08-2013 at 04:17 PM.
 
Old 05-07-2013, 04:43 AM   #14
AnanthaP
Member
 
Registered: Jul 2004
Location: Chennai, India
Distribution: UBUNTU 5.10 since Jul-18,2006 on Intel 820 DC
Posts: 804

Rep: Reputation: 186Reputation: 186
find has got 3 components.
(1) Find from where?. In this case, find from root and hence /
(2) Find what criterion? lets say the name of the file is hollysdog. Then -name hollysdog . or use -iname hollysdog
(3) Do what? Default is to list the files "found" matching the criterion.

OK
 
Old 05-07-2013, 04:56 AM   #15
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,130
Blog Entries: 2

Rep: Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825
Before we rewrite an entire tutorial for the usage of find I will just give a link to an existing one: http://content.hccfl.edu/pollock/unix/findcmd.htm
 
  


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
Root User using Freshclam command cannot write to directory. swamprat Linux - Newbie 2 01-06-2012 09:43 PM
Why don't I have write privileges on my Wordpress theme directory? davide123 Linux - Software 5 05-22-2011 01:43 PM
CLI - How do i open vedio file with real player which is located in root directory? hulk321 Linux - Software 6 12-01-2008 01:45 PM
How to write crontab to check file size and all file in a directory? modpriest Linux - Newbie 1 02-14-2008 07:48 AM
Processing file located using the FIND command PirateJack Linux - Newbie 2 04-04-2006 12:24 PM


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