Linux how to

Below command have been tested on Ubuntu OS.
Remove a directory:
rmdir python

Remove a non empty directory:
rm -rf pythonscripts

To reach to your home directory:
cd ~

To create a path shortcut in linux:
Create a global variable:
export variablename=”path”
Use in the command for example:
cd $variablename

To check global variable:

printenv

To extract the tar file use following command:
tar -xf

To extract file to a new directory use following command:
mkdir techsupport && tar -xf techsupport.tgz -C techsupport

Search pattern with grep:
grep “pattern to search”

Show few line after the matched pattern:
grep -A “pattern to search”
grep -A4 “:packet” monitor.log

Search all file inside a directory and sub directory:
grep-R “pattern to search” *

To get list of installed software:
dpkg -l

To check the version of a software:
dpkg -l syslog-ng

To uninstall one software:
apt-get –purge remove

To check if a software is installed or not:
apt-cache policy openssl

To find a directory/file name in linux:
find / -name Desktop

To check Linux is listening on which ports:
netstat

To get folder size:

du -sh /var/

To get disk space:

df -h

To get file system type:

df -T

To get all folder size:

du

To capture traffic using tcpdump:

tcpdump -i any host 62.239.180.185 and  port 18184

Root password: By default ubuntu root password is not set. You need to set the root password use following command to set root password

sudo passwd root

How to enable vlan tagging(8021q) in linux:

create a subinterface with vconfig
vconfig add eth0 1
ifconfig eth0.1 10.1.1.1 netmask 255.255.255.0


Remove IP address from interface
:

ifconfig eth0 0.0.0.0

How to create a file with the help of a script:

Put following is a .sh file and give proper permission to file
below script will create a file named index.html under path "/usr/local/httpd/bin/"

echo "" > /usr/local/httpd/bin/index.html

ntpq command:

ntpq> ?
Commands available:
addvars        associations   authenticate   cl             clearvars
clocklist      clockvar       cooked         cv             debug
delay          exit           help           host           hostnames
keyid          keytype        lassociations  lopeers        lpassociations
lpeers         mreadlist      mreadvar       mrl            mrv
ntpversion     opeers         passociations  passwd         peers
poll           pstatus        quit           raw            readlist
readvar        rl             rmvars         rv             showvars
timeout        version        writelist      writevar

Local host file dns entry in ubuntu:

Change the directory to /etc edit file hosts

 

Advertisements
This entry was posted in Linux and tagged , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s