LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-20-2013, 06:37 AM   #1
hitesh_ingole2000
LQ Newbie
 
Registered: Apr 2013
Posts: 6

Rep: Reputation: Disabled
Question Find coommand does not include the hidden folder for searching


The scenario is as below
/abc/xyz/
The folder xyz folder contains .A,.B,C
where A and B are hidden folders
all the folders contain file ending with T
The command which iam using is

find /abc/xyz/* |grep "T$"
/abc/xyz/C/slpT
/abc/xyz/C/polT

now i only get file from C and not from .A and .B that is the hidden folders are excluded
 
Old 05-20-2013, 06:56 AM   #2
mina86
Member
 
Registered: Aug 2008
Distribution: Debian
Posts: 517

Rep: Reputation: 229Reputation: 229Reputation: 229
First of all, do not use grep, but “-name \*T”. Second of all, it's not find that is skipping hidden directories, but shell when you pass “/abc/xyz/*”. Instead, just do:
Code:
find /abc/xyz -name \*T
 
1 members found this post helpful.
Old 05-21-2013, 11:07 AM   #3
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
The basic syntax for find is this:

Code:
find <start_dirs> <global_opts> <matching_opts> <actions>
Note that you should give it directories to start from, not files (If you already know where the files are, why would you need find?). And the use of "*" style shell globbing patterns will usually expand into a list of files (and/or directories) before the command is run.

Note too that find's -name matching option and its relatives also use globbing patterns, which need to be escaped by quotation marks or backslashes so that the shell doesn't try to interpret them first.

Here are a couple of good links about using find:
http://mywiki.wooledge.org/UsingFind
http://www.grymoire.com/Unix/Find.html

Finally, if you don't need to search recursively, and just need to match files by names only, shell globbing will be faster and more efficient than find. You can enable the dotglob shell option to match hidden files, and use a simple echo or printf for printing, if you just want to list them.

Code:
shopt -s dotglob nullglob
printf '%s\n' /abc/xyz/.[AB]/*T /abc/xyz/C/*T

shopt -s dotglob nullglob extglob
printf '%s\n' /abc/xyz/*(.)[ABC]/*T
The second one uses bash's extended globbing for greater brevity.
 
Old 05-21-2013, 12:26 PM   #4
mina86
Member
 
Registered: Aug 2008
Distribution: Debian
Posts: 517

Rep: Reputation: 229Reputation: 229Reputation: 229
Quote:
Originally Posted by David the H. View Post
Note that you should give it directories to start from, not files (If you already know where the files are, why would you need find?).
There are uses of find with files given on command line. For instance, having a list of files, delete those created more than a week ago.
 
Old 05-21-2013, 01:25 PM   #5
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
Yes, indeed. I'm aware of that. You can run files through it if you want to evaluate them according to some criterion that find is good at. But that's a relatively rare exception to the rule, and not what the OP was asking about.

I'd probably recommend using a shell loop and tests instead such cases anyway, depending on the exact circumstances of the operation.
 
Old 05-22-2013, 04:03 AM   #6
mina86
Member
 
Registered: Aug 2008
Distribution: Debian
Posts: 517

Rep: Reputation: 229Reputation: 229Reputation: 229
Granted, but “you should give it directories” sounds too me as a bit of a strong statement. “you usually give it directories” would sound better.
 
  


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
find hidden files from wild card path using 'find' nagendrar Linux - Newbie 5 10-13-2011 10:48 PM
searching network for hidden IP cams Lemmingz Linux - Software 5 02-18-2011 06:51 AM
[SOLVED] help abt ll coommand keimasi Linux - Desktop 3 01-04-2011 11:18 AM
rsync - How to Include Hidden (.something) Files and Directories? edwin11 Linux - Software 4 11-29-2006 07:47 AM
How to transfer file to hidden folder Brosky SUSE / openSUSE 4 02-27-2005 03:29 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:35 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