Useful Linux commands

Following are some of the most commonly used Linux/Unix commands which I have to use at times while managing hosted sites on my and client’ server. Making a list for my own personal reference and ease. Someone may also find it useful.

Check os version in Linux

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

Find Linux kernel version

uname -r

Change Directory

cd /home/admin/



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 “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

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

IdentityFile ~/.ssh/bitbucket_rsa

To find or Search a string in files

Adding the SSH-Keychain fingerprint

MySQL Command

To export db to sql file

To export and zip in a single command

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

Show file permissions in numerical format


Leave a Reply