Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6166189
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T22:17:45+00:00 2026-05-23T22:17:45+00:00

I have a file server backup on an external hard drive a few months

  • 0

I have a file server backup on an external hard drive a few months old for a file server that went down since then. Most of the data was recovered onto a temporary file server thats been in use since then but there are some inconsistencies.

I am going to mount the external and rsync it with the current data to it but first I need to establish files that have gotten updated on the newer copy.

I can do diff -r -q /old/ /new/ to obtain this, I am trying to get better at scripting so I am trying to write something that will rename the old file to filename.old whenever diff returns a difference.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T22:17:46+00:00Added an answer on May 23, 2026 at 10:17 pm

    So after checking, I wasn’t able to find an option in diff to only output the filename differences so we’ll just work with what diff outputs.

    If diff finds files that differ, the output is something like this:

    Files old/file and new/file differ
    

    Since all your bash script would be doing is renaming the changed file from the old directory, we want to extract old/file from this output. Let’s start by only displaying lines like Files...differ (as other lines may be produced):

    diff -rq old/ new/ | grep "^Files.*differ$"
    

    Now you’ll only get lines like the one shown before. Next step is getting the filename. You can do this with awk by adding something like awk '{print $2}' as another pipe but if the filename itself contains spaces, awk will break up that as two separate strings. We’ll use sed instead:

    diff -rq old/ new/ | grep "^Files.*differ$" | sed 's/^Files \(.*\) and .* differ$/\1/'
    

    Now this will produce a list of files that have changed in the old directory. Using a simple for loop, you can now rename each of the files:

    for old_file in `diff -rq old/ new/ | grep "^Files.*differ$" | sed 's/^Files \(.*\) and .* differ$/\1/'`
    do
       mv $old_file $old_file.old
    done
    

    And that’s it!

    edit: actually, that’s not all. This loop still fails on files with spaces so let’s muck with it a bit. for will try to produce a list separated by a space by default. Let’s change this to use newlines instead:

    OLD_IFS=$IFS
    # The extra space after is crucial
    IFS=\
    
    for old_file in `diff -rq old/ new/ | grep "^Files.*differ$" | sed 's/^Files \(.*\) and .* differ$/\1/'`
    do
       mv $old_file $old_file.old
    done
    IFS=$OLD_IFS
    

    This temporarily replaces bash’s default separator ($IFS) to a newline and puts it back after it’s done with the loop so you don’t split by space.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a password protected sql server backup file that I need to restore.
Have made backup script that does well: makes backup zip-file and then uploads it
I have a tar backup from an old subversion server which has long since
I have to develop a file server service that transfer file form a specified
I have been working on designing a file server that could take the load
I have a file called error.log on my server that I need to frequently
I have this SQL Job (in SQL Server 2005) that creates a backup every
I have a backup server that replicates my production server's mysql database, awhile ago
I have a database backup for which SQL Server Management Studio says that it
I have a batch file that executes a .sql file to backup a database.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.