fbpx

Linux basic commands

Linux basic commands

check the ip address

ifconfig

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

passwd

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.

XKBLAYOUT="gb"

Reboot the system to take effect

sudo reboot

start the desktop

startx

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.

lsusb

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 tick.greyware.com

Get the current time

time

Correct & sync the server time https://help.ubuntu.com/lts/serverguide/NTP.html
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 username@domainname.com:/var/www/filename.tar.gz /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

> /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 >> 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 127.0.0.1

Show possible locations of php

whereis php

Change file permissions

chmod -R 0775 <DIRECTORY/DIRECTORY/>

Change file owner/group

chown -R ownername:groupname  <DIRECTORY/DIRECTORY/>

 
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 <currently_server_directory>/ /<remote_server_directory>/ --progress

upload files via ftp

ncftpput -R -u<username> -p<password> <domain_name.com> /<local_directory>/ /<remote_directory>/

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
LANG="en_US"
LANGUAGE="en_US:en"

Check Ubuntu current version/release/codename

lsb_release -a

change password for webmin, if password lost

sudo /home/webmin-1.580/changepass.pl /etc/webmin <user_name> <password>

uninstall webmin

/etc/webmin/uninstall.sh

Check last login of user on server

apt-get install finger
finger

 
 
 

Share this post