Visit Jeremy's Blog.
Go Back > Forums > Linux Forums > Linux - Software
User Name
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.


  Search this Thread
Old 09-29-2003, 12:23 AM   #1
LQ Newbie
Registered: Sep 2003
Posts: 2

Rep: Reputation: 0
Scripting help needed.

I am having difficulties writing a bash script to compare files in one directory to a second directory. If the file in the second directory is newer, delete the file from the first directory and copy the file from the second directory to the first. To add to difficulty, the file names have a base with numbers. The numbers are revision identifiers. For example,

directory 1 ... file thefile- compare to thefile- The second file is newer. Delete the first file and copy the new file to directory 1.

Please help...

Old 09-29-2003, 04:18 AM   #2
Registered: Apr 2003
Location: Netherlands
Distribution: SuSE (before: Gentoo, Slackware)
Posts: 613

Rep: Reputation: 30
Maybe you want to use Perl instead. It combines the powers of grep, sed, and sh (bash)
Old 09-29-2003, 10:47 AM   #3
Registered: Aug 2003
Distribution: redhat 9.0
Posts: 37

Rep: Reputation: 15
Okie, I find this script in a tutorial about bash's scripting. You could modify this a bit and you should be able to do what you need as you describe above.


# Backs up all files in current directory modified within last 24 hours
#+ in a "tarball" (tarred and gzipped file).

# If no backup-archive filename specified on command line,
#+ it will default to "backup.tar.gz."

tar cvf - `find . -mtime -1 -type f -print` > $archive.tar
gzip $archive.tar
echo "Directory $PWD backed up in archive file \"$archive.tar.gz\"."

# Stephane Chazelas points out that the above code will fail
#+ if there are too many files found
#+ or if any filenames contain blank characters.

# He suggests the following alternatives:
# -------------------------------------------------------------------
# find . -mtime -1 -type f -print0 | xargs -0 tar rvf "$archive.tar"
# using the GNU version of "find".

# find . -mtime -1 -type f -exec tar rvf "$archive.tar" '{}' \;
# portable to other UNIX flavors, but much slower.
# -------------------------------------------------------------------

exit 0

--------hope this is helpful...------------


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
shell scripting - help needed jonhewer Linux - Newbie 54 09-09-2005 03:58 PM
bash scripting --- some help needed rajsharma Linux - Software 1 09-09-2005 03:49 AM
scripting help Abe_the_Man Linux - General 1 11-03-2004 06:30 PM
linux scripting help needed read from file line by line exc commands each line read atokad Programming 4 12-26-2003 11:24 PM
Shell scripting and background processes - help needed. trafalgar Programming 3 06-08-2003 10:15 AM

All times are GMT -5. The time now is 12:58 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration