Linux Cheatsheet is here just to not waste time when i will try to remember one of these commands.
1. Find all files changed in a certain range of time
To find all files modified on the 26 June, 2015:
$ find /home/user/docs/ -type f -newermt 2015-04-26 ! -newermt 2015-04-27
-newermt – modified files
-newerat – accessed files
-newerct – files which had their permission changed
2. Find files containing text
grep --include=\*.php -rnw /home/user/docs/ -e "birthday"
3. Get a number of files in a directory
ls -1 /home/user/docs/ | wc -l
4. Delete large number of files
rm does not help in this cause. Usually you will get smth like “/bin/rm: Argument list too long.”
find /home/user/docs/ -type f -delete
5. Change owner/group of files recursively
sudo chown -R www-data:www-data /home/user/docs/
6. Change permission of files recursively
sudo chmod -R 770 /home/user/docs/
7. Get folder size
du -hs /path/to/directory
-h is to get the numbers “human readable”, e.g. get 140M instead of 143260 (size in KBytes)
-s is for summary (otherwise you’ll get not only the size of the folder but also for everything in the folder separately)
8. Find files bigger than 100MB
find . -type f -size +100M
If you want the current dir only:
find . -maxdepth 1 -type f -size +100M
9. Working with iptables
add rule to block certain IP
iptables -A INPUT -s xx.xx.xx.xx -j DROP
insert rule to block IP into first line
iptables -I INPUT 1 -s xx.xx.xx.xx -j DROP
save current iptables rules to file
iptables-save > ip-tables
search for blocked IP address
iptables -L INPUT -v -n | grep xx.xx.xx.xx
list INPUT rules with line numbers
iptables -L INPUT -n --line-numbers
delete rule on line 3
iptables -D INPUT 3
To be updated…