Common Linux Commands

Here you can find the most common Linux commands that I personally use everyday to administer few linux servers. All these Linux commands are typed in the command prompt (also known as terminal). Some commands may need root access to be executed, you can use sudo command to elevate the privileges of the command. If you found these Linux commands useful, share this page with your friends.

//Append text to a file
echo "content" >> <file>

//Overwrite a file's content
echo "content" > <file>

//Redirect (append) standard output to a file
ls -la >> <file>

//View resources being used on your system
top

//View who is logged on
who

//View used and available disk space
df -h

//Clear a command line screen
clear

//Start a service
service <name> start

//Stop a service
service <name> stop

//Restart a service
service <name> restart

//View the content of a file
cat <file>

//View the last 10 lines of a file's content
tail -10 <file>

//View the first 10 lines of a file's content
head -10 <file>

//Force termination of a process
kill -9 pid

//Delete an empty directory
rmdir <dir>

//Create an empty file
touch <file>

//Change the password of an user
passwd <username>

//View a snapshot of the currently running processes
ps x

//Compress a file in .tar.gz
tar czf compressed.tar.gz <file>

//Compress a file in .tar
tar cf compressed.tar <file>

//Decompress a .gz file
gunzip <file>

//Decompress a .tar file
tar xf <file>

//Change directory
cd <dir>

//Update the package lists from the repositories
apt-get update

//Install a new package
apt-get install <packagename>

//Completely remove an installed package
apt-get --purge autoremove  <packagename>

//Update an already installed package
apt-get update && apt-get install <packagename>

//Get the current directory
pwd

//View active connections
netstat -an

//List directory content
ls -la <dir>

//List block devices by their assigned name
lsblk

//Get md5 checksum of a file
md5sum <file>

//View information about the machine name
uname -a

//View history of executed commands in terminal
history

//Clear recent hostory of executed commands
history -c

//Create a new directory
mkdir <dir>

//Change file permissions
chmod <permissions> <file>

//Change the owner and group of a folder
chown www-data:www-data /var/directory

//Change the owner and group of a folder recursively
chown -R www-data:www-data /var/directory

//Remove a file
rm -f <file>

//Remove a folder (and files) recursively
rm -rf <dir>

//Get current date and time
date

//Copy a file from one location to another
cp <file> <location>

//Move a file from one location to another
mv <file> <location>

//Rename a file
mv <file> <newfile>