How can I read a single line from a text file using bash?

In summary, the conversation is about the desire to write a script that will automatically backup files to a remote computer only when a newer version exists. The question is how to read a single line from a text file in bash and the suggestion is to use rsync which not only backups files but also copies only the parts that have changed.
  • #1
Euclid
214
0
I want to write a script that will automatically backup my documents to a remote computer. I have a lot (~500 MB) of files, so I only want the files to be backed up when a newer version exists.

Short version of the question: how do I read a single line from a text file using bash?

Long version of the question:
Here is the plan for the script...

#!/bin/bash
ssh remoteComputer # connect to remote comp
find ~/Documents * > files.txt #find all files in documents and write to files.txt
line=1
fileLength = (number of lines if files.txt)
while [line -lte fileLength]
do
(put filename at the lineth line to the string fileName)
if fileName -nt remoteComputer:~/Documents/fileName
#go through all files and
#check to see if remoteComputer has the
#latest version of this file already
scp line to remoteComputer
#if so, update file
fi
line=$[$line+1]
done
exit #leave ssh session

The exact implementation is what I need help on. If I could read files.txt line by line this would be very easy, but I can't figure it out!
 
Technology news on Phys.org
  • #2
You should look at rsync, it not only does this but can copy just the parts of files that have changed.
 
  • #3
That's just too easy! Thanks mgb_phys!
 

1. What is automated backup of files?

Automated backup of files is the process of automatically creating copies of important files and storing them in a secure location. This ensures that the files are protected in case of accidental deletion, hardware failure, or other emergencies.

2. How does automated backup work?

Automated backup works by using specialized software or tools to regularly scan for changes in designated files and folders. When a change is detected, the software will automatically create a copy of the file and store it in a predetermined location.

3. What are the benefits of using automated backup?

There are several benefits to using automated backup, including saving time and effort by eliminating the need for manual backups, ensuring data security and protection against data loss, and providing peace of mind knowing that important files are always backed up.

4. What types of files can be backed up with automated backup?

Automated backup can be used to back up any type of file, including documents, photos, videos, and more. It is important to regularly back up all important files to ensure their safety and accessibility in case of an emergency.

5. Is automated backup secure?

Yes, automated backup is secure if proper measures are taken. It is important to use reliable and reputable backup software, choose a secure backup location, and regularly test the backups to ensure their integrity. It is also recommended to use encryption to further protect sensitive files.

Similar threads

  • Programming and Computer Science
Replies
11
Views
1K
  • Programming and Computer Science
Replies
6
Views
1K
  • Programming and Computer Science
Replies
16
Views
3K
  • Programming and Computer Science
Replies
19
Views
1K
Replies
16
Views
2K
  • Programming and Computer Science
Replies
6
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
16
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
3
Views
3K
  • Programming and Computer Science
Replies
4
Views
3K
  • Programming and Computer Science
Replies
1
Views
5K
Back
Top