Linux basic commands

Linux basic commands

check the ip address


Check the hidden ip address which are not correctly configured

ifconfig -a

Change name servers of network

sudo nano /etc/resolv.conf

check gateway address

netstat -r

Find all files with in the system

sudo find / -name "*php.ini*"

Find all file and folder count

for t in files links directories; do echo `find . -type ${t:0:1} | wc -l` $t; done 2> /dev/nu

Find the total number of files/folder in a folder

find . -type f | wc -l

Server shutdown

sudo halt

change password of current user


Change user

su my_username

Change directory

cd /abc/

ctrl + c to quit command
This command shows listing. l for long format, h for human readable, A for hidden files.

ls -lhA

get list and permissions of the directories

ls -lh

Get directory listing & size

du -h

Get hard disk space information

df -h

Shutdown is the command and -r is a flag which is used by the shutdown command. In this case the -r means reboot. 0 is the time in minutes before the shutdown occurs.

sudo shutdown -r 0

How to change keyboard language layout?
sudo nano /etc/default/keyboard
Change the “gb” to the two letter code for your country.


Reboot the system to take effect

sudo reboot

start the desktop


Install chromium browser

sudo apt-get install chromium-browser

Make the browser more visually appealing enter the following

sudo apt-get install ttf-mscorefonts-installer

List all the usb connecting devices.


Use the Ctrl-Alt-F1 shortcut keys to switch to the first console.
To switch back to Desktop mode, use the Ctrl-Alt-F7 shortcut keys.
How to correct wrong server time

rdate -s

Get the current time


Correct & sync the server time
In this example, filename.tar represents the file you are creating and files/directories represents the files or directories you want to put in the new file.

tar -cvf filename.tar /directories/files

Compressed tar files are conventionally given the extension .tgz and are compressed with gzip.

tar -czvf filename.tar

Copy all files in a tar file and also gzip it

sudo tar -cpf - /var/www/* | gzip > /home/filename.tar.gz

unzip a compressed file

gzip -d file_name.sql.gz

unzip an unrar file.
unrar x <filename>
copy file from server to server

scp /home/

Convert tar.gz to tar file

tar -zxpf 2010-07-31-zain.tar.gz

Unzip a gz file

gunzip filename.sql.gz

copy and remove files from destination

cp -R var/www/* /var/www/new_directory/

change the ownership of a file or a directory

chown -R username:groupname /var/www/

View cronjob file

crontab -l

edit cronjob file

crontab -e

Edit user cron jobs

crontab -u [filesystem-username] -e

Restart crontab service

service crond restart

find process id

pidof lighttpd

-9 is special Kill signal, which will kill the process.

kill -9 3486

delete all mails from a username

&gt; /var/mail/username

list all fonts on ubuntu

identify -list font

install font on ubuntu

mv /var/www/font-name.ttf /usr/share/fonts/truetype/

print history in a file

history &gt;&gt; file_name.txt

show file content

tail file_name.txt

Check user group

groups zalam

nmap port scanner

apt-get install nmap
nmap -sS -O

Show possible locations of php

whereis php

Change file permissions

chmod -R 0775 &lt;DIRECTORY/DIRECTORY/&gt;

Change file owner/group

chown -R ownername:groupname&lt;DIRECTORY/DIRECTORY/&gt;

mark a file executable

chmod +x filename

mount shared folder 

sudo mount --bind /media/sf_E_DRIVE/ /var/www/e_drive/

Sync folder or file to another server

rsync -avz &lt;currently_server_directory&gt;//&lt;remote_server_directory&gt;/ --progress

upload files via ftp

ncftpput -R -u&lt;username&gt; -p&lt;password&gt; &lt;; /&lt;local_directory&gt;/ /&lt;remote_directory&gt;/

Show apache compiled modules

apache2 -l

Install php extension to see php error trance

sudo apt-get install php5-xdebug

How do I change the language via a terminal?

sudo nano/etc/default/locale

Check Ubuntu current version/release/codename

lsb_release -a

change password for webmin, if password lost

sudo /home/webmin-1.580/ /etc/webmin &lt;user_name&gt;&lt;password&gt;

uninstall webmin


Check last login of user on server

apt-get install finger


Share this post