Commands and Scripts
Cpanel ,Linux ,Server Commands and Scripts
Articles
How to Exclude Files and Directories with rsync
To make rsync skip files or folders, add --exclude with a pattern, once per pattern:
rsync -av --exclude='cache/' --exclude='*.log' /var/www/site/ /backup/site/
Three...
How to Find Out Who is Using a File in Linux?
Lsof is used on a file system to identify who is using any files on that file system. You can run the lsof command on Linux filesystem and the output identifies the...
How to Find the Geographic Location of a Server From the Terminal
To find where a server, or any IP address, is located, ask an IP geolocation service from the terminal. The result is an estimate based on registration and routing...
How to Increase Swap Space in Linux
To increase swap space in Linux without a reboot, add a second swap file next to the swap you already have: create it with fallocate, run chmod 600, mkswap and swapon,...
How to Read ls -l Output in Linux: Permissions, Links, Owner, Size and Date Explained
Each line of ls -l has the same fields, left to right: file type and permissions, hard link count, owner, group, size in bytes, last modification time and name. This...
How to Use rsync to Copy and Sync Files and Directories in Linux
To copy files with rsync, run rsync -av SOURCE DESTINATION. For example rsync -av site/ /backup/site/ copies the contents of the site folder to /backup/site/, keeping...
Input Redirection in Linux: stdin, Here Documents and Here Strings Explained
Input redirection feeds a file, or text you type in the script, to a command’s standard input instead of the keyboard. command < file reads from a file,...
Linux Commands List by Category: A Quick Reference
Access Control
exit - terminate a shell (see "man sh" or "man csh")
logout - sign off; end session (C shell and bash shell only;)
passwd - change login...
Linux Uptime Command With Usage Examples
Uptime is a command that returns information about how long your system has been running together with the current time, number of users with running sessions, and the...
Nginx Redirect: How to Redirect a URL, HTTP to HTTPS and www
To redirect a URL in nginx, add a return line to the site's server block: location = /old-page.html { return 301 /new-page.html; } for one page, or return 301...
OpenVZ useful commands
Here is the list of some useful OpenVZ commands which should be run from the main node :
1. To fetch the consumption of disk for each container in the node along...
Script to restart server if load increases above a given limit
This script reboots the server automatically if its load average goes above a limit you set. Treat it as a stopgap for sudden load spikes, not a fix: if the server...
Setuid, Setgid and Sticky Bit in Linux: What They Do on Files and Directories
Linux has three special permission bits on top of read, write and execute. The setuid bit (octal 4, u+s) makes a program run with the rights of the file's owner...
Terminalizer: Record Your Linux Terminal and Generate Animated GIF
Terminalizer is a free, open source, simple, highly customizable and cross-platform program to record your Linux terminal session and generate animated gif images or...
The ar Command in Linux: Create and Extract Archives
To extract an ar archive, run ar x archive.a: every member is written to the current directory. ar t archive.a lists the members first, and ar rcs archive.a file1...
The echo Command in Linux: Print Text and Variables with Examples
echo prints its arguments followed by a new line. The $ belongs to the shell, not to echo: before echo runs, Bash replaces $name with the value of the variable name....
The sleep Command in Linux: Pause a Script for Seconds, Minutes or Hours
sleep pauses for the time you give it, then exits. sleep 5 waits five seconds. Add a suffix for other units: s seconds, m minutes, h hours, d days. It is mostly used...
Todo.txt: Manages Your Todo Tasks from Linux Terminal
odo.txt (todo.txt-cli) is an easy and extensible shell script for managing your todo.txt file. It allows you to add todos, list added todos, mark an entry as done,...
Understand more about vmstat
vmstat (virtual memory statistics) reports a summary of memory, processes, interrupts, paging and block I/O. Give it a delay (in seconds) to sample system activity...
bash: lsb_release: command not found on Debian: How to Fix It
bash: lsb_release: command not found on Debian means the lsb-release package is not installed. Minimal installs, cloud images and containers leave it out. Install it...
findmnt: Shows Currently Mounted File Systems in Linux
The findmnt command is a simple command-line utility used to display a list of currently mounted file systems or search for a file system in /etc/fstab, /etc/mtab or...
how to find and replace a word in the entire folder using single command?
Replace a word or URL in every file of a folder with one command, for example after changing a domain.
Steps
Back up the folder first: tar czf ~/backup-site.tar.gz...
npm Commands Cheat Sheet: install, ci, update, run and audit
npm is the package manager that comes with Node.js. These are the commands you use every day, with what they printed in our tests.
Start a project
npm init -y...
cPanel License Update Command: Update, Refresh or Renew a cPanel License Key (cpkeyclt)
To update a cPanel license, run /usr/local/cpanel/cpkeyclt as root on the server. It fetches the licence issued to your server's IP address from cPanel's licence...
Common cPanel Commands: Accounts, Services, Email, DNS and Backups
A quick reference of the command-line tools a cPanel server administrator uses for everyday jobs: accounts, services, updates, email, databases, DNS and backups. Run...