- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Keep find within a single directory
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-22-2005 04:26 AM
тАО12-22-2005 04:26 AM
All the solution I find say to use find then pipe or -xargs the find output to grep -l -E
That does work, but it has two problems.
First, it returns ./
But second and worse, find wants to drill down to lower subdirectories. I only want to return files from the single directory where I'm searching.
I've tried the -prune and -xdev options for find, but none effectively stop the subdirectories from being included in the search.
Is there any way to keep find in a single directory, or an alternative to using find to fix the original grep "paramter list too long" problem?
Thanks,
Jim
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-22-2005 04:34 AM
тАО12-22-2005 04:34 AM
Re: Keep find within a single directory
Another option would be to put your file list in a variable (could be read in from a file or from output of an ls command of some sort) and do a for loop that would grep each file individually.
Jeff Traigle
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-22-2005 04:35 AM
тАО12-22-2005 04:35 AM
Re: Keep find within a single directory
ll | grep "^\-"| awk '{print $NF}' | xargs
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-22-2005 04:38 AM
тАО12-22-2005 04:38 AM
Re: Keep find within a single directory
Pete
Pete
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-22-2005 04:46 AM
тАО12-22-2005 04:46 AM
SolutionThe key is to leverage both the '-path' and the '-prune' options of 'find':
# find /home/jrf -path "/home/jrf/*" -prune -type f -exec grep "ARY" /dev/null {} \;
...would search for files in '/home/jrf' without descent into subdirectories, and 'grep' for the pattern "ARY". All occurances found would be printed with the filename in front.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-22-2005 04:59 AM
тАО12-22-2005 04:59 AM
Re: Keep find within a single directory
The -prune and -path options did the trick to restrict the find command to the current directory:
cd
find . -path "./*" | xargs grep -l -E
I'll also try the ls suggestion.
Thanks!
Jim
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-22-2005 02:32 PM
тАО12-22-2005 02:32 PM
Re: Keep find within a single directory
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-22-2005 06:55 PM
тАО12-22-2005 06:55 PM
Re: Keep find within a single directory
# ls -l | awk '/^-/ { print $9; }'
To grep into the file with find command then use syntax as,
# find
or
# find
There is another problem in your requiremnet. Grep will create messy messages when grepping with binary file??
You can remove that with file option as,
for file `find
do
file $file | grep -q 'executable'
if [[ $? -ne 0 ]]
then
grep 'pattern' ${file}
fi
done
-Muthu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-22-2005 08:11 PM
тАО12-22-2005 08:11 PM
Re: Keep find within a single directory
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-26-2005 05:01 PM
тАО12-26-2005 05:01 PM
Re: Keep find within a single directory
The first ls suggestion didn't work well, but the find suggested by James Ferguson got implemented in my app easily.
The app itself is a Java UI running on a Windows server that connects to HP-UX data via CIFS. Searches over the CIFS connection for files with specific content were simply impossible using any Windows search tool (and we tried almost a dozen), so my Java app constructs a short Unix script, sends it to the HP-UX server, executes it, collects the results (they were piped to a file), and reformats into a simple Java grid table for file name, date, size, path, etc.
It now works with larger directory sizes thanks to using the find command.
Thanks again to everyone for the prompt replies plus options in case one didn't work!
Jim