Linux
OS-Mgmt
Daily Use Cmd

Disk Usage Commands 🗂️

Check Disk Usage of Current Folder

sudo du -h --max-depth=1 -a
sudo du -h --max-depth=1 -a | sort -rh

Set Timezone and Hostname

timedatectl set-timezone Asia/Kolkata
hostnamectl set-hostname abc.com-server

Port Checking and Management 🌐

Check and Kill Port

sudo lsof -i :8000
ps -ef | grep nginx/dashboard
ss -tulnp
netstat -tulnp
netstat -tulnp | grep 8000
pgrep <service_name>

Directory and File Search 📂

Find Folder in a Directory

find /var/www -type d -name "static"

Search for a String in Files

grep "example" *.txt
grep "example" file1.txt file2.txt file3.txt file4.txt file5.txt file6.txt file7.txt file8.txt file9.txt file10.txt
findstr "example" *.txt
grep "^https://arctic\.admin\.in" repos.txt 

AWS S3 Commands ☁️

(To be filled based on your specific S3 commands)

Timezone Configuration ⏰

Set Timezone

timedatectl set-timezone Asia/Kolkata
timedatectl set-timezone America/New_York

Change Timezone Manually (Not Recommended)

sudo unlink /etc/localtime
sudo ln -s /usr/share/zoneinfo/[zone/timezone] /etc/localtime

PM2 Commands 📊

PM2 Management

pm2 status
pm2 save
pm2 resurrect
pm2 startup
pm2 show app-name
crontab -e 
    @reboot pm2 start /var/www/html/app.js
pm2 resurrect
pm2 status

Python Script Management 🐍

Run Python Script with Nohup

nohup python3 200ok.py > gunicorn-200ok.log &
kill PID
ps aux | grep 200ok.py

Other Useful Commands 💡

Extract and Start Services

tar -xzf bastillion-jetty-v3.15_00.tar.gz
nohup ./startBastillion.sh &  # Output will go to nohup.out in same directory 
./startBastillion.sh &   # Terminate the command after closing the terminal

Query Logs

# Extract the query line by line and save to file 
grep sql query-2024-01-31-19.log | jq -r '.sql' >> sql.log
# Remove duplicate lines in the file 
sort sql.log | uniq -c | sort -nr

List Installed Packages

apt list --installed | grep php  # Check packages installed

Create a Command Shortcut

sudo cp uat.sh /usr/local/bin/uat  # Create a command shortcut

Log Monitoring

sudo tail -f /var/log/apache2/error.log  # Tail log file
journalctl -u apache2.service | tail -n 20  # Journalctl for Apache2

Troubleshooting Commands 🛠️

Network and Service Troubleshooting

dig google.com
nslookup google.com
systemctl list-units 
systemctl list-units --all
systemctl list-unit-files
journalctl
journalctl -b  # Boot
journalctl -k  # Kernel messages
journalctl -k -b  # Current boot
journalctl -u nginx.service  # Logs of specific service
journalctl -b -u nginx.service  # Boot logs of specific service
systemctl list-dependencies nginx.service
systemctl list-dependencies --all nginx.service
sudo systemctl daemon-reload

Port Check and Kill

sudo lsof -i :8000
sudo netstat -tuln | grep 8000

🧙 AI Wizard - Instant Page Insights

Click the button below to analyze this page.
Get an AI-generated summary and key insights in seconds.
Powered by Perplexity AI!