LinuxQuestions.org
Help answer threads with 0 replies.
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 11-29-2010, 06:55 AM   #1
geekpie
LQ Newbie
 
Registered: Oct 2006
Posts: 24

Rep: Reputation: 0
finding all files starting with a .


To find all files recursively starting with a . (period), is the following OK:

find ./ -name '.'*

Thanks in advance
 
Old 11-29-2010, 07:12 AM   #2
tronayne
Senior Member
 
Registered: Oct 2003
Location: Northeastern Michigan, where Carhartt is a Designer Label
Distribution: Slackware 32- & 64-bit Stable
Posts: 3,007

Rep: Reputation: 742Reputation: 742Reputation: 742Reputation: 742Reputation: 742Reputation: 742Reputation: 742
You can try
Code:
find . -name '.*'
The syntax is find path [options] pattern; the dot is current directory (you don't need the slash but it doesn't hurt either). Pretty much always a good idea to enclose the pattern in quotes.

Oops, forgot... you can also isolate name of files and directories; i.e., you may only want files or only want directories, so
Code:
find . -type f -name '.*'          files
or
find . -type d -name '.*'          directories
Hope this helps some.

Last edited by tronayne; 11-29-2010 at 07:19 AM.
 
1 members found this post helpful.
Old 11-30-2010, 04:43 AM   #3
geekpie
LQ Newbie
 
Registered: Oct 2006
Posts: 24

Original Poster
Rep: Reputation: 0
Thanks: I see that does work: I tried it.

However, I don't understand why it works. Don't the single quotes around '.*' stop the shell doing any expansion, ie make it look for the string literal .*

?
 
Old 11-30-2010, 07:47 AM   #4
tronayne
Senior Member
 
Registered: Oct 2003
Location: Northeastern Michigan, where Carhartt is a Designer Label
Distribution: Slackware 32- & 64-bit Stable
Posts: 3,007

Rep: Reputation: 742Reputation: 742Reputation: 742Reputation: 742Reputation: 742Reputation: 742Reputation: 742
Are quotes always necessary? Nope. But quotes are used to isolate the pattern from any possible shell expansion.

In this case, if you simply did
Code:
find . -type f -name .*
You'd get
Code:
Usage: find [-H] [-L] [-P] [-Olevel] [-D help|tree|search|stat|rates|opt|exec] [path...] [expression]
It more or less never hurts to enclose an expression in quotes so you don't have unexpected results (and, if you're using an asterisk in an expression like the above, you have to).

Can't hurt, probably will help.

Hope this helps some.
 
Old 12-01-2010, 06:40 AM   #5
geekpie
LQ Newbie
 
Registered: Oct 2006
Posts: 24

Original Poster
Rep: Reputation: 0
But if quotes stop the shell from doing any expansion, how is the * being expanded in:

find . -type f -name '.*'

Thanks for all help so far by the way.
 
Old 12-01-2010, 07:12 AM   #6
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Servers: Debian Squeeze and Wheezy. Desktop: Slackware64 14.0. Netbook: Slackware 13.37
Posts: 8,528
Blog Entries: 27

Rep: Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176
Quote:
Originally Posted by geekpie View Post
But if quotes stop the shell from doing any expansion, how is the * being expanded
find is using it as a match pattern (not expanding it) -- which is what you want.
 
Old 12-01-2010, 08:24 AM   #7
tronayne
Senior Member
 
Registered: Oct 2003
Location: Northeastern Michigan, where Carhartt is a Designer Label
Distribution: Slackware 32- & 64-bit Stable
Posts: 3,007

Rep: Reputation: 742Reputation: 742Reputation: 742Reputation: 742Reputation: 742Reputation: 742Reputation: 742
Some things that may come in handy someday are a little more sophisticated match patterns; as you know, the asterisk will match anything for any length. What if you want to find file (or directory) names that begins with (or ends with) a particular letter or digit?

Those patterns are [A-Z]* to match all upper case letters or [A-Z,a-z]* to match both upper- and lower case letters. A particular letter is matched [A]* (or simply A*) and a group of particular letters are matched by [ACZ]*; i.e., a name beginning with A, C or Z. Same with numbers; [0-9]*, [123]* and so on. You can go crazy and look for all file (directory) names that begin with a, b, or c followed by any digit with [abc][0-9]*.

The above also works at the end of a pattern; e.g., *[A-Z].

If you want to find a particular pattern anywhere in a name, *stuff* will find stuff, stuffandnonsense, nonsenseandstuff and so on.

And, as kindly pointed out by catkin, to prevent shell expansion, all enclosed in quotes.

Hope this helps some.
 
Old 12-02-2010, 04:05 AM   #8
geekpie
LQ Newbie
 
Registered: Oct 2006
Posts: 24

Original Poster
Rep: Reputation: 0
OK Thanks: plenty to think about and try out there.
 
  


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
Finding multiple files with ascending numerical files extensions unim21 Linux - Newbie 3 04-23-2009 07:50 PM
when finding files in Konqueror, why use the files index? newbiesforever Linux - General 4 03-20-2009 09:06 AM
Finding files and then finding content within those files... Maeltor Linux - Software 5 03-13-2007 12:06 PM
XFree4 not finding my mouse and not starting!? silex_88 Linux - Software 8 10-03-2006 12:56 AM
Newbie trouble finding/starting x General Dude Debian 11 02-29-2004 08:53 PM


All times are GMT -5. The time now is 10:58 PM.

Main Menu
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