Miscallenous Useful Commands page index

wget https://hostname.fqdn/ --delete-after --no-check-certificate (equivalent curl -k) wget --no-check-certificate Forge a POST request for tests:
curl -i -X POST -H 'Content-Type: application/json' -d '{"name": "New item", "year": "2009"}' https://domain.com/ curl -i -X POST -H 'Content-Type: application/php' -d '{"name": "wanan.php}' https://domain.com/ Add a network route:
route add default gw {IP-ADDRESS} {INTERFACE-NAME} ip route add via Remotely tcpdump all traffic except ssh on port 22:
ssh root@ -- "tcpdump -w - -s 65535 'not port 22' > capture.pcap

Network File systen - NFS

Lines example in fstab:
/mnt/db1 IP_ADDRESS/,sync) /mnt/db0 IP_ADDRESS/,sync) Manual Mount Commands:
mount -o nolock IP_ADDRESS_NFS_SERVER:/shared/mount/point /LOCAL/MOUNT/POINT Example:
mount -o nolock IP_ADDRESS:/mnt/db1 /srv/db1 /mnt/dnbd1 IP_ADDRESS/,sync) /mnt/dnbd0 IP_ADDRESS/,sync) mount -o nolock IP_ADDRESS:/mnt/dnbd0 /srv/dnbd0 mount -o nolock IP_ADDRESS:/mnt/dnbd1 /srv/dnbd1


Watching established connection between two hosts:
watch -d -n 3 "netstat -ap | grep `hostname`:4444[1-4] | grep ESTABLISHED" Watching a reverse proxy access_log, counting requests:
cd /logs && for s in `ls -lrt *_access_log | grep " $(date "+%b %d")" | grep -v servername| awk '{print $9}'`; do flog $s; done Remote multi tail on log files passed through colorization (with ccze):
ssh -i id-do-sfo02 root@web01 -p9922 'tail -F /logs/*.log | ccze -A' flog: dump STDIN to file and reopen on SIGHUP
The always useful tail, cat and consorts:
tail -f /logs/access | grep 'string' tail -f /logs/access | grep -E --color "$string|OtherString|AnotherString" cat /logs/access | grep -E "string" | tail -1 | awk '{print $3}' | cut -d= -f2 Limites, lsof, fuser and watch:
/proc/$PID/limits \___Limits N directory N maximum files opened at the same time, Number N of file descriptor sysctl limites.conf lsof |___________ Check process or user using a remote FS fuser | watch -d -n TEMPS en secondes "commande | commande 2 | etc..."


Manage Services via SYSTEMCTL:
systemctl list-units --type=service systemctl is-active service_name.service Rename an host:
hostnamectl set-hostname NEW_NAME_HERE systemctl restart systemd-logind.service Example:
hostnamectl set-hostname debsrv01 && systemctl restart systemd-logind.service Reconfigure Time Zone:
dpkg-reconfigure tzdata

Miscellaneous awesome commands

ctrl+R in bash <= reverse search ctrl+L in bash <= clear screen apachectl -t <= Test Apache configurations chkconfig systemctl cd - <= returns to your previous directory See what is installed on a Debian / Ubuntu system:
dpkg-query -f '${binary:Package}\n' -W How To Remove All Packages Installed After a Date:
grep "2015-12-19.*.install " /var/log/dpkg.log | awk '{ print $4 }' | cut -d: -f1 > file.txt apt-get remove --purge | paste -s -d ' ' file.txt bg <= Backgrounds a job, more on jobs, see the jobs command fg <= Foregrounds a job, more on jobs, see the jobs command free uname whereis whatis id / whoami who <= who's connected w <= What do connected users do? Disk Usage: Easier and shorter way to read outpur for DU -H on a single folder, example:
du -h --max-depth=1 . mtr <= MyTraceRoute ping + traceroute combined nl <= number of lines in a file ss <= netstat likely but with more options and info tree (not by default in system bins) pstree (of a pid: awesome!) A blank space before typing a command in Bash Shell will prevent it from being recorder in history. FILE and STAT on a file give back info:
file infos.txt && stat infos.txt less Shift+F = tail -f
Copy file permissions from one to another:
chown --reference=reference_file file chmod --reference=users.list users1.list users2.list users3.list THE column COMMAND, awesome too:
mount | column -t screen ./long-unix-script.sh To use when the command long-unix-script.sh is running hit CTRL+A and the D to de-attach from current bash/terminal process.
Then to re-attach use:
screen -r 4980.pts-0.localhost => PID_NUMBER.pts-DEVICE_NUMBER.host_where_command_runs
tac is cat inversed a bit like a tail.
Init Commands:
init 0 <= Is "reboot" harshly
init 6 <= Is "shutdown -r now", gracefully
sort -f -b <= Sorts the content of a file
sort -f -b -o OUTPUT_FILE <= To a specific output file named