Useful Linux commands – Linux Commands Cheatsheet

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

find /var/www -type d -exec sudo chmod 2775 {} + find /var/www -type f -exec sudo chmod 0664 {} +

Remove (only) files recursively

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

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

Zip file including hidden files

zip * .[^.]*

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

grep -rnw ‘/path/to/somewhere/’ -e ‘string_to_search’

Adding the SSH-Keychain fingerprint

ssh-keyscan -H >> ~/.ssh/known_hosts

MySQL Export/Import

To export db to sql file

mysqldump -u username -p DBNAME > filename.sql

To export and zip in a single command


mysqldump -u username -p DBNAME | zip >


To import sql to db

mysql -u username -p -h localhost DATA-BASE-NAME < data.sql

To enable/Link a virtual host on apache

sudo ln -s /etc/httpd/sites-available/default.conf /etc/httpd/sites-enabled/default.conf

Restart Apache and PHP on centos 7

systemctl restart httpd.service systemctl restart php-fpm.service

Apache on NetBSD


/etc/rc.d/apache start /etc/rc.d/apache stop


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

du -sh /home/devarticles

Extract tar.gz on NetBsd

tar xfzv archive.tar.gz

Show file permissions in numerical format

stat -c '%A %a %n' /path/to/folder # * for current folder

To Set an additional user the rwx rights to a folder

setfacl -m u:username:rwx myfolder


Leave a Reply