LinuxQuestions.org
Visit Jeremy's Blog.
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 09-13-2011, 10:00 AM   #1
wshruti
LQ Newbie
 
Registered: Sep 2011
Posts: 3

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


Hi,
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:

#!/bin/bash
find ~/ -name 'core*'
hostname

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, 10:17 AM   #2
rahulchandrak
Member
 
Registered: Apr 2010
Posts: 33

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

Rep: Reputation: 346Reputation: 346Reputation: 346Reputation: 346
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:
Code:
$ locate -b \core | grep $HOME
/home/Peter/.cache/compizconfig/core.pb
/home/Peter/.gnash/SharedObjects/cdn-akm.vmixcore.com
/home/Peter/.wine/drive_c/windows/system32/d3d10core.dll
/home/Peter/.wine/drive_c/windows/system32/mscoree.dll
/home/Peter/.wine/drive_c/windows/system32/winecoreaudio.drv
/home/Peter/.wine-x86_64/drive_c/windows/system32/d3d10core.dll
/home/Peter/.wine-x86_64/drive_c/windows/system32/mscoree.dll
/home/Peter/.wine-x86_64/drive_c/windows/system32/winecoreaudio.drv
/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/Books/Gutenberg/PALM/Launcher/ecore11p.prc
/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 11:21 AM.
 
1 members found this post helpful.
  


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

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

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