DevOps Linux commands
# Sometimes only access linux system using terminal, and need to check which linux version is,
lsb_release -a
# Open terminal and run one application/scripts with long console output, and try to search some keyword text in GUI,not impacted by previous command output, avoid to re-open new terminal to re-run, so clear terminal cache,
printf '\33c\e[3J'
# To check which ports are open on one ip
netstat -ntl | grep LISTEN
or
netstat -ntlp | grep LISTEN
or
#e.g. Check ip:192.168.1.10 and port:80
nc -zw3 192.168.1.10 80 && echo "opened" || echo "closed"
# Find command but only list files including text
find . -name '*.*' -exec grep -l 'keyword' /dev/null {} +
or
grep -Ril "keyword" /
# Output to log file, save and return exit code at the same time
sh command.sh | tee logfile
echo $?
or
echo ${PIPESTATUS[0]}