LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
Search this Thread
Old 08-01-2009, 07:01 AM   #1
salasi
Senior Member
 
Registered: Jul 2007
Location: Directly above centre of the earth, UK
Distribution: SuSE, plus some hopping
Posts: 3,886

Rep: Reputation: 774Reputation: 774Reputation: 774Reputation: 774Reputation: 774Reputation: 774Reputation: 774
Simple bash scripting question, involving finding newer files


This is a simple syntax question about trying to find files that are newer than a certain date within a particular directory tree (in this case,within a .kde4 tree). This is just out of general interest, and can't be said to be in any way urgent, as I'm just trying to satisfy curiosity here and my crude script accomplished the necessary minimum.

What I am trying to do is use find to go through the .kde4 tree and find what is new there. What I've got is:

Code:
sep
find ~/.kde4 -type f -mtime -5 -ls | grep -v .org | grep -v .co.uk | grep -v .com | grep -v cache-
sep
(you can ignore the two 'sep'statements - they just print a row of dashes, to make script output easier to read, and is used in other scripts)

The first issue is that the line of 'grep -v' statements is inelegant, and I'm sure there is a way of filtering several things at once, but I can't figure out the syntax.

The supplementary question is that the script uses fixed parameters (-mtime 5, .kde4) which it might be nice to read from the invocation.

I could read $1, $2,... but sorting out the business of the parameters being given in different orders, sometimes being present, sometimes absent, sometimes non-numerical parameters being given where numbers should have been given and this seems more complication than is sensible for a trivial script. Is this because I'm trying to do this the hard way, and there is an easy way that I should be using?
 
Old 08-01-2009, 09:06 AM   #2
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,453

Rep: Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941
Quote:
Originally Posted by salasi View Post
The first issue is that the line of 'grep -v' statements is inelegant, and I'm sure there is a way of filtering several things at once, but I can't figure out the syntax.
You can negate a test using !. If you want to exclude the .org, .co.uk, .com, and cache- files, you can do something like:
Code:
find ~/.kde4 -type f -mtime -5 ! -name \*.org ! -name \*.co.uk ! -name \*.com ! -name cache-\* -ls
You can also consider the test -regex.

Regarding your second question I think you can't avoid to use positional parameters. A bunch of checks at the beginning of the script it's easy to implement. Every time some condition is not satisfied, you can print a "usage" message and exit. "usage" can be a function at the beginning of the script, so that you have not to repeat the same lines of code all over the script.

Last edited by colucix; 08-01-2009 at 09:15 AM.
 
Old 08-01-2009, 03:22 PM   #3
salasi
Senior Member
 
Registered: Jul 2007
Location: Directly above centre of the earth, UK
Distribution: SuSE, plus some hopping
Posts: 3,886

Original Poster
Rep: Reputation: 774Reputation: 774Reputation: 774Reputation: 774Reputation: 774Reputation: 774Reputation: 774
Yes, that's neater than my version. Oddly though, it doesn't quite work as well for me in a way that I hadn't thought of.

It turns out that my version also cuts out some stuff like
Code:
.kde4/cache-lenny/http/d/download.kde.org_khotnewstuff_plasmathemes_previews_m100945-1.png_7369118b_freq
where your version doesn't get the ones that don't have the .org at the end of the term. Both are OK though (note that this isn't a criticism in any way; I didn't give any kind of spec for what it should do and I hadn't thought about this part.)

I probably should have given some more detail, although you have figured out the important parts; I was trying to have a look at a user's kde tree, to see what had been changed, if anything, in an update. Just looking at everything that has been changed since the update doesn't give a clear picture because it throws up lots of stuff that has been changed, but isn't relevant, such as cached records of websites, apparently. hence the isea of scrubbing the .com, .org and .co.uk, which gets a lot of the junk in my case.

Quote:
Regarding your second question I think you can't avoid to use positional parameters.
Ah well, I was hoping that there was a clever and simple way that I was overlooking, particularly as it is such a common problem.

Anyway, thank you for your help.
 
  


Reply

Tags
find, script


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 scripting simple question wildtiger23 Programming 1 03-04-2009 10:35 AM
Shell Scripting question involving ping jhilton Linux - Newbie 3 07-29-2008 10:16 AM
Very simple BASH scripting question clickster Linux - Newbie 6 11-23-2005 04:28 PM
Simple bash/awk/sed scripting question R00ts Programming 4 04-16-2005 02:55 AM
Bash Scripting--Simple Question mooreted Linux - General 4 05-10-2004 01:44 PM


All times are GMT -5. The time now is 03:31 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration