Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 09-13-2011, 11:00 AM   #1
LQ Newbie
Registered: Sep 2011
Posts: 3

Rep: Reputation: Disabled
Bash Script to Find 'core' Files in directory

I have wrote my first bash script to find files having word 'core' in their prefix, and list their locations and machine name in which they reside.

This what I have wrote:

find ~/ -name 'core*'

Please let me know if this is right, or is there any better way of doing it.
Thank you in advance.
Old 09-13-2011, 11:17 AM   #2
Registered: Apr 2010
Posts: 33

Rep: Reputation: 2
type 'find ~/ -type f -name "core*" '
1 members found this post helpful.
Old 09-13-2011, 12:18 PM   #3
Senior Member
Registered: Dec 2004
Location: Olympia, WA, USA
Distribution: Fedora, (K)Ubuntu
Posts: 4,186

Rep: Reputation: 347Reputation: 347Reputation: 347Reputation: 347
find ~/ -name core* will find all files under your home directory that start with the string "core."
If you want all such files that contain the string "core," you should use find ~/ -name *core*.

Note that, if you have installed the locate command (which is usually included in most Linux distributions) and run updatedb, you can get the results much faster with the command locate -b \code | grep $HOME. Here's an example:
$ locate -b \core | grep $HOME
/home/Peter/Books/Burroughs, Edgar Rice /At the Earth's Core/ecore11h.htm
/home/Peter/Books/Gutenberg/Gutenberg SF/ecore11.txt
/home/Peter/Books/Gutenberg/Gutenberg SF/ecore11h.htm
/home/Peter/Books/Gutenberg/Gutenberg SF/ecore11l.lit
/home/Peter/Scripts/gawk/Gutenburg/Burroughs, Edgar Rice /At the Earth's Core/ecore11h.htm
/home/Peter/TSS-4/C/C:/Documents and Settings/Administrator.TSS-4/Local Settings/Temporary Internet Files/Content.IE5/XGBO3EKY/coregadv[1].js
(The pipe into grep $HOME restricts the output to files in your home directory.)

You could also do a case-insensitive search with the command locate -ib \code | grep $HOME

Note: The \code in the example locate commands is a simple "shorthand" for *code* which works in the locate command.

Last edited by PTrenholme; 09-13-2011 at 12:21 PM.
1 members found this post helpful.


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
Bash script to access all files in a directory shinni Programming 5 04-24-2009 04:46 PM
bash script to check how many files in directory guest Programming 8 02-01-2009 12:55 AM
Using Bash, Find script files in a directory or subdirectories within... ray5_83 Programming 4 10-10-2008 08:42 PM
Script to find file differences in two directory trees (bash) Syqers Linux - Newbie 3 10-02-2008 12:55 AM
To rename files in a directory should I use Bash script or a Perl Script ? jamtech Programming 7 01-23-2008 12:25 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:24 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration