Useful Linux commands

Following some of the most commonly used linux command which I have to use most of the times while managing hosted sites on my and client’ server. It is just few of them which I usually forget and just wanted to make a list here for my own personal reference.

Check os version in Linux

cat /etc/os-release
lsb_release -a
hostnamectl
cat /proc/version

Find Linux kernel version

uname -r

Change Directory

cd /home/admin/

Permissions

CHOWN

chown -R admin:admin Locale

chmod on folders/files

Remove (only) files recursively

By file type
find . -name “*.pyc” -exec rm -rf {} \;

Remove all files
find . -type f -exec rm -rf {} \;

Remove files from zip archive

zip -d gallery.zip “picture_43_9.jpg”

Delete All files/folders of a certain group

find . -group mygroup -exec rm -fr {} \;

GIT checkout to a folder

cd /home/admin/myrepo.git && git fetch 2>&1
GIT_WORK_TREE=/home/admin/mysitefolder/public_html git checkout -f [branch]
chown -R admin:admin
/home/admin/mysitefolder/public_html

Run cron every minute to hit an url

1 * * * * curl –request GET ‘http://url_to_hit

Edit Crontab

crontab -e

Generate RSA Key Pair

ssh-keygen -t rsa

Generate a private key

openssl genrsa 2048 > your_private_key_name.pem

Generate CSR with private key

openssl req -new -key your_private_key_name .pem -out your_csr_name.pem

RSA Config Private Key

Host bitbucket.org
IdentityFile ~/.ssh/bitbucket_rsa

Search a string in files

Adding the SSH-Keychain fingerprint

MySQL Command

To export db to sql file

To import sql to db

To enable a virtual host on apache

Restart Apache and PHP on centos 7

Apache on NetBSD

To know the process id of a service

netstat -nlp | grep :8080

To run React/Node app continuously on Linux server

npm start > stdout.txt 2> stderr.txt &

To get the summary of a grand total disk usage size of an directory

Extract tar.gz on NetBsd

Leave a Reply

Your email address will not be published. Required fields are marked *