LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
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 04-17-2012, 09:46 AM   #1
nancydrew72
LQ Newbie
 
Registered: Apr 2012
Posts: 10

Rep: Reputation: Disabled
Script to find file sizes over 1GB only


Hello everyone. I am new to this forum and have never done scripting before (in any language). I am on Redhat 5.3. I wrote a script to locate all files over 1GB in a specific directory and it works greate if there actually happens to be a file over 1 GB. The problem is, if there isn't a file over 1GB then it just seems to report random files that aren't even in the directory I'm telling it to look it. Can someone please tell me what I'm doing wrong?

Here's a copy of the script:
find /sxplive/db -size +1G -name livenxt* -print0 | xargs -0 ls -lSh > /sxplive/rd/tmp/dbfilesize.log
cat /sxplive/rd/tmp/dbfilesize.log | mail -s "Review SXPLIVE DB file sizes" support@domain.com
 
Old 04-17-2012, 09:50 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
You don't have "livenxt*" in single quotes, and as such bash will glob the filename and expand the command line to contain everything that matches that pattern, using them as arguments to "find". Put the pattern into single quotes and then the * will end up inside find, rather than being expanded beforehand.
 
Old 04-17-2012, 09:52 AM   #3
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,148
Blog Entries: 2

Rep: Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886
The problem here is that the ls command in the scond part of that script will not get any arguments if no file is found that is larger than 1GB. In that case the default behavior for ls is just to display the files in the current directory. Change the first line to
Code:
find /sxplive/db -size +1G -name "livenxt*" -exec ls -lSh "{}" \; > /sxplive/rd/tmp/dbfilesize.log
and it should work as intended.
For more info have a look at
Code:
man find

Last edited by TobiSGD; 04-27-2012 at 04:39 PM.
 
Old 04-17-2012, 11:30 AM   #4
nancydrew72
LQ Newbie
 
Registered: Apr 2012
Posts: 10

Original Poster
Rep: Reputation: Disabled
Smile Thank you

Thank you both for the quick response. I will test your recommendations this week and see if that corrects the issue.
 
Old 04-27-2012, 04:00 PM   #5
nancydrew72
LQ Newbie
 
Registered: Apr 2012
Posts: 10

Original Poster
Rep: Reputation: Disabled
Script to find file sizes over 1GB only

On the first solution I got the same result I was getting before the change.

The second suggestion find /sxplive/db -size +1G -name "livenxt*" -exec ls ls -lSh "{}" \; > /sxplive/rd/tmp/dbfilesize.log resolved my issue.

Thank you!

Last edited by nancydrew72; 04-27-2012 at 04:03 PM.
 
Old 04-27-2012, 04:07 PM   #6
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
TobiSGD's solution was righterer than mine, ignore my comments... a little typo, but looks mostly good...

find /sxplive/db -size +1G -name "livenxt*" -exec ls -lSh "{}" \; > /sxplive/rd/tmp/dbfilesize.log
 
Old 04-27-2012, 04:38 PM   #7
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,148
Blog Entries: 2

Rep: Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886
Oops, I missed that, corrected.
 
  


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
My / file system says it has 25Gb. How come I can only find about 1Gb? dangfitz Linux - Newbie 7 09-26-2011 09:09 AM
need help with bash script to compare file sizes rimvydazas Programming 3 04-03-2008 06:18 AM
can't find zm script file to copy. Buddhike G Linux - Software 1 10-08-2007 05:17 PM
A shell script for optimising OpenDocument file sizes human2.0 Programming 3 06-05-2006 07:54 PM
Comparing file sizes using a bash script. IanChristie Programming 5 12-19-2003 10:14 PM

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

All times are GMT -5. The time now is 09:27 PM.

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