Shell script linux

MariaBma

New Member
Joined
May 14, 2020
Messages
3
Reaction score
1
Credits
36
I am really struggling with a homework.I have to make a shell script that will copy to a separate path the files in which the user modified more than 20 lines on a specific date.The files should also be archived and them deleted.
What I know right now:
To copy a file somewhere else i use this:
$ ls dir1/
dir2/
$ cp -r dir1/ dir1.copy
$ ls dir1.copy
dir2/
To show number of lines in a file and modified files in the last days:
wc -l file1
mtime or find ~/Desktop -type f -newermt 2020-05-22 -ls for example

I use tar for archives and rm to remove.The problem is I have very little experience with linux and I don’t know how to form the final shell script.
 


I’m not sure what to suggest here. What is the exact wording of the assignment you’ve been given? I wonder if there’s something that you’ve misinterpreted, or misunderstood.

The file system can keep track of the modified dates of files, so you can track files that were modified on a particular date, but we won’t know how many lines have changed in any of the files. Not without some kind of mechanism for tracking all of the files and the changes made to them....
 
I talked to my teached and I managed to understand the assignment but I still got stuck.
I have to make a shell script which compares 2 files line by line and finds different lines.If the number of the different lines is greater than 20,then I have to copy the 2 files to another path and then archive and delete the files.Dir1 and dir2 are the 2 files.What I came up with is:
#!/bin/bash
If [ “$(diff dir1 dir2 |wc -l)” -gt “20” ] then
I know I need the cp command but I don’t know how to write it exactly.I alsoo need tar for archives and rm $file to delete
 

Members online


Top