10:49 PM Some great usage and example of find command in Linux |
Hello Linux/Unix lovers, I never knew that find command can be so useful. I have collated some cool find command example which can always help you in your work stations. I am sure you all know the format of find command. Format: find path criteria action Example find . -name "*.log" -exec ls -l {} \;
1. Find all the log file inside a folder/subfolder and delete or archive them.
2. Let's say you want to delete all txt files which are older than 60 days from /temp folder.
3. Now we want to delete/archive some set of files which are 3 months old and whose size is bigger than 1 mb.
4. Find out the total size of all log files in a folder which are 30 days older.
The above command will list files with their size in mb. Now you can apply logic to add the first column values to get total size using awk.
Using awk we added all the values in first column and print the total. Note:- du -ak afile shows file size in KB du -am afile shows file size in MB. likewise du -ag afile shows file size in GB. 5. List the files' count in a directory which are any files but not log files(*.log). find /path ! -name "*.log" -type f -exec ls -l {} \; | wc -l
6. List out all the directories in a folder recursively whose name is "archive" find . -name "archive" -type d "." points to current directory. 7. Archive any files which are older than 2 days and but exclude the files which are already zipped, from /tmp folder.
Here, gzip has below options: -v -> archive in verbose mode. -f -> if there is already a file with the name filename.gz, that will be replaced.
8. Search for a particular pattern in all ARD file inside a folder which are older than 90 and get their occurrence count. Don't look into *.zip.gz files
I will keep this article updated with new stuff. If you like it share it!! |
|
Related blogs
You may also like to see:
[2014-03-03] | [Open System-Linux] |
Working with VI Editor: Basic and Advanced |
[2014-03-13] | [Open System-Linux] |
crontab: A command in linux to automatically start/repeat a process at certian time and interval |
[2014-10-04] | [Open System-Linux] |
SYSCTL : A command to configure kernel parameters at runtime in linux |
[2014-02-19] | [Open System-Linux] |
Some unique and special commands in Linux |
[2015-05-25] | [Open System-Linux] |
Password-less Login to Linux/Unix Servers in Putty |
Total comments: 0 | |