Cheatsheet
This page aim is just a reminder of useful commands, at least for me :)
Reminder
Most of those commands are working with bash, I do not try other shells.
Network and services
Check serivces on a specific port
lsof -i :5000
Iptables
sudo iptables -L
sudo iptables --line -vnL
Check if Apache server is working i.e. listening on port 80
sudo netstat -anp |grep apache
check if default page of apache is working (if no browser)
wget http://127.0.0.1/ -O /dev/null
curl -4 http://ip
Find Listening Network Ports
netstat -tulpn
Run simple http server
python3 -m http.server
Multimedia
Resize jpg
The convert program is a member of the ImageMagick(1) suite of tools. Source
convert image.jpg resize 960x1280 image.jpg
Convert image with hotizontal mirror effect
convert -flop cursiveLetters.pdf cursiveLettersMirror.pdf
Cut a video from a start time to specific end time
ffmpeg -i henri.webm -ss 00:04:52 -t 00:08:52 -async 1 file_name.mp4
Development
Install node/npm through nvm, fix binary path issue
If we install node through apt-get, the globally installed package installation will fail when the symlink will be created into the /usr/bin folder. Instead of using sudo, it is better to use nvm, indeed we will be able to choose which version to install. However after a successful installation, the path of node, and npm will be something like /home/tom/.nvm/versions/node/v10.17.0/bin/node. Even if this path is in PATH, I have encountered a case where node is looked for in /usr/bin, so we need to add a symlink to solve all potential issues.
nodepath=$(which node); sudo ln -s $nodepath /usr/bin/node
npmpath=$(which npm); sudo ln -s $npmpath /usr/bin/npm
Linux
Delete terminal history
history -cw
Docker
Run a container and attach a shell
#Get a image id
docker image ls
#Run it
docker run -it <image-id> /bin/bash
Tmux
Create a session
tmux new -s <session_name>
Detach a session
Ctrl^b d
List all sessions
tmux ls
Attach a session
tmux attach-session -t <session_name>
Kill a session
If you are in an attached sesion just type :
exit
Or from outside :
tmux kill-session -t <session_name>
Latex
Indent your .tex files :
latexindent comes automatically after intalling latex in your distrubution. The following command overwrite the file but create a backup.
latexindent --overwrite myLatexFile.tex