Others

To correct the system time if it is in the wrong timezone, use the "date" command

sudo ln -sf /usr/share/zoneinfo/Europe/Istanbul /etc/localtime
BASH


To manually adjust the date in the correct timezone if it is still incorrect

date -s '2014-12-25 12:34:56'
BASH


In case of encountering the "no-key" error on Ubuntu

#W: GPG error: https://download.docker.com/linux/ubuntu focal InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 7EA0A9C3F273FCD8

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 7EA0A9C3F273FCD8
BASH


To fix the issue where the user is running dash instead of bash after SSH due to user configuration

chsh -s /bin/bash $(whoami)
BASH


To view applications killed by the OOM Killer

dmesg -T | egrep -i 'killed process'
BASH



Disk Operations

Checking usage and limits about current disks

df -h
BASH

Checking usage and limits on specific path

du -sh <FILE_PATH>
BASH

Memory Operations

Memory details

cat /proc/meminfo
BASH

Current memory usage and limits

free -g
BASH

Processor Operations

Cpu details

less /proc/cpuinfo
lscpu
BASH

Checking Cpu core count

cat /proc/cpuinfo | grep processor | wc -l
BASH

Checking total Thread count

ps -eo nlwp | tail -n +2 | awk '{ num_threads += $1 } END { print num_threads }'
 
cat /proc/sys/kernel/threads-max
BASH

Checking total Thread count of Java application

ps -ef | grep java
#The process ID of Java is written below, for example: 10057.
ps huH p 10057 | wc -l
BASH

Taking Dump

//jcmd-> While under the JRE
sudo -u apinizer ./jcmd 26032 Thread.print > ./Thread.dump
sudo -u apinizer ./jcmd 26032 GC.heap_dump ./Heap.dump
BASH

Setting Process count limit for current user

ulimit -Su 30000
BASH

Jar Operations

Extracting from jar

jar -xf apinizer-gateway-2.1.2.jar
BASH

Compress as Jar

jar -cf apinizer-gateway-2.1.2.jar **
BASH

Compressing file with manifes file as jar

/opt/apinizerManager/jre8162linux/bin/jar -cfm apinizer-gateway-2.1.2.jar ./META-INF/MANIFEST.MF **
BASH

File Operations

Copy files and directories between two locations with SCP

scp -r /opt/apinizerManager/* <REMOTE_SERVER_USER>@<REMOTE_SERVER_ID>:<PATH_TO_COPY_TO>
BASH


Extract tar.gz and compress as zip

tar xzf jre282linux.tar.gz && zip jre282linux.zip $(tar tf jre282linux.tar.gz)
BASH

List of open files

lsof | wc -l
BASH

See File settings

cat /etc/sysctl.conf
// system-wide maximum number of files 
cat /proc/sys/fs/file-max
cat /proc/sys/fs/file-nr
BASH

Check the biggest 10 files that are opened

cd /proc
for pid in [0-9]*
do
    echo "PID = $pid with $(ls /proc/$pid/fd/ | wc -l) file descriptors"
done | sort -rn -k5 | head | while read -r _ _ pid _ fdcount _
do
  command=$(ps -o cmd -p "$pid" -hc)
  printf "pid = %5d with %4d fds: %s\n" "$pid" "$fdcount" "$command"
done
BASH

Checking the processes that holds the most files open

lsof -Fnst | awk '
    { field = substr($0,1,1); sub(/^./,""); }
    field == "p" { pid = $0; }
    field == "t" { if ($0 == "REG") size = 0; else next; }
    field == "s" { size = $0; }
    field == "n" && size != 0 { print size, $0; }
' | sort -k1n -u | tail -n42 | sed 's/^[0-9]* //'
BASH



Firewall Operations

sudo iptables -A PREROUTING -t nat -i ens160 -p tcp --dport 443 -j REDIRECT --to-port 9443
iptables-save > /opt/apinizerManager/iptables.conf
BASH
#The following is written inside the `startManager`.
iptables-restore < /opt/apinizerManager/iptables.conf
 
max_allowed_packet=500M
lower_case_table_names=1
innodb_log_file_size=2G
BASH



Wget Operations

Downloading from Google Drive with Wget

wget --load-cookies /tmp/cookies.txt "https://docs.google.com/uc?export=download&confirm=$(wget --quiet --save-cookies /tmp/cookies.txt --keep-session-cookies --no-check-certificate 'https://docs.google.com/uc?export=download&id=Adres_Unique_Idsi_yZ8JlXtWwdOQg_5h' -O- | sed -rn 's/.*confirm=([0-9A-Za-z_]+).*/\1\n/p')&id=Adres_Unique_Idsi_yZ8JlXtWwdOQg_5h" -O apinizer.zip && rm -rf /tmp/cookies.txt
BASH

Sorting by File Size

sudo lsof
| grep REG
| grep -v "stat: No such file or directory"
| grep -v DEL
| awk '{if ($NF=="(deleted)") {x=3;y=1} else {x=2;y=0}; {print $(NF-x) "  " $(NF-y) } }' 
| sort -n -u 
| numfmt  --field=1 --to=iec
BASH

Network Operations

Checking a user process or service of specific port

netstat -ltnp | grep -w ':80'
BASH

With the running port

ss -antp
 State         Recv-Q        Send-Q                Local Address:Port                  Peer Address:Port
 LISTEN        0             128                         0.0.0.0:22                         0.0.0.0:*            users:(("sshd",pid=734,fd=4))
 ESTAB         0             0                    173.249.11.199:22                    3.83.11.233:48610        users:(("sshd",pid=44179,fd=5),("sshd",pid=44178,fd=5))
 ESTAB         0             0                    173.249.11.199:22                  176.43.11.169:4400         users:(("sshd",pid=4714,fd=5),("sshd",pid=4712,fd=5))
 ESTAB         0             0                    173.249.11.199:22                  176.43.11.169:4488         users:(("sshd",pid=1182,fd=5),("sshd",pid=1161,fd=5))
 ESTAB         0             0                    173.249.11.199:22                  78.175.12.218:37538        users:(("sshd",pid=4391,fd=5),("sshd",pid=4370,fd=5))
 ESTAB         0             40                   173.249.11.199:22                  78.175.12.218:40141        users:(("sshd",pid=4369,fd=5),("sshd",pid=4367,fd=5))
 ESTAB         0             0                    173.249.11.199:22                 222.186.13.130:12376        users:(("sshd",pid=44169,fd=5),("sshd",pid=44168,fd=5))
 ESTAB         0             0                    173.249.11.199:22                 157.230.12.208:56782        users:(("sshd",pid=44177,fd=5),("sshd",pid=44176,fd=5))
 LISTEN        0             128                            [::]:22                            [::]:*            users:(("sshd",pid=734,fd=6))    -t : Show only TCP sockets on Linux
 
//Diğer sık kullanılan parametreler şu şekildedir:
    -t : Show only TCP sockets on Linux
    -u : Display only UDP sockets on Linux
    -l : Show listening sockets. For example, TCP port 22 is opened by SSHD server.
    -p : List process name that opened sockets
    -n : Don’t resolve service names i.e. don’t use DNS



Certificate Operations

Obtaining a server certificate through a Linux server.

openssl s_client -showcerts -connect <URL>:443 </dev/null 2>/dev/null|openssl x509 -outform PEM > mycertfile.pem
BASH


Importing a certificate into a JAR file

/opt/apinizerManager/jre8282linux/jre/bin/keytool -import -trustcacerts -keystore /opt/apinizerManager/jre8282linux/jre/lib/security/cacerts -storepass changeit -alias <CERTIFICATE_ALIAS> -import -file <CERTIFICATE_FILE>
BASH



Vi Editor Operations

To list all commands related to Vi and Vim, you typically enter command-line mode by pressing the escape key, and many commands begin with the colon (:) character.

To exit without saving changes

:q!
BASH


To exit and save changes

:wq
BASH

Change All

:%s/old_word/new_word/g
BASH



CURL Operations

#To access SSL-protected addresses without verification -k
#for verbose logging -v
#For timeout -m 10
#To send username and make it asks for password  -u <USERNAME>
#To getting output --output response.txt

Logging the response after making a SOAP request

curl -D -  --header "Content-Type:text/xml;charset=UTF-8" --header "SOAPAction:XXX" -d '<SOAP_BODY_GOES_HERE>' https://api.adres/apigateway/relativepath >> response.txt
BASH

Accessing a WSDL address with Basic Auth (prompting for the password) and saving it

curl -u username "http://api.address.com?wsdl" --output response.wsdl
BASH