find . -name "*.pyc" -exec rm -rf {} \;
or use this:
find . | grep -E "(__pycache__|\.pyc|\.pyo$)" | xargs rm -rf
source: link
find ~/ -type d -name "directoryname"
find ~/ -type f -name "filename"
apt-get install $(grep -vE "^\s*#" filename | tr "\n" " ")
grep -rnw '/home/to/specific/path/' -e 'pattern'
grep -Ril "MyWord" /
i
stands for ignore case (optional in your case).R
stands for recursive.l
stands for "show the file name, not the result itself"./
stands for starting at the root of your machine.
source : (here)[https://stackoverflow.com/a/16956844/1756032]
find . -name '*.php' | xargs wc -l
find . -name '*.py' | xargs wc -l
find . -name '*.js' | xargs wc -l
find . -name '*.html'| xargs wc -l
find . -name '*.css' | xargs wc -l
- compression
tar -czvf name-of-archive.tar.gz /path/to/directory-or-file --exclude=.git/ --exclude=.github/ --exclude=*.mp4
- compression without .git version (This excludes all version control system directories)
--exclude-vcs
tar -czvf archive.tar.gz --exclude-vcs --exclude='*.zip' /home/username/mycode
- decompression
tar -xzvf archive.tar.gz -C /tmp
yourcommand > /dev/null 2>&1
to run in the background add an &
yourcommand > /dev/null 2>&1 &
>/dev/null 2>&1
means redirectstdout
to/dev/null
ANDstderr
to the place wherestdout
points at that time
If you want stderr
to occur on console and only stdout
going to /dev/null
you can use:
yourcommand 2>&1 > /dev/null
In this case
stderr
is redirected tostdout
(e.g. your console) and afterwards the originalstdout
is redirected to/dev/null
If the program should not terminate you can use:
nohup yourcommand &
Without any parameter all output lands in nohup.out
.bashrc
is not sourced when you log in using SSH. You need to source it in your .bash_profile
(for debian .profile
) like this:
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
source: here
echo "put /tmp/test.txt /tmp/" | sftp [email protected]
source: here
nmap -sP 192.168.1.0/24
to get ssh version
timeout 1 cat </dev/tcp/192.168.1.10/22
sudo kill -9 `sudo lsof -t -i:8000`
you can use use $()
for command interpolation
sudo kill -9 $(sudo lsof -t -i:8000)
source: here
# find everything in /var/www/html and set to read-only #
find /var/www/html -iname "*" -print0 | xargs -I {} -0 chattr +i {}
to allow again read/write on directory
find /var/www/html -iname "*" -print0 | xargs -I {} -0 chattr -i {}
using printenv
command
printenv
source: here
to print quiet pretty sorted
env -0 | sort -z | tr '\0' '\n'
# or
env | sort -f
source: here
In a nutshell swap is a piece of storage used from harddisk which can be used as additional RAM, to change the swap size:
- Turn off all running swap processes:
swapoff -a
- Resize swap
fallocate -l 1G /swapfile
to change to 1 GB size - CHMOD swap
chmod 600 /swapfile
- Make file useable as
mkswap /swapfile
- Active the swap file
swapon /swapfile
Some commands may take some time to be executed, just wait patiently for the commands to finish.
to verify swap size run the following command free -m
source: here
to get all keys
redis-cli> KEYS *
to delete redis related patterns
redis-cli --scan --pattern 'Product:*:*' | xargs redis-cli DEL
source: here
to disable all rules on iptables
iptables -F
iptables -X
iptables -t nat -F
iptables -t nat -X
iptables -t mangle -F
iptables -t mangle -X
iptables -P INPUT ACCEPT
iptables -P FORWARD ACCEPT
iptables -P OUTPUT ACCEPT
source: here