Frequently used Bash Commands

Frequently used Bash Commands

# find first level js, and grep
find */*.js -print0 | xargs -0 grep --color 'treemap'
# find lines of code
find */*.html *.html -print0 | xargs -0 wc -l -c
# Search word in files
grep -rnw '/path/to/somewhere/' -e 'pattern'
grep -nR --include="*.py" -E "work" "/path/"
# with depth
find -maxdepth 3 -path '*.py' -print0 | xargs -0 grep -n 'importlib' --color=always
# List 10 last modified files
ls -lht --time-style=full-iso /mnt/location/ | head -10
# or use subshell like
(cd /mnt/location/ && ls -lht --time-style=full-iso | head -10)
# Run command in background
nohup jupyter notebook --listen.port=7001 &
# Run in background and redirect log
nohup python script.py > ~/script.out &
# Find process on file
sudo fuser -v db.sqlite3
# Find Owner of a Process
ps aux | grep 7001
fuser 7001/tcp
# Kill process running a port
fuser -k 7001/tcp
# Kill a process PID
kill -9 {PID}
# Check if Nginx is Running
service nginx status
ps -aux | grep nginx
# Check if nginx config is working
nginx -t
# Check nginx configuration
nginx -V
# copy the entire revenge dir from your server to your local
scp -r user@server.com:~/revenge ~/revenge
# Print file without comments
grep ^[^#] file.txt
cat file.ext | egrep -v "^\s*(#|$)"
# Find all css files in sub-directories BUT ignore node_modules 
find . -path ./node_modules -prune -o -name '*.css' -print
# flake8 on git diff on python files
flake8 $(git status -s | grep -E '\.py$' | cut -c 4-)
# Image resize in folders
find Album-2 -iname "*.jpg" | while read f; do echo $f; convert -resize 20% "$f" "resize-$f"; done
# make the current user own the folders and sub
sudo chown -R $USER ~/.blabla
# run remote commands via ssh
ssh server 'find /mnt/ -type f | wc -l'
# folder size
du -sh /mnt/location/
# rsync
rsync -avz /localpath/file root@remoteip:/path/
rsync -chavzP --stats source target

22. Mar 2021