Table of contents
Hello Friends,
Today I am going to write a short blog on find and diff command which is very important for DevOps engineers.
Find Command
The find command is used to search files or directories in Linux. We can use the find command in various conditions like finding a file by
Permission
Size
Users
Groups etc.,
Syntax: find / <options> <filename>
Options | Usage |
-name | To search a file with its name |
-user | To search a file who is the owner or user of a file |
-group | To search for a file belonging to a particular group |
/ => It means it will search in all directories.
. => It means it will search in current directories
Now we will see the find command with some use cases.
How to search a file1 in the home directory?
[root@ip-172-31-89-38 ~]# find ~ -name file1.txt /root/file1.txt
How to search a file1 in the current directory?
[root@ip-172-31-89-38 ~]# find . -name file1.txt ./file1.txt
How to search all files whose permission is 777?
[root@ip-172-31-89-38 ~]# find -type f -perm 777 ./file3.txt
How to search all empty files?
[root@ip-172-31-89-38 ~]# find . -type f -empty
How to display the files which are older than 30 days?
mtime ==> it means modified time.
Display 30 days old files in the current working directory.
$find. -mtime +30 print
Display 30 days old files in a specific directory.
$find <directory path> -mtime +30 print
How to delete all the files which are older than 30 days?
$find <directory path> -mtime +30 delete
diff command
diff command is used to see the difference between two files.
Syntax: diff <file1> <file2>
I hope this blog would be informative.
Thank You for reading this blog
Parimal Pradhan
You can follow me on LinkedIn for my daily updates:- linkedin.com/in/parimal-pradhan-b62021168