Ubuntu how to

Below command have been tested on Ubuntu OS.

Delete a directory:

rmdir python 

Here python is the folder which you want to delete. Note the folder should
be empty.

Remove a non empty directory:

rm -rf pythonscripts

To delete a non empty directory you need to use -rf option where r means
recursive and f means force

To reach to your home directory:
cd ~

To check global variable:

printenv

To create a path shortcut in linux:

 Create a global variable of the path whose shortcut you want to create
 export variablename="path"

 Use in the command for example:
 cd $variablename

To get information about file system hierarchy:

man hier

How to create a user in ubuntu:

root@ubuntu:/home/panlab# adduser scp
Adding user `scp' ...
Adding new group `scp' (1001) ...
Adding new user `scp' (1001) with group `scp' ...
Creating home directory `/home/scp' ...
Copying files from `/etc/skel' ...
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
Changing the user information for scp
Enter the new value, or press ENTER for the default
 Full Name []: scp
 Room Number []:
 Work Phone []:
 Home Phone []:
 Other []:
Is the information correct? [Y/n]

How to shutdown ubuntu from cli:

shutdown -h now

How to reboot ubuntu from cli:

shutdown -r now

How to store output of a command to a file:

ifconfig > interface.txt

Here output of the command will be stored in file named as interface.txt

How to rename a file:

mv oldfilename newfilename

How to move a file from one place to another:

mv shutinterface /home/test/Desktop/

How to copy a file:

cp /home/sourcefilename /home/destinationfilename

How to change the time on ubuntu:

root@ubuntu:~# date 102815592017
Sat Oct 28 15:59:00 PDT 2017

How to change the timezone :

List all time zone with following command:
timedatectl list-timezones
Select the desired time zone with following command:
timedatectl set-timezone Asia/Kolkata

How to get all running process:

ps -aux

How to kill a process:

kill

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 the dependencies of a software:

apt-cache showpkg

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

To check about a file type:

file

To find a directory/file name in linux:

find / -name Desktop
This command search for all file/direcotory with name as Desktop in
all folder and sub folders.

To check Linux is listening on which ports:
netstat

To check Linux is listening on which tcp ports:
netstat -at

To check Linux is listening on which ports and get process name as well:
netstat -ap

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 x.x.x.x and  port xxx

To capture traffic for specific protocol:

tcpdump -i ens38 -v icmp

To store the captures in a pcap file:

tcpdump -i any host x.x.x.x and  port xxx -w issue.pcap

To specify snaplen in TCP dump:

tcpdump -s 1500

To view captured packet:

tcpdump -qns 0 -X -r
tcpdump -As0 -vvnn -r

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 "put content of file" > /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

How to user curl with proxy :

curl -x a.b.c.d:xx  -A "MSIE 9.0"  -v https://www.google.com
here a.b.c.d is the proxy IP and xx is the port number on which proxy is listening.

How to change IP address from static to dhcp on ubuntu:

ifconfig ens33 0.0.0.0 0.0.0.0 && dhclient

How to assign IP address manually:

killall dhclient && ifconfig eth0 10.1.1.2 netmask 255.255.255.0

How to get version of python:

#python -V

How to list all user :
cut -d : -f 1 /etc/passwd

How to list all group:
cut -d : -f 1 /etc/group

How to list all user in a group:

cat /etc/group

The above command will show all group and the userbelong to that group will be shown as follows:
adm:x:4:syslog
in this example syslog is a user and adm is a group

To add a new user:

sudo useradd new_username

To remove/delete a user:

1> delete the user
sudo userdel username
2> delete the directory
sudo rm -r /home/username

To modify the username of a user:

usermod -l new_username old_username

To change the password for a user:

sudo passwd username

To change the shell for a user:

sudo chsh username

To change the details for a user:

sudo chfn username

Add a user to a group:

sudo adduser username groupname

Delete a user from a group:

sudo adduser username groupname

To get details of a user:

id username

Create a new group:

sudo groupadd groupname
 How to know which version/flavor of linux you are using:
Try following command:

cat /etc/os-release
dmesg | head -1
cd /proc/version
cat /etc/issue
cat /etc/redhat-release
cat /etc/debian_version
cat /etc/*-release
lsb_release -a

How to change number of command linux save in history:

Linux saves all command you run in a file in you home directory.
Name of the file where these command are saved is .bash_history
This is a hidden file you have to run ls -a command to see the hidden files.
Now the number of command that can be saved are kept in .bashrc file.
If you want to change the number of command to be save you need to change the value of following filed:

HISTSIZE=<value>

How to print calender on cli:

root@ubuntu:/home/netsec# cal
 December 2017
Su Mo Tu We Th Fr Sa
                1  2
 3  4  5  6  7  8  9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31

How to check the RAM memory usage:

free
        total     used     free   shared  buff/cache  available
Mem:  1430572   227568    728008    8864      474996     999988
Swap: 1046524       0    1046524

How to ssh from CLI on a random port:

ssh username@host -p 26
in this example we are ssh on port 26

How to open a file with name as –

cd ./-

 

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