Useful shell

check the keyword in response header

$ curl -vvvsH "Host: software-center.ubuntu.com" -H "Accept-Encoding: gzip" http://91.189.89.82/api/2.0/applications/en/ubuntu/precise/i386/ 2>&1 > /dev/null | grep 'ETag\|X-Cache\|Content-Length\|Content-Type'

kill the pid of one application's

# kill `ps -ef | grep apache | awk '{print $2}'`

kill multiple pid related process

# kill `ps -ef | grep '7890\|7891' | awk '{print $2}'`

check linux kernel

# uname -a
Linux XPS-13 3.19.0-31-generic #36-Ubuntu SMP Wed Oct 7 15:04:02 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux

# lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 15.04
Release: 15.04
Codename: vivid

# cat /etc/issue
Ubuntu 15.04 \n \l

# getconf WORD_BIT
64

check graphic card info?

$ lspci -vnn | grep VGA -A 12
or
$ lshw -numeric -C display

check hardware acceleration

$ glxinfo | grep OpenGL

find motherboard model

$ sudo dmidecode -t baseboard | grep -i 'Product'
or 
$ inxi -M

check the network ports

$ sudo netstat -atunl | grep ':443'

check CPU and IO every 3 seconds

$ iostat nvme0n1 -cdmtyz 5

network tracing

$ mtr -4 -i 1 aws.memodir.com

$traceroute aws.memodir.com

search keyword in the file

$ ack-grep -A 1 origin_whitelist
configs/dc_staging_click-updown-lazr.conf
46:origin_whitelist: developer.staging.ubuntu.com
47-
configs/dc_production_click-updown-lazr.conf
46:origin_whitelist: myapps.developer.ubuntu.com
47-
configs/schema-lazr.conf
381:origin_whitelist:
servers/u1servers/click_updown/settings.py
122:CORS_ORIGIN_WHITELIST = config.cors.origin_white

Change language from command calling webAPI :

$ curl -H "Accept-Language: es" https://login.staging.ubuntu.com

Best way to kill all child processes

ps x -o  "%p %r %y %x %c "
$ kill -TERM -5112

get the partitions UUID

$ sudo blkid -o full -s UUID

find modified files 2 days ago

$ find . -type f -mtime -2

find modified files in 3 days

$ find -ctime -3

find and delete files under /data/backup over 6 days

$ find /data/backup -ctime +6 -exec rm -f {} \;

delete files in /data/backup that modified date is over 6 days, and remove emtpy folders

$ find /data/backup -type d -empty -exec rmdir {} \; >/dev/null 2>&1

find empty file that over 6 days

$ find ./ -type d -empty -ctime +6

only list today's files

$ ls -al[X|S] —time-style=+%D | grep ‘date +%D’
$ find . -maxdepth 1 -newermt “2016-12-07"

Test the server connection with port

$ nc -vzw5 hadar.canonical.com 5672

How to do the for-loop

1. for i in {1..10}; do echo $i; done
2. for in `seq 1 10`; do echo $i; done
3. for ((i=1;i<10;i++)); do echo $i; done

how to find zombie processes?

#Find them:
$ ps aux | grep 'Z'

#Find their parent's process:
$ pstree -p -s 26711

the methods to check a port is being listened on linux

$ sudo netstat -atunl | grep ':443'
list all (-a) tcp (-t) and udp (-u) listening sockets (-l) in nnumerical addresses (-n)

$ sudo lsof -i :443

$ nc -vz localhost 443

nc commands

#open a TCP connection to port 42, using 31337 as the source port, timeout = 5 seconds
$ nc -p 31337 -w 5 host.example.com 42

#open a UDP connection to port 53
$ nc -u host.example.com 53

connect to host.example.com via a HTTP proxy 10.2.3.4 port 8080 with the authentication
$ nc -x10.2.3.4:8080 -Xconnect -Pruser host.example.com 42

#data transfer
#computer A:
$ nc -l 1234 > file.out

#computer B:
$ nc -N host.example.com 1234 < file.in

check SSL certification

$ openssl s_client -host staging2.ttllaw.memodir.com -port 443

how to mount a disk?
if we have a 20GB disk, device name is /dev/vdb

$ fdisk -l
$ fdisk -u /dev/vdb
p -> n -> p -> 1 -> ... -> w

$ fdisk -lu /dev/vdb

$ mkfs.ext4 /dev/vdb1

$ sudo mkdir /data

$ echo /dev/vdb1 /data ext4 defaults 0 0 >> /etc/fstab

$ mout /dev/vdb1 /data

umount:

$ umount /data
 
$ df -h