Delete files directory

amigos
necesito dejar en un directorio solo los archivos del dia anterio, como puedo hacer eso con una shell

Here is an example of code that will delete directories and their contents older than 2 weeks.
-type d says that you are deleting a directory and piping that to xargs with rm -rfv
means to force delete anything in the directory.

find /path/to/directory/directory_prefix_* -mtime +14 -type d | xargs rm -rfv

that code delete files or direct sub too?

friend in the directory have the attached file photo, without em, I Bargo the code below does not bring anything when I run

-rw-r--r-- 1 satverpv desa    2912 oct 24 17:38 1000169320160930.RSAT
-rw-r--r-- 1 satverpv desa 390936 oct 25 11:39 1000169320160921.RSAT
-rw-r--r-- 1 satverpv desa         0 oct 25 11:41 1000169320160928.RSAT
-rw-r--r-- 1 satverpv desa 390936 oct 25 12:34 1000169320160929.RSAT
-rw-r--r-- 1 satverpv desa         0 oct 26 16:27 1000169320160101.RSAT
-rw-r--r-- 1 satverpv desa 390936 oct 27 16:37 1000169320160922.RSAT
-rw-r--r-- 1 satverpv desa          0 oct 28 11:49 1000169320160927.RSAT
-rw-r--r-- 1 satverpv desa 396032 oct 28 12:24 1000169320161025.RSAT

satverpv(satdes) /u01/home/desa/satverpv/sat/dat> find /u01/home/desa/satverpv/sat/dat/*.RSAT -mtime +14 -type d


If you are deleting files and not directories, then you want to use -type f not d. The first line will return the files found. The second will find and delete the files that you want. You can also try the third line to get the number of files found.

find /u01/home/desa/satverpv/sat/dat/*.RSAT -mtime +14 -type f
find /u01/home/desa/satverpv/sat/dat/*.RSAT -mtime +14 -type f | xargs rm -rfv
find /u01/home/desa/satverpv/sat/dat/*.RSAT -mtime +14 -type f | wc --lines

+14 means that the look from today's date to 14 days ago?

I'm not quite sure I understand either of the posts #1 or #3, but if you say that the find command mentioned doesn't return anything, this is not surprising:

  • -type d returns only directory names: none of your files is a directory.
  • -mtime +14 returns names older than 14 days (in fact 14 * 24 hours): none of your files is that old; the oldest (24. Oct) is nine days old as of today (2. Nov).

thank you very much to everyone at the end serves me the solution

find /u01/home/desa/satverpv/sat/dat/*.RSAT -mtime +14

friends that this code no longer works

-rw-r--r-- 1 satverpv desa    29 nov  2 12:14 prueba_1.txt
drwxr-xr-x 2 satverpv desa  4096 nov  2 12:14 .
drwxr-xr-x 9 satverpv desa 77824 nov  3 14:17 ..
satverpv(satdes) /u01/home/desa/satverpv/sat/dat/prueba_mr>

find /u01/home/desa/satverpv/sat/dat/prueba_mr -mtime +1

quiero que me liste todo los archivos menores a la fecha de hoy

Google translator gives me this:-

Is .../sat/... in the directory meant to suggest the day of the week?

If so, replace it with * in the find command:-

find /u01/home/desa/satverpv/*/dat/*.RSAT -mtime +14

Is that what you need? If not, where are the files that you need to find for the other days?

Robin

I need to delete the file that has more ancient date of the current day 1 day

example in this directory have a file

-rw-r--r-- 1 satverpv desa    29 nov  2 12:14 prueba_1.txt
drwxr-xr-x 2 satverpv desa  4096 nov  2 12:14 .
drwxr-xr-x 9 satverpv desa 77824 nov  3 14:17 ..

but this code brings me nothing

find /u01/home/desa/satverpv/sat/dat/prueba_mr -mtime +1 -type f

I'm doing wrong?

What's the output of

find /u01/home/desa/satverpv/sat/dat/prueba_mr

?

}


satverpv(satdes) /u01/home/desa/satverpv/sat/dat/prueba_mr> find /u01/home/desa/satverpv/sat/dat/prueba_mr
/u01/home/desa/satverpv/sat/dat/prueba_mr
/u01/home/desa/satverpv/sat/dat/prueba_mr/prueba_1.txt
satverpv(satdes) /u01/home/desa/satverpv/sat/dat/prueba_mr>

Now go on running that command adding (and: modifying) the tests step by step.

but I need to add ???

find /u01/home/desa/satverpv/sat/dat/prueba_mr 
find /u01/home/desa/satverpv/sat/dat/prueba_mr -type d 
find /u01/home/desa/satverpv/sat/dat/prueba_mr -type f
find /u01/home/desa/satverpv/sat/dat/prueba_mr -mtime -1 -type d 
find /u01/home/desa/satverpv/sat/dat/prueba_mr -mtime 1 -type d 
find /u01/home/desa/satverpv/sat/dat/prueba_mr -mtime +1 -type d 
find /u01/home/desa/satverpv/sat/dat/prueba_mr -mtime -14 -type d 
find /u01/home/desa/satverpv/sat/dat/prueba_mr -mtime 14 -type d 
find /u01/home/desa/satverpv/sat/dat/prueba_mr -mtime +14 -type d 

now if it works perfect !!!!!

find /u01/home/desa/satverpv/sat/dat/prueba_mr -mtime -5 -type f | xargs rm

I doubt that means only one this is?

xargs 

You can also remove the files with find without piping the find output into xargs :

find /u01/home/desa/satverpv/sat/dat/prueba_mr -mtime -5 -type f -exec rm {} +

This is not only more efficient than using xargs , it will also avoid lots of other problems if you ever need to process pathnames that contain <space>, <tab>, or <newline> characters.