delete files in linux

If you’re running out of space on your Linux machine and want to free up some space, so you need to know how to delete files and logs which are not required anymore. You can find files by date and also find files older than x days. Let’s see how to find the location of files in Linux.

How To Delete File And Logs Older Than 30 Days In Linux:

I will show you many ways and commands to delete the files.  

Check Out: How To Install RabbitMQ Message Broker On Linux

There’re many ways of doing this you just need to know the files which are not required anymore in your server. Simply remove or delete them using the single command in Linux.

if you want to delete 30 days old logs or files from the location, so run the below commands. you can also configure the log server and move older logs to that server using logrotate command

Check Out: Configure Role Based User Access In Jenkins Server On Linux

find /path/to/dir/ -mtime +30 -exec rm -rf {} \;

if you want to match "files pattern" and delete them.

find /path/to/dir/ -type f -mtime +days -name ’*.txt’ -execdir rm — ‘{}’ \;

Check Out: How To Install Git (Subversion Control) In Ubuntu 19.04

you can also user -delete the option to remove the files and this is the safest method.

find /path/to/dir/ -mdepth 1 -mtime +30 -delete

you can use -depth -print command instead of -delete to test this command.

You’re done linux find files older find location of file find files by date


Please enter your comment!
Please enter your name here