Hi,
New to scripting and looking for some help.
I am trying to write a script that will search a specified directory for any new or modified files within the last 7 days and display the results. This will be ran daily and emailed?
Thanks
What have you tried?
What do you believe would solve this?
We are not a coding service, and some requests like this have a "school work" feel to them.
Please provide information on what you have attempted.
Find (directory) �name �*.file extention� �mmin -1440 � print
Is basically giving me what I am after just wanting the files to display in the results though not full paths?
Welcome Con592,
I have a few to questions pose in response first:-
- Is this homework/assignment? There are specific forums for these.
- What have you tried so far?
- What output/errors do you get?
- What OS and version are you using?
- What are your preferred tools? (C, shell, perl, awk, etc.)
- What logical process have you considered? (to help steer us to follow what you are trying to achieve)
Most importantly, What have you tried so far?
There are probably many ways to achieve most tasks, so giving us an idea of your style and thoughts will help us guide you to an answer most suitable to you so you can adjust it to suit your needs in future.
We're all here to learn and getting the relevant information will help us all.
Kind regards,
Robin
You can cd to the directory and use a relative path
find . -type f -name "*.ext" -mmin -1440 -print
Or you filter the output
directory="directory"
find "$directory" -type f -name "*.ext" -mmin -1440 -print | sed "s#^$directory##'
For long times like 7 days you better take -mtime -7 not -mmin -10080 .
Hi,
Thanks for the info.
How can I get more info from the find output, for example modified date etc in the output?
Does your find version offer the -ls action? And, I'm pretty sure no find version will work with the non-ascii � � � characters...
Yes -ls works didn't know this worked with find.
What options are available to edit the results, for example I am trying to remove the full file path to only show the file name. I am wanting to remove the permissions that are displayed as well. I have been trying to use the sed command but not having much joy. Is it possible to display column heading for example modified by etc.
Linux Bash
Editing options are countless - show us what you get and show us what you want.
I am running
find "directory" -type f -name "*.ext" -mmin -1440 -ls | sed -s ^"directory"
trying to remove the full filepath. The result I am wanting is a headed set of files that have been modified in the last 24h only showing modified by , time/date and the file.
I can't remove a full filepath as I don't get anything out of your above command. Please check the syntax.
In order to make the thread more efficient, don't scenically describe the result, but post input and output as you have / want it, line by line, character by character, trimmed but meaningful.
I am running:
find "directory" -type f -name "*.exe" -mmin -1440 -ls
And getting the output:
-rwxrw-r-- 10 root root 2048 Sep 18 11:11 afile.exe
I would like the output:
Owner name file size time of last Modification directory
root 2048 Jan 13 07:11 afile.exe
Would piping your find results through this
awk -v OFS="\t" '
BEGIN {print "Owner name file size time of last Modification directory"
}
{print $3, $5, $6 " " $7 " " $8, $9
}
'
Owner name file size time of last Modification directory
root 2048 Sep 18 11:11 afile.exe
come close to what you need? Or do you REALLY need Sep 18 11:11 converted to Jan 13 07:11 as in your sample output?
Thanks I am looking more into the awk command
---------- Post updated at 04:02 PM ---------- Previous update was at 02:55 PM ----------
awk -v OFS="\t" '
BEGIN {print "Owner name file size time of last Modification directory"
}
{print $3, $5, $6 " " $7 " " $8, $9
}
'
Is it possible to add more space between the results
{print $3, $5, $6 " " $7 " " $8, $9
}
Hi.
Assuming that your file is TSV (Tab-Separated-Values), looking like this on file z6:
$ cat -A z6
Owner name^Ifile size^Itime of last Modification^Idirectory$
root^I2048^ISep 18 11:11^Iafile.exe$
Then you could use utility align , like so, output separated by TABs:
$ align -st z6
Owner name file size time of last Modification directory
root 2048 Sep 18 11:11 afile.exe
For more control over spacing, use a gutter change with blanks to separate:
$ align -st -js -g3 z6
Owner name file size time of last Modification directory
root 2048 Sep 18 11:11 afile.exe
Here are some details for align :
align Align columns of text. (what)
Path : ~/p/stm/common/scripts/align
Version : 1.7.0
Length : 270 lines
Type : Perl script, ASCII text executable
Shebang : #!/usr/bin/perl
Help : probably available with --help
Home : http://kinzler.com/me/align/ (doc)
Modules : (for perl codes)
Getopt::Std 1.10
Best wishes ... cheers, drl
If your awk allows for it, try -v OFS="\t\t" so it separates fields with two <TAB>s.
Instead of
\t
is there something for a space?
Try
.
.
.
{printf "%-13s%-13s%-28s%-20s\n", $3, $5, $6 " " $7 " " $8, $9
}
'
Owner name file size time of last Modification directory
root 2048 Sep 18 11:11 afile.exe