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 05-10-2011, 03:35 AM   #1
vraptor
LQ Newbie
 
Registered: May 2011
Posts: 11

Rep: Reputation: 0
[shell script] ignore folder if it contains file x


Okay so some of you may have realised that i am creating a small backup script, now i have another question.

Lets say that the file backup_log.txt will be within the directory where files are backed up to.

So for example i have run my script and it has backed up to
./.backup
so within that folder there is a file named backup_log.txt

Now my problem is, lets assume i am backing up the current directory, and this directory contains a previous backup folder.

So i am backing up my home directory:
and inside i have
test1.txt
test2.txt
.backup/backup_log.txt

I have a sort of recursive script to go through and backup files, and i created a simple case to check whether the folder name was .backup

Code:
 case $(dirname $filestoback) in
                                        */.backup*) echo "is backup folder"
                                        ;;
                                        *)
However what i would really like to do, is exclude the folder, only if it contains the backup_log.txt file inside it, because theoretically, the backup folder could have a different name!
Thank you very much.
 
Old 05-10-2011, 04:52 AM   #2
baltho
Member
 
Registered: Aug 2004
Location: Adelaide, South Australia
Distribution: Ubuntu (Natty)
Posts: 38

Rep: Reputation: 18
IMHO, it would look something like this:

if [ -f $dirname/backup_log.txt ] ; then
echo "is backup folder"
else
echo "is not..."
fi

Square brackets are shorthand for the test shell builtin - "man test" will show all of the options, but the "-f" means file exists and is readable.
 
Old 05-10-2011, 04:57 AM   #3
vraptor
LQ Newbie
 
Registered: May 2011
Posts: 11

Original Poster
Rep: Reputation: 0
Thank you for the response however, that will simply be if that specific file is found. What i need is a check before hand, to exclude the folder that that file is contained in, not simply exclude that file itself
Thanks again !
 
Old 05-10-2011, 07:30 AM   #4
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,254

Rep: Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686
I think you may have to explain further as obviously if the directory contains the file then the directory must exist.

Also, you could exclude the folder using find so it will also depend on how you are retrieving the folder and / or file names.
 
Old 05-10-2011, 07:38 AM   #5
vraptor
LQ Newbie
 
Registered: May 2011
Posts: 11

Original Poster
Rep: Reputation: 0
How would i go about excluding the directory using find?

Edit nvm found it:
Code:
find $directory -name ".foldername" -prune -o -type f -print

Last edited by vraptor; 05-10-2011 at 08:06 AM.
 
  


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
Ignore/Disable Ctrl-C (SIGINT) in a shell script dctw Programming 3 01-11-2010 03:30 AM
Shell Script To extract more than one tar file in to a single folder greensuman Linux - General 5 12-03-2009 12:08 AM
shell script which makes *something* with every file in folder matt79 Programming 5 02-17-2009 04:58 PM
BASH Shell script : copying a file to multiple folder zamri Programming 14 04-29-2008 11:27 AM


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