Migrated notes from mdnotes
This commit is contained in:
53
Fun with Find.md
Normal file
53
Fun with Find.md
Normal file
@@ -0,0 +1,53 @@
|
||||
# Fun with Find
|
||||
|
||||
## Find the total size of certain files within a directory branch
|
||||
|
||||
```bash
|
||||
find <path> -type f -iname '*-bin*' -exec du -ch {} +
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Find files larger than...
|
||||
|
||||
|
||||
### 100M:
|
||||
|
||||
|
||||
```bash
|
||||
find . -type f -size +100000k -exec ls -lh {} \; | awk '{ print $9 ": " $5 }'
|
||||
```
|
||||
|
||||
### 1G:
|
||||
|
||||
|
||||
```bash
|
||||
find . -type f -size +1000000k -exec ls -lh {} \; | awk '{ print $9 ": " $5 }'
|
||||
```
|
||||
|
||||
...and so on...
|
||||
|
||||
---
|
||||
|
||||
## Find, archive and purge old files
|
||||
|
||||
```bash
|
||||
# Find disk space used by logfiles older that 360 days
|
||||
find /var/log/hbase -type f -iname "*log*" -mtime +360 -exec du -ch {} +
|
||||
|
||||
# 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
|
||||
|
||||
# Delete the original files
|
||||
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.
|
||||
|
||||
[Reference](https://www.cyberciti.biz/faq/linux-unix-find-tar-files-into-tarball-command/)
|
||||
|
||||
---
|
||||
|
||||
|
||||
Tags:
|
||||
howto
|
||||
Reference in New Issue
Block a user