create/update 'blog - fun with find.md' file

This commit is contained in:
anonymous
2024-02-02 14:30:18 -05:00
parent c480cd9864
commit b9a64bb97e

View File

@@ -1,47 +1,62 @@
# Fun with Find # Fun with Find
## Find the total size of certain files within a directory branch ## Find the total size of certain files within a directory branch
```bash ```bash
find <path> -type f -iname '*-bin*' -exec du -ch {} + find <path> -type f -iname '*-bin*' -exec du -ch {} +
``` ```
--- ---
## Find files larger than... ## Find files larger than...
### 100M: ### 100M:
```bash ```bash
find . -type f -size +100000k -exec ls -lh {} \; | awk '{ print $9 ": " $5 }' find . -type f -size +100000k -exec ls -lh {} \; | awk '{ print $9 ": " $5 }'
``` ```
### 1G: ### 1G:
```bash ```bash
find . -type f -size +1000000k -exec ls -lh {} \; | awk '{ print $9 ": " $5 }' find . -type f -size +1000000k -exec ls -lh {} \; | awk '{ print $9 ": " $5 }'
``` ```
...and so on... ...and so on...
--- ---
## Find, archive and purge old files ## Find, archive and purge old files
```bash ```bash
# Find disk space used by logfiles older that 360 days # Find disk space used by logfiles older that 360 days
find /var/log/hbase -type f -iname "*log*" -mtime +360 -exec du -ch {} + find /var/log/hbase -type f -iname "*log*" -mtime +360 -exec du -ch {} +
# Archive those files to another location # Archive those files to another location
find /var/log/hbase -type f -iname "*log*" -mtime +360 -print0 | xargs -0 tar cfz /tmp/hbase-logs.tgz find /var/log/hbase -type f -iname "*log*" -mtime +360 -print0 | xargs -0 tar cfz /tmp/hbase-logs.tgz
# Delete the original files # Delete the original files
find /var/log/hbase -type f -iname "*log*" -mtime +360 -delete find /var/log/hbase -type f -iname "*log*" -mtime +360 -delete
``` ```
Replace `hbase` with the log directory you want to search. If you don't need to save the archives anywhere, skip step two. Replace `hbase` with the log directory you want to search. If you don't need to save the archives anywhere, skip step two.
[Reference](https://www.cyberciti.biz/faq/linux-unix-find-tar-files-into-tarball-command/) [Reference](https://www.cyberciti.biz/faq/linux-unix-find-tar-files-into-tarball-command/)
---
## Find files by group and mode
Note: *from Teachingbooks web directory permission fix.* at OverDrive
Find files that have `group: www-data` and current `permissions: 644`, then update the permissions to 664
```bash
find <directory> -type f -group www-data -perm 644 -exec ls -al {} \;
find <directory> -type f -group www-data -perm 644 -exec chmod g+w {} \;
```
[Reference](https://ostechnix.com/find-files-based-permissions/)