LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Shell script project Asap (https://www.linuxquestions.org/questions/linux-newbie-8/shell-script-project-asap-4175675221/)

BringMara 05-14-2020 09:19 AM

Shell script project Asap
 
Hi,I need to make a shell script that copies to a separate Path only the files in which the user modified more than 20 lines at a certain time/date.Files are archived and then deleted.

pan64 05-14-2020 09:21 AM

ok, and what is your problem? Where did you stuck?

shruggy 05-14-2020 09:21 AM

Not enough info. Are the files kept in a VCS?

berndbausch 05-14-2020 09:26 AM

While the filesystem keeps the time of last modification, it's only possible to know the modified lines if the original file is kept. Also, if the file is modified today and again tomorrow, today's modification date is forgotten.

In other words, your requirement can't be fulfilled without a very special filesystem type, and/or a special application with which the files are altered.

GPGAgent 05-14-2020 09:28 AM

Quote:

Originally Posted by BringMara (Post 6122837)
Hi,I need to make a shell script that copies to a separate Path only the files in which the user modified more than 20 lines at a certain time/date.Files are archived and then deleted.

1. What sort of files, text, word, spreadsheet?

2. So if 19 lines were modified it two days ago and 1 line today it would be rejected? Because 20 lines weren't modified today?

3. You copy files to a specified path and then you archive them and then you delete them. Seems a bit odd.

Puzzled???

TB0ne 05-14-2020 09:38 AM

Quote:

Originally Posted by BringMara (Post 6122837)
Hi,I need to make a shell script that copies to a separate Path only the files in which the user modified more than 20 lines at a certain time/date.Files are archived and then deleted.

Then by all means, you should write one to do just that. Given that your subject line is "Shell script project Asap", that says to me this is a homework question. Since you need it 'ASAP', you should start writing immediately.

And if you get STUCK, you need to post what YOU have written/done/tried, give us examples of what you're using for input, what you want as output, and where things are failing, and we will be glad to assist you from there. But we are not the place for 'need my homework done ASAP'

BringMara 05-25-2020 06:29 AM

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.

rtmistler 05-25-2020 08:35 AM

Quote:

Originally Posted by BringMara (Post 6127062)
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.

Please review the link from my signature titled My Bash Blog.

It provides some good overview of bash programming, how to start and how to debug.

JJJCR 05-26-2020 03:18 AM

Check out this link: https://bash.cyberciti.biz/guide/Hello,_World!_Tutorial

Or open Google.com and search for this keyword: "how to create a shell script in linux"

Or this keyword: "linux bash hello world tutorial"

Example:
Quote:

#!/bin/bash
echo "Hello, World!"
echo "Knowledge is power. But don't do a shortcut to the knowledge. Learn the hard way."

echo "Hello, World!" <-- is a command, so technically you can replace it with any commands in Linux

Good luck!!!


All times are GMT -5. The time now is 06:44 AM.