DIFFERENT SCENARIOS TO FIND FILES IN LINUX

DIFFERENT SCENARIOS TO FIND FILES IN LINUX

You are required to find last 7 days archivelog files generated by oracle database

[root@orcl19x /]# find . -name *.arc -type f -print -mtime +7
./data01/FRA/ORCL19X1/archivelog/2021_02_22/o1_mf_1_841_j36x7nj7_.arc
./data01/FRA/ORCL19X1/archivelog/2021_02_22/o1_mf_1_842_j374n3wc_.arc
./data01/FRA/ORCL19X1/archivelog/2021_02_24/o1_mf_1_843_j3bolp6y_.arc
./data01/FRA/ORCL19X1/archivelog/2021_02_25/o1_mf_1_844_j3gbntv3_.arc
./data01/FRA/ORCL19X1/archivelog/2021_02_25/o1_mf_1_845_j3gc0l9z_.arc
./data01/FRA/ORCL19X1/archivelog/2021_02_25/o1_mf_1_846_j3gcf32l_.arc

You are required to list all the files from last 7 days

[root@orcl19x /]# find . -name *.arc -type f -print -mtime +7 -ls
./data01/FRA/ORCL19X1/archivelog/2021_02_22/o1_mf_1_841_j36x7nj7_.arc
44214794 37444 -rw-r-----   1 oracle   oinstall 38341120 Feb 22 14:40 ./data01/FRA/ORCL19X1/archivelog/2021_02_22/o1_mf_1_841_j36x7nj7_.arc
./data01/FRA/ORCL19X1/archivelog/2021_02_22/o1_mf_1_842_j374n3wc_.arc
44214795 41716 -rw-r-----   1 oracle   oinstall 42715648 Feb 22 16:46 ./data01/FRA/ORCL19X1/archivelog/2021_02_22/o1_mf_1_842_j374n3wc_.arc
./data01/FRA/ORCL19X1/archivelog/2021_02_24/o1_mf_1_843_j3bolp6y_.arc
44214798 27060 -rw-r-----   1 oracle   oinstall 27708928 Feb 24 00:54 ./data01/FRA/ORCL19X1/archivelog/2021_02_24/o1_mf_1_843_j3bolp6y_.arc
./data01/FRA/ORCL19X1/archivelog/2021_02_25/o1_mf_1_844_j3gbntv3_.arc
44214801 11028 -rw-r-----   1 oracle   oinstall 11290624 Feb 25 10:12 ./data01/FRA/ORCL19X1/archivelog/2021_02_25/o1_mf_1_844_j3gbntv3_.arc
./data01/FRA/ORCL19X1/archivelog/2021_02_25/o1_mf_1_845_j3gc0l9z_.arc
44214802 41248 -rw-r-----   1 oracle   oinstall 42235392 Feb 25 10:18 ./data01/FRA/ORCL19X1/archivelog/2021_02_25/o1_mf_1_845_j3gc0l9z_.arc
./data01/FRA/ORCL19X1/archivelog/2021_02_25/o1_mf_1_846_j3gcf32l_.arc

You want to housekeep the server to take care of space crunch and you need to delete log files older than last 7 days

Note: Be careful when you use this command. Specify the right path and perform deletion. Ensure that you dont delete any critical files which are used by process

[root@orcl19x /]# find . -name *.trc -type f -mtime +7 -exec rm -rf {} \;

You were requested by application team to find the application directories which got created in the last 7 days,then use this command

[oracle@exdbadm01 ~]$ find . -type d -print -mtime +7
.
./oradiag_oracle
./oradiag_oracle/diag
./oradiag_oracle/diag/clients
./oradiag_oracle/diag/clients/user_oracle
./oradiag_oracle/diag/clients/user_oracle/host_17562726_80

You got a request to find the top 10 files which occupy more space in home directory

[oracle@exdbadm01 ~]$ find /home/oracle/ -type f -print -mtime +7 -exec du -csh {} \; | sort -nr|head
884K    total
884K    /home/oracle/Scripts/Chapter8/awrdiff_1_17_1_19.html
616K    total
616K    /home/oracle/awrrpt_1_112_113.html
440K    total
440K    /home/oracle/Scripts/Chapter7/awrrpt_1_13_14.html
428K    total
428K    /home/oracle/Scripts/Chapter11/awrrpt_1_54_55.html
420K    total
420K    /home/oracle/Scripts/Chapter11/awrrpt_1_56_57.html

[oracle@exdbadm01 ~]$ find . -type f -perm 777 -print
./stack.sql
./strace
./.libcell15.trc.swp
./runload??
./sqltest.log
./oradiag_oracle/diag/clients/user_oracle/host_17562726_80/trace/sqlnet.log
./oradiag_oracle/diag/clients/user_oracle/host_17562726_80/alert/log.xml
./oradiag_oracle/diag/clients/user_oracle/host_17562726_80/lck/AM_1096102262_3454819329.lck
./oradiag_oracle/diag/clients/user_oracle/host_17562726_80/lck/AM_3216668543_3129272988.lck
./oradiag_oracle/diag/clients/user_oracle/host_17562726_80/lck/AM_1096102193_3488045378.lck

Leave a Reply

%d bloggers like this: