Priya
Priya

Reputation: 9

I wanna to delete all files and directories in linux

I have to delete all directories and files which should be 3 years back from current date what should be the specific command for that in linux.

Upvotes: 0

Views: 62

Answers (1)

Rémy
Rémy

Reputation: 454

It depends on how you define "3 years back": created, last modified... If that's last modified, you can do something like this to list those files

find /directory -mtime +1095

/directory is the starting directory, +1095 meaning modified 1095 days ago, 365*3.

If you're okay with the list, then add the delete option

find /directory -mtime +1095 -delete

Be careful not to put -delete before -mtime, there's a specific order there. See man find for more informations.

Upvotes: 1

Related Questions