Hi All
I want to remove the files with name like data*.csv from the directory older than 10 days.
If there is no files exists to remove older than 10 days, It should not do anything.
Thanks
Jo
Hi All
I want to remove the files with name like data*.csv from the directory older than 10 days.
If there is no files exists to remove older than 10 days, It should not do anything.
Thanks
Jo
find <directory_path> -mtime +10 -name "data*.csv" -exec rm -f {} \; 2>/dev/null
This will also descend into sub-directories of the directory. To prevent descent, use
find <directory_path> \( ! -name <directory_path> -prune \) -mtime +10 -name "data*.csv" -exec rm -f {} \; 2>/dev/null
I tried as below
# Remove files older than 31 Days
find -iname -mtime +31 -name 'Datapull*.csv.COMPLETE' -exec rm -f {} \;
But when i tried to execute the shell script i got the bellow error
https://mail.google.com/mail/images/cleardot.gif
find: paths must precede expression
Usage: find [path...] [expression]
you missed a path for "find" (in elixir_sinari's post variable "<directory_path>")
Where is the path???
The path should should be the first argument to find (after options, if any)...
just cd to that directory and run your find with a . after find..
and what's that
-iname
doing there alone???
Try
find . -mtime +31 -iname 'Datapull*.csv.COMPLETE' -exec rm -f {} \;
Hi
I tried by including the path as below.
find /lz/BI/ -mtime +31 -name 'Datapull*.csv.COMPLETE' -exec rm -f {} \;
Got below error.
find: missing argument to `-exec'
Iam very new to unix scripting,Pls advice.
Thanks
Jo
First run:
to count how many lines was returned by find.
next run this:
find /lz/BI/ -mtime +31 -name 'Datapull*.csv.COMPLETE' -exec rm -f '{}' \;
The problem in Post #6 is weird.
Please post what Operating System and version you are running and what Shell you are using.
Please confirm that you are using a unix/Linux editor such as vi
or vim
and not a Microsoft editor.
try this.
find /<dir_name>/<file_pattern> -type f -mtime +10 2>> /dev/null |xargs -I FILE_NAME rm FILE_NAME 1>> /dev/null 2>> /dev/null
I would ignore post #9 (syntax issues).
Let's try something safer. First we check what files would be deleted:
find /lz/BI/ -type f -mtime +10 -name 'Datapull*.csv.COMPLETE' -print | while read filename
do
# Remove echo when tested
echo rm -f "${filename}"
done