Tuesday, April 21, 2015

Find and clean / remove files with a specific pattern in a deep directory tree

If you need to remove all the files that comply to:
* file pattern (eg *Uploads/*.pdf)
* a size constraint (eg >= 50k)
* older than some days before today (eg 365 days older)


find . -wholename *Uploads/*.pdf -size +50k -mtime +365 -print0 | xargs -0 rm

Create a zip file per directory and delete the directories

for i in *do[ -d "$i" ] && zip -rmT "$i.zip" "$i"done
# just -r for only zip (mT is for delete)
Remove only directories in Linux

cd thedirrm -rf */

Installing VirtualBox in Linux could fail about no kernel sources available DKMS.



If this is the case then set KERN_DIR variable and then again retry installing VirtualBox

## Current running kernel on Fedora ##
KERN_DIR=/usr/src/kernels/`uname -r`
## Current running kernel on CentOS and Red Hat (RHEL) ##
KERN_DIR=/usr/src/kernels/`uname -r`-`uname -m`
## Fedora example ##
KERN_DIR=/usr/src/kernels/2.6.33.5-124.fc13.i686
## CentOS and Red Hat (RHEL) example ##
KERN_DIR=/usr/src/kernels/2.6.18-194.11.1.el5-x86_64
## Export KERN_DIR ##
export KERN_DIR



Source: http://www.if-not-true-then-false.com/2010/install-virtualbox-with-yum-on-fedora-centos-red-hat-rhel/