Sponsored Content
Full Discussion: Ls -l and rm
Top Forums UNIX for Beginners Questions & Answers Ls -l and rm Post 303038520 by Neo on Thursday 5th of September 2019 05:58:22 AM
Old 09-05-2019
You can use find with the -exec flag for this.

For example in Linux:

Code:
find /path/to/files* -mtime +30 -exec rm {} \;

Note that there must be spaces between rm, {} and \;

More Explanation:

The first argument is the path to the files you want to delete. This can be a path, a directory, or a wildcard as in the example above. I would recommend using the full path, and make sure that you run the command without the exec rm to make sure you are getting the right results.


The second argument, -mtime, and this switch is used to specify the number of days old that the file is. If you enter +30, it will find files older than 30 days.

The third argument, -exec, allows you to pass in a command such as rm. The {} \; at the end is required at the end the of the command.


NOTE:

Do not run this without testing it first... for example. always run first and look at the output, for example:

Code:
find /path/to/files* -mtime +30  > /tmp/testing_123.txt


After you are happy it is working as you wish, then you can run it.. but honestly, here is what I do:

Code:
mkdir /tmp/files_to_delete
find /path/to/files* -mtime +30 -exec mv {} /tmp/files_to_delete \;

Better to move first and delete later!!! ALWAYS

Get in the very good habit of moving files before you delete them, especially using scripts where one fat finger mistake can ruin your day!

Last edited by rbatte1; 09-05-2019 at 12:36 PM..
 
DH-EXEC-INSTALL(1)						      dh-exec							DH-EXEC-INSTALL(1)

NAME
dh-exec-install - Install (and possibly rename) files. SYNOPSIS
#! /usr/bin/dh-exec debian/default.conf => /etc/my-package/start.conf usr/bin/* DESCRIPTION
Being a sub-command of dh-exec(1), this program must not be ran directly, but through dh-exec, which automatically runs all available sub-commands if run bare; or explicitly with dh-exec --with=install. It is meant to be used for dh_install(1) files, and those alone. If it finds that its input is not such a file, it will do nothing, but echo back the contents. The purpose of the program is to extend dh_install(1)'s functionality, by allowing to specify a destination filename. This can be accomplished by a special syntax: the " => " mark between a source and a destination means that the source file should be installed with the specified destination name. For obvious reasons, the source must not be a wildcard, and the destination in this case must be a file, and not a directory. All other non-comment lines are left alone. RESTRICTIONS
Due to the way executable scripts are called from debhelper(1), there is no way to know what options were used for the original dh_install(1). This means, that the --sourcedir option of dh_install(1) will not work correctly when dh-exec-install is in use. IMPLEMENTATION
Internally, the renaming happens by creating a temporary directory under debian/tmp/, and copying (or moving, if the source was under debian/tmp/ to begin with) the file there, with the new name. This is done this way to allow dh_install(1) to do the real copying, and allow its options to continue working, even when renaming is involved. The temporary directory is put under debian/tmp so that it will be cleaned by dh_prep(1) when the clean target gets to run. Thus, no extra code is needed anywhere to clean up the renamed files. ENVIRONMENT
DH_EXEC_SCRIPTDIR Indicates which directory the command-specific scripts should be sought for. If not specified, scripts will be searched for in /usr/share/dh-exec/. FILES
$DH_EXEC_SCRIPTDIR/dh-exec-install-* The various scripts for the higher-level program. SEE ALSO
debhelper(1), dh-exec(1), dh_install(1) AUTHOR
dh-exec-install is copyright (C) 2011-2012 by Gergely Nagy <algernon@madhouse-project.org>. 2012-05-03 DH-EXEC-INSTALL(1)
All times are GMT -4. The time now is 04:41 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy