Google it ....

Showing posts with label delete old files. Show all posts
Showing posts with label delete old files. Show all posts

Monday, January 29, 2018

How to delete old files in linux based system timestamp

In this blog post I'll show you how to delete old files based system timestamp, the system timestamp means when a file was created OR when it was last modified. for example if you want to find and delete files older than 30 days in your linux machine you need next commands :
to find list of files which are older than specified days for example 30
find /directory/path/ -type f -mtime +30 -print
to delete files older than specified days for example 30
find /directory/path/ -type f -mtime +30 -exec rm -f {} \; -exec printf "." \;

Let's create small demo and delete some files from some directory which are older than 3 days :
cd /u01/app/oracle/diag/rdbms/testdb/testdb/alert/

[oracle@testdb alert]$ ls -lrt
total 1531540
-rw-r----- 1 oracle asmadmin 10485828 Oct 25  2016 log_115.xml
-rw-r----- 1 oracle asmadmin 10485847 Oct 26  2016 log_116.xml
-rw-r----- 1 oracle asmadmin 10485837 Oct 26  2016 log_117.xml
-rw-r----- 1 oracle asmadmin 10485885 Jun  6  2017 log_118.xml
-rw-r----- 1 oracle asmadmin 10485826 Jun  6  2017 log_119.xml
-rw-r----- 1 oracle asmadmin 10485965 Jun  7  2017 log_120.xml
-rw-r----- 1 oracle asmadmin 10485877 Jun  7  2017 log_121.xml
-rw-r----- 1 oracle asmadmin 10485788 Jun  8  2017 log_122.xml
-rw-r----- 1 oracle asmadmin 10485821 Jun  8  2017 log_123.xml
-rw-r----- 1 oracle asmadmin 10485835 Jun  8  2017 log_124.xml
-rw-r----- 1 oracle asmadmin 10485975 Jun  9  2017 log_125.xml
-rw-r----- 1 oracle asmadmin 10485870 Jun  9  2017 log_126.xml
-rw-r----- 1 oracle asmadmin 10486074 Jun 10  2017 log_127.xml
-rw-r----- 1 oracle asmadmin 10485926 Jun 10  2017 log_128.xml
-rw-r----- 1 oracle asmadmin 10485938 Jun 10  2017 log_129.xml
-rw-r----- 1 oracle asmadmin 10486197 Jun 11  2017 log_130.xml
-rw-r----- 1 oracle asmadmin 10485909 Jun 11  2017 log_131.xml
-rw-r----- 1 oracle asmadmin 10486043 Jun 12  2017 log_132.xml
-rw-r----- 1 oracle asmadmin 10485964 Jun 12  2017 log_133.xml
-rw-r----- 1 oracle asmadmin 10485806 Jun 12  2017 log_134.xml
-rw-r----- 1 oracle asmadmin 10485807 Jun 13  2017 log_135.xml
-rw-r----- 1 oracle asmadmin 10485863 Jun 13  2017 log_136.xml
-rw-r----- 1 oracle asmadmin 10485801 Jun 14  2017 log_137.xml
-rw-r----- 1 oracle asmadmin 10486012 Jun 14  2017 log_138.xml
-rw-r----- 1 oracle asmadmin 10485960 Jun 14  2017 log_139.xml
-rw-r----- 1 oracle asmadmin 10485860 Jun 15  2017 log_140.xml
-rw-r----- 1 oracle asmadmin 10485939 Jun 15  2017 log_141.xml
-rw-r----- 1 oracle asmadmin 10485939 Jun 16  2017 log_142.xml
-rw-r----- 1 oracle asmadmin 10485780 Jun 16  2017 log_143.xml
-rw-r----- 1 oracle asmadmin 10485805 Jun 16  2017 log_144.xml
-rw-r----- 1 oracle asmadmin 10485949 Jun 17  2017 log_145.xml
-rw-r----- 1 oracle asmadmin 10485930 Jun 17  2017 log_146.xml
-rw-r----- 1 oracle asmadmin 10485872 Jun 17  2017 log_147.xml
-rw-r----- 1 oracle asmadmin 10485873 Jun 18  2017 log_148.xml
-rw-r----- 1 oracle asmadmin 10485949 Jun 18  2017 log_149.xml
-rw-r----- 1 oracle asmadmin 10485881 Jun 19  2017 log_150.xml
-rw-r----- 1 oracle asmadmin 10485836 Jun 19  2017 log_151.xml
-rw-r----- 1 oracle asmadmin 10485853 Jun 19  2017 log_152.xml
-rw-r----- 1 oracle asmadmin 10485936 Jun 20  2017 log_153.xml
-rw-r----- 1 oracle asmadmin 10485991 Jun 20  2017 log_154.xml
-rw-r----- 1 oracle asmadmin 10485812 Jun 21  2017 log_155.xml
-rw-r----- 1 oracle asmadmin 10485861 Jun 21  2017 log_156.xml
-rw-r----- 1 oracle asmadmin 10486012 Jun 21  2017 log_157.xml
-rw-r----- 1 oracle asmadmin     3048 Jun 21  2017 log_158.xml
-rw-r----- 1 oracle asmadmin 10486092 Jun 22  2017 log_159.xml
-rw-r----- 1 oracle asmadmin 10485946 Jun 22  2017 log_160.xml
-rw-r----- 1 oracle asmadmin 10485863 Jun 23  2017 log_161.xml
-rw-r----- 1 oracle asmadmin 10485854 Jun 23  2017 log_162.xml
-rw-r----- 1 oracle asmadmin 10485936 Jun 23  2017 log_163.xml
-rw-r----- 1 oracle asmadmin 10485948 Jun 24  2017 log_164.xml
-rw-r----- 1 oracle asmadmin 10485882 Jun 24  2017 log_165.xml
-rw-r----- 1 oracle asmadmin 10485814 Jun 25  2017 log_166.xml
-rw-r----- 1 oracle asmadmin 10485879 Jun 25  2017 log_167.xml
-rw-r----- 1 oracle asmadmin 10485939 Jun 25  2017 log_168.xml
-rw-r----- 1 oracle asmadmin 10485821 Jun 26  2017 log_169.xml
-rw-r----- 1 oracle asmadmin 10485939 Jun 26  2017 log_170.xml
-rw-r----- 1 oracle asmadmin 10485936 Jun 27  2017 log_171.xml
-rw-r----- 1 oracle asmadmin 10485876 Jun 27  2017 log_172.xml
-rw-r----- 1 oracle asmadmin 10486169 Jun 27  2017 log_173.xml
-rw-r----- 1 oracle asmadmin 10485951 Jun 28  2017 log_174.xml
-rw-r----- 1 oracle asmadmin 10486182 Jun 28  2017 log_175.xml
-rw-r----- 1 oracle asmadmin 10486140 Jun 29  2017 log_176.xml
-rw-r----- 1 oracle asmadmin 10485821 Jun 29  2017 log_177.xml
-rw-r----- 1 oracle asmadmin 10486098 Jun 29  2017 log_178.xml
-rw-r----- 1 oracle asmadmin 10485856 Jun 30  2017 log_179.xml
-rw-r----- 1 oracle asmadmin 10485849 Jun 30  2017 log_180.xml
-rw-r----- 1 oracle asmadmin 10486028 Jun 30  2017 log_181.xml
-rw-r----- 1 oracle asmadmin 10485768 Jul  1  2017 log_182.xml
-rw-r----- 1 oracle asmadmin 10485880 Jul  1  2017 log_183.xml
-rw-r----- 1 oracle asmadmin 10485774 Jul  2  2017 log_184.xml
-rw-r----- 1 oracle asmadmin 10485947 Jul  2  2017 log_185.xml
-rw-r----- 1 oracle asmadmin 10485896 Jul  2  2017 log_186.xml
-rw-r----- 1 oracle asmadmin 10485964 Jul  3  2017 log_187.xml
-rw-r----- 1 oracle asmadmin 10485810 Jul  3  2017 log_188.xml
-rw-r----- 1 oracle asmadmin 10485920 Jul  4  2017 log_189.xml
-rw-r----- 1 oracle asmadmin 10485827 Jul  4  2017 log_190.xml
-rw-r----- 1 oracle asmadmin 10485771 Jul  4  2017 log_191.xml
-rw-r----- 1 oracle asmadmin 10486064 Jul  5  2017 log_192.xml
-rw-r----- 1 oracle asmadmin 10485802 Jul  5  2017 log_193.xml
-rw-r----- 1 oracle asmadmin 10485868 Jul  6  2017 log_194.xml
-rw-r----- 1 oracle asmadmin 10485879 Jul  6  2017 log_195.xml
-rw-r----- 1 oracle asmadmin 10485782 Jul  6  2017 log_196.xml
-rw-r----- 1 oracle asmadmin 10485860 Jul  7  2017 log_197.xml
-rw-r----- 1 oracle asmadmin 10485893 Jul  7  2017 log_198.xml
-rw-r----- 1 oracle asmadmin 10485981 Jul  8  2017 log_199.xml
-rw-r----- 1 oracle asmadmin 10485869 Jul  8  2017 log_200.xml
-rw-r----- 1 oracle asmadmin 10485920 Jul  8  2017 log_201.xml
-rw-r----- 1 oracle asmadmin 10485915 Jul  9  2017 log_202.xml
-rw-r----- 1 oracle asmadmin 10486110 Jul  9  2017 log_203.xml
-rw-r----- 1 oracle asmadmin 10486011 Jul 10  2017 log_204.xml
-rw-r----- 1 oracle asmadmin 10485770 Jul 10  2017 log_205.xml
-rw-r----- 1 oracle asmadmin 10485821 Jul 10  2017 log_206.xml
-rw-r----- 1 oracle asmadmin 10485869 Jul 11  2017 log_207.xml
-rw-r----- 1 oracle asmadmin 10485779 Jul 11  2017 log_208.xml
-rw-r----- 1 oracle asmadmin 10485845 Jul 12  2017 log_209.xml
-rw-r----- 1 oracle asmadmin 10485843 Jul 12  2017 log_210.xml
-rw-r----- 1 oracle asmadmin 10485779 Jul 12  2017 log_211.xml
-rw-r----- 1 oracle asmadmin 10485780 Jul 13  2017 log_212.xml
-rw-r----- 1 oracle asmadmin 10485889 Jul 13  2017 log_213.xml
-rw-r----- 1 oracle asmadmin 10485833 Jul 13  2017 log_214.xml
-rw-r----- 1 oracle asmadmin 10485968 Jul 14  2017 log_215.xml
-rw-r----- 1 oracle asmadmin 10485797 Jul 14  2017 log_216.xml
-rw-r----- 1 oracle asmadmin 10485875 Jul 15  2017 log_217.xml
-rw-r----- 1 oracle asmadmin 10485790 Jul 15  2017 log_218.xml
-rw-r----- 1 oracle asmadmin 10485869 Jul 15  2017 log_219.xml
-rw-r----- 1 oracle asmadmin 10485923 Jul 16  2017 log_220.xml
-rw-r----- 1 oracle asmadmin 10485963 Jul 16  2017 log_221.xml
-rw-r----- 1 oracle asmadmin 10485852 Jul 17  2017 log_222.xml
-rw-r----- 1 oracle asmadmin 10485846 Jul 17  2017 log_223.xml
-rw-r----- 1 oracle asmadmin 10485941 Jul 17  2017 log_224.xml
-rw-r----- 1 oracle asmadmin 10485942 Jul 18  2017 log_225.xml
-rw-r----- 1 oracle asmadmin 10485878 Jul 18  2017 log_226.xml
-rw-r----- 1 oracle asmadmin 10485851 Jul 19  2017 log_227.xml
-rw-r----- 1 oracle asmadmin 10486089 Jul 19  2017 log_228.xml
-rw-r----- 1 oracle asmadmin 10485952 Sep 14 18:43 log_229.xml
-rw-r----- 1 oracle asmadmin 10485981 Sep 15 04:01 log_230.xml
-rw-r----- 1 oracle asmadmin 10486100 Sep 15 13:21 log_231.xml
-rw-r----- 1 oracle asmadmin 10485764 Oct 13 00:29 log_232.xml
-rw-r----- 1 oracle asmadmin 10486093 Oct 13 09:48 log_233.xml
-rw-r----- 1 oracle asmadmin 10485787 Oct 13 19:10 log_234.xml
-rw-r----- 1 oracle asmadmin 10486118 Oct 14 04:38 log_235.xml
-rw-r----- 1 oracle asmadmin 10486024 Oct 14 14:05 log_236.xml
-rw-r----- 1 oracle asmadmin 10485823 Oct 14 23:34 log_237.xml
-rw-r----- 1 oracle asmadmin 10485821 Oct 15 09:01 log_238.xml
-rw-r----- 1 oracle asmadmin 10485866 Oct 15 18:28 log_239.xml
-rw-r----- 1 oracle asmadmin 10485821 Oct 16 03:55 log_240.xml
-rw-r----- 1 oracle asmadmin 10485868 Oct 16 13:21 log_241.xml
-rw-r----- 1 oracle asmadmin 10485789 Oct 16 22:50 log_242.xml
-rw-r----- 1 oracle asmadmin 10485813 Oct 17 08:15 log_243.xml
-rw-r----- 1 oracle asmadmin 10485841 Oct 17 17:41 log_244.xml
-rw-r----- 1 oracle asmadmin 10485800 Oct 18 03:07 log_245.xml
-rw-r----- 1 oracle asmadmin 10485883 Oct 18 12:35 log_246.xml
-rw-r----- 1 oracle asmadmin 10485793 Oct 18 22:00 log_247.xml
-rw-r----- 1 oracle asmadmin 10485964 Oct 19 07:28 log_248.xml
-rw-r----- 1 oracle asmadmin 10486018 Oct 19 16:56 log_249.xml
-rw-r----- 1 oracle asmadmin 10485935 Oct 20 02:22 log_250.xml
-rw-r----- 1 oracle asmadmin 10486117 Oct 20 11:47 log_251.xml
-rw-r----- 1 oracle asmadmin 10485802 Oct 20 21:15 log_252.xml
-rw-r----- 1 oracle asmadmin 10485801 Oct 21 06:44 log_253.xml
-rw-r----- 1 oracle asmadmin 10486078 Oct 21 16:11 log_254.xml
-rw-r----- 1 oracle asmadmin 10485771 Oct 22 01:39 log_255.xml
-rw-r----- 1 oracle asmadmin 10485850 Oct 22 11:08 log_256.xml
-rw-r----- 1 oracle asmadmin 10486064 Oct 22 20:35 log_257.xml
-rw-r----- 1 oracle asmadmin 10486135 Oct 23 06:01 log_258.xml
-rw-r----- 1 oracle asmadmin 10485845 Oct 23 15:27 log_259.xml
-rw-r----- 1 oracle asmadmin 10485768 Oct 24 00:56 log_260.xml
-rw-r----- 1 oracle asmadmin 10485821 Oct 24 10:23 log_261.xml
-rw-r----- 1 oracle asmadmin 10486102 Oct 24 19:49 log_262.xml
-rw-r----- 1 oracle asmadmin 10486166 Oct 25 05:18 log_263.xml
-rw-r----- 1 oracle asmadmin 10485830 Dec 22 13:50 log_264.xml
-rw-r----- 1 oracle asmadmin  4378328 Jan 29 14:04 log.xml

find /u01/app/oracle/diag/rdbms/testdb/testdb/alert -type f -mtime +3 -exec rm -f {} \; -exec printf "." \;
......................................................................................................................................................[oracle@testdb alert]$
[oracle@testdb alert]$ ls -lrt
total 4300
-rw-r----- 1 oracle asmadmin 4398534 Jan 29 14:05 log.xml