Possible Issues, Solutions, and Helpful Commands in Linux
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
To manually adjust the date in the correct timezone if it is still incorrect
date -s '2014-12-25 12:34:56'
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
To fix the issue where the user is running dash instead of bash after SSH due to user configuration
chsh -s /bin/bash $(whoami)
To view applications killed by the OOM Killer
dmesg -T | egrep -i 'killed process'
Disk Operations
Checking usage and limits about current disks
df -h
Checking usage and limits on specific path
du -sh <FILE_PATH>
Memory Operations
Memory details
cat /proc/meminfo
Current memory usage and limits
free -g
Processor Operations
Cpu details
less /proc/cpuinfo
lscpu
Checking Cpu core count
cat /proc/cpuinfo | grep processor | wc -l
Checking total Thread count
ps -eo nlwp | tail -n +2 | awk '{ num_threads += $1 } END { print num_threads }'
cat /proc/sys/kernel/threads-max
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
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
Setting Process count limit for current user
ulimit -Su 30000
Jar Operations
Extracting from jar
jar -xf apinizer-gateway-2.1.2.jar
Compress as Jar
jar -cf apinizer-gateway-2.1.2.jar **
Compressing file with manifes file as jar
/opt/apinizerManager/jre8162linux/bin/jar -cfm apinizer-gateway-2.1.2.jar ./META-INF/MANIFEST.MF **
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>
Extract tar.gz and compress as zip
tar xzf jre282linux.tar.gz && zip jre282linux.zip $(tar tf jre282linux.tar.gz)
List of open files
lsof | wc -l
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
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
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]* //'
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
#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
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
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
Network Operations
Checking a user process or service of specific port
netstat -ltnp | grep -w ':80'
With the running port
|
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
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>
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!
To exit and save changes
:wq
Change All
:%s/old_word/new_word/g
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
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