Find And Delete Files Older Than Some Particular Time Period In Linux

October 9th, 2022, posted in Solaris
Share

Searching By File Timestamp

Unix/Linux filesystems have three types of timestamp on each file. They are as follows:

  1. Access time (-atime): The timestamp when the file was last accessed.
  2. Modification time (-mtime): The timestamp when the file was last modified.
  3. Change time (-ctime): The timestamp when the metadata for a file (such as permissions or ownership) was last modified.

 

Search and delete file older than 7 days

Lets take an example, wherein we will find and delete file older than 7 days. We will be using the option “-mtime” of the find command for this.

1. Get a list of files using find command as follows:

# find /path_to_directory -mtime +7 -type f -exec ls {}\;

2. If the filenames start with any particular pattern, filter using that as follows:

# find /path_to_directory -name 'filenamepattern*' -mtime +7 -type f -exec ls {}\;

3. After checking and confirming the output, go for removal script(It is very IMPORTANT), otherwise there will be irrecoverable data loss.

# find /path_to_directory -name 'filenamepattern*' -mtime +7 -type f -exec rm -fv {}\;

# find . -name “*.pdf” -atime +7 -exec rm {} \;

4. If this needs to be done on a remote server through cron job and log the filenames of deleted files, use the following command

# ssh user@remote_ip "find /path_to_directory -name 'filenamepattern*' -mtime +7 -type f -exec rm -fv {} \; >> /tmp/backup_deletion`date +%Y%m%d`.log 2>&1"

 

Conclusion

The -mtime parameter will search for files based on the modification time; -ctime searches based on the change time. The -atime, -mtime, and -ctime use time measured in days. The find command also supports options that measure in minutes. These are as follows:

  1. -amin (access time)
  2. -mmin (modification time)
  3. -cmin (change time)

For example, to print all the files that have an access time older than seven minutes, use the following command:

# find . -type f -amin +7 -print

-newer option

The -newer option specifies a reference file with a modification time that will be used to select files modified more recently than the reference file.

Find all the files that were modified more recently than file.txt file:

# find . -type f -newer file.txt -print
Share

Hussain and Revolution by Josh Malihabadi

October 3rd, 2022, posted in Muharram, POEtRY..
Share

husain-aur-inqilab-josh-malihabadi-ebooks,Hussain and Revolution,Josh Malihabadi, Josh English Translation,Who Is Hussain, Immam Hussian

Hussain and Revolution,Josh Malihabadi, Josh English Translation,Who Is Hussain, Immam Hussian Hussain and Revolution,Josh Malihabadi, Josh English Translation,Who Is Hussain, Immam Hussian

Share

What Is The Difference Between 11i And R12 In Oracle Apps

September 25th, 2022, posted in Oracle
Share

11i
1) Consist of 3C
2) No concept of MOAC.
3) Major table changes like po_vendors.
4) Banks are created in Account Payables.
5) Ap_Invoices_lines_all table in finance is not there.

R12
1) Consist of 4C
2) Introduction of MOAC( Multi org access control)
3) Major table changes (Ap_suppliers)
4) Banks are created in Cash Management.
5) Subledger Accounting is not there.
5) Ap_invoices_lines_all is there.
6) Subledger Accounting is there.

Share

Kakashi Tells To Be Good Memory

September 18th, 2022, posted in Naruto
Share

kakashi

Share

What are the Aggregate Functions in Oracle SQL

September 18th, 2022, posted in Oracle
Share

Aggregate Functions

MIN returns the smallest value in a given column
MAX returns the largest value in a given column
SUM returns the sum of the numeric values in a given column
AVG returns the average value of a given column
COUNT returns the total number of values in a given column
COUNT(*) returns the number of rows in a table
Share