File Management

Zip up files in current directory and save to /root:
tar cvf - . | gzip > /root/myfile.tar.gz
Unzip in current directory from /root:
gunzip < /root/myfile.tar.gz | tar xvf -
Change owner and group of directories/files (-R means recursive):
chown -R exampleuser:examplegroup directoryname
Change permissions of directories/files (-R means recursive):
chmod -R 777 directoryname
Change all files in a directory to 644 permissions:
find /home2/username/public_html -type f | xargs chmod 644
Change all directories in a directory to 755 permissions:
find /home2/username/public_html -type d | xargs chmod 755
Delete files older than 100 days:
find /directory -mtime +100 -exec rm {} \;
Delete files with a certain name:
find /directory -name filename -exec rm {} \;
Find files larger than 100 Mb:
find / -size +100000k
Find files modified since yesterday:
find / -mtime -1
Find files that have a .exe extension owned by user apache and write them to a file:
find /var/www/vhosts \( -name '*.exe' -user apache -fprintf /root/suid.txt '%#m %u %p\n' \)
Find php files that have world write permissions:
find /path -name *.php -perm 777 -print
Search for text in all files:
grep -lir "some_text" *