This finds files from yesterday and today.
I need it to find only files from today.
sudo find /home/andy -iname "*.sh" -mtime -1 -print
This finds files from yesterday and today.
I need it to find only files from today.
sudo find /home/andy -iname "*.sh" -mtime -1 -print
GNU find has
find /home/andy -daystart -iname "*.sh" -mtime -1 -print
BTW (because we are 100% correct) -mtime -1
will also find files with a future time stamp. "Only today" is -mtime 0
.
Vielen Dank. It worked great.
Modification is this.
#!/bin/bash
# Ubuntu_Mate 18.04 LTS
# Help from MadeInGermany @ The UNIX and Linux Forums - Free Linux and Unix Tech Support
#
# Find files just from today
#
[ ! $1 ] && {
echo -e "Error!! No filename given.!!"; exit 1; } || echo -e "Searching for $1"
find /home/andy -daystart -iname "*.sh" -mtime -1 -print
Wondering about the dconf and .gvfs.
Neither contained any .sh files?
Todays_Files.sh *.sh
Searching for restore-all.sh
/home/andy/bin/70_Percent_VOL.sh
/home/andy/bin/Todays_Files.sh
/home/andy/bin/Backup_18_04.sh
find: �/home/andy/.cache/dconf': Permission denied
find: �/home/andy/.gvfs': Permission denied
/home/andy/.config/ukuu-notify.sh
They are error messages - check permissions - are you running this as the owner?
Please get used to if-then-else-fi rather than && and || and their pitfalls.
In the case of an exit you can safely use alone a &&
[ -z "$1" ] && {
echo -e "Error!! No filename given.!!"
exit 1
}
echo -e "Searching for $1"
# prune at a .* path; the .?* is needed if the start directory is a .
find /home/andy -daystart -type d -name ".?*" -prune -o -iname "*.sh" -mtime -1 -print
# The -o is an OR and behaves like an ELSE; if needed you can group the following in \( \)
Thanks.
I noticed that the first 3 lines are not necessary.
I was hoping to be able to search for any file extension, not just .sh.
Search for *.sh and *.csh (case insensitive): \( -iname "*.sh" -o -iname "*.csh" \)
echo -e "Searching for $1"
# prune at a .* path; the .?* is needed if the start directory is a .
find /home/andy -daystart -type d -name ".?*" -prune -o \( -iname "*.sh" -o -iname "*.txt" -o -iname "*.odt" \)" -mtime -1 -print
Yes that makes sense.
One quote too many, after the \)
.
The )
must be quoted. You can as well quote it as ")"
.