How to find files on linux OS ( distributions )

If you are working on Linux OS, finding files effectively always a tricky part.

Like find files greater than 500 MB, find files which are created 2 days ago, find and delete all files recursively which are greater than specific date.

Lets learn these simple linux tricks to work with files.

How to find files or directory in Linux?

For Files command: 

find /path/to/directory -name "*.txt" -type f

For Directory

find /path/to/directory -name "nameOfDirectory" -type d

In the above commands only type argument is changed from f to d. f represents for file and d represents for directory.

How to find files which are greater than specific size?

find /path/to/directory -type f -size +1024M

How to find files which are created after number of days?

find /path/to/directory -mindepth 1 -mtime +5 -size +700M

How to delete files after finding files?

Method 1:

find /path/to/directory -mindepth 1 -mtime +5 -size +700M -delete

mindepth is for level

mtime for number of days

size is for file size greater than or equal to.

Method 2:

find . -name "*.done" -type f -print0 | xargs -0 rm -f

How to find files and set permission to 644 or 664?

find . -type f -print0 | xargs -0 chmod 0644

How to find all directory and set permission to 755 or 775?

find . -type d -print0 | xargs -0 chmod 0755

This is how you can work with find command. You can always check for man for more arguments.

Surya

Living in permanent beta mode: Learning, Improving & evolving. SPECIALTIES: Web Application Development, Digital Media, E-Commerce Solutions, SEO, CRM Solutions, Open Source Technologies, System Administration ( Linux ), VOIP Solutions, Cloud Computing, Web Security.

Share
Published by
Surya

Recent Posts

How to get the all the database and table sizes of MySQL or MariaDB?

If you are working with MySQL or MariaDB web server, sooner or later you will…

7 years ago

How to set or change default text editor for crontab in Linux?

To edit the crontab entries you use crontab -e. The command will check for the…

7 years ago

How to install Comodo SSL certificate with NGNIX web server?

Installation method for COMODO SSL Certificate If you have generated the CSR and purchased or…

7 years ago

How to give access to specific users to specific buckets on AWS S3

In AWS S3, you might want to provide the access to selected users to selected…

7 years ago

How to add or change the password (passphrase) of OpenSSH key?

It's possible you have earlier generated a ssh key without password/ passphrase. Later you found…

7 years ago

How to create CSR ( Certificate Signing Request ) for new SSL or to renew SSL?

What is SSL? SSL (Secure Sockets Layer) is a standard security protocol for establishing encrypted…

7 years ago