LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-08-2011, 02:29 PM   #1
coop59
LQ Newbie
 
Registered: Mar 2011
Posts: 6

Rep: Reputation: 0
New to Bash Scripting


Hey Guys I sorta of have an Idea on where to start but I fear this is going to get complicated on me quick.

I have a list of directories that I delete files from all the time but now there has come a need to exclude some of those directories and keep the files in there for a bit longer.

In my script I need to be able to list those directories and output the list to a file, then read from that file and exclude the dirs that I need to keep files in. Can anyone give me a hint as to where to start with this. I already have a script written to delete files from all of these directories just not sure how to handle the exceptions I guess,

Thanks a ton,
Michael
 
Old 04-08-2011, 02:33 PM   #2
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 4,278

Rep: Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694
What does your script look like? If you post some of that, it would be possible to modify it for you. Or offer you advice on what to change.
 
Old 04-08-2011, 03:31 PM   #3
Ramurd
Member
 
Registered: Mar 2009
Location: Rotterdam, the Netherlands
Distribution: Slackwarelinux
Posts: 703

Rep: Reputation: 111Reputation: 111
if it's shell scripting:

two ways I will present onto thee, the number of the ways being two:

the first way, of the two ways being this: that thou commenteth out thy lines like so:

Code:
/tmp/directory1
#/tmp/directory2
/home
grep -v "^#"

The second way you can also see, and is not as efficient, but sometimes schoolteachers like things a bit complicated:

make a file of directories to ignore:
in your loop for the directories, you can grep the directory-to-be-cleared in the ignore file (send stdout and stderr to /dev/null); use the return value of grep (checkout man grep) to determine whether or not the directory is in the ignore-list; if it isn't: clear it out, else keep it dirty.

the rest I leave to you, as I have a sinking feeling some school told people to look here for help
 
  


Reply



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 ZAMO Linux - General 1 01-19-2009 02:25 AM
Reading a bash variable in bash scripting problem freeindy Programming 3 11-27-2008 02:29 AM
Bash scripting disruptive Programming 5 06-29-2006 03:49 PM
Bash scripting pete1234 Programming 1 09-27-2005 01:48 AM
bash scripting.. kurrupt Programming 3 09-21-2005 12:07 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:18 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
Open Source Consulting | Domain Registration