Commands


1)
 df -h      :it shows all mounted partions in GB+ MB
1.1)df        :it shows all mounted partions in KB
//if we r copying smth into pendrive and its mounted to /mnt we can show how much data is copied through command

1A)du -h      : it will show all disk usage of each file in a perticular folder
                in KB MB GB
   du          :it will show in KB
   du -sh      : it will show all the size of directory (it will not show individual file spaces)
   du -sh  /home/naveen(directory)
A quick way to get a summary of the available and used disk space on your Linux system is to type in the df command in a terminal window. The command df stands for "disk filesystem". With the -h option (df -h) it shows the disk space in "human readable" form, which in this case means, it gives you the units along with the numbers.

The du command on the other hand shows the disk space used by the files and directories in the current directory. Again the -h option (df -h) makes the output easier to comprehend.

2)
 cp -R * /media/navi252
//its copy all files and directories and sub directories into /media/navi252 recursively
3)cp src1 src2 scr3 destnation
//it copies 3 sources to one destination

3) tmpwatch 12 /tmp

It will remove any files older than 12 hours and you can change this to 12, 24 or any number of hours you want. Just change the ’12′ in above command to the number of hours you want.

4)
#ls | wc -l      -------it wil show no of lines or packages in perticular directory

5)
#vmstat -s -S M | grep mem  ------it will show all memory of RAM
  #free ------it will show in kb
  #free -m  ---it will show in MB

6)

ethtool eth0  -------it will show eth0 speed duplex
  mii-tool eth0  -------it will show eth0 speed duplex
  CHANGE FROM HALF DUPLEX TO FULL DUPLEX

# mii-tool --force=100baseTx-HD eth0 (half duplex 100 base T)
# mii-tool --force=100baseTx-FD eth0 (Full duplex 100 base T)
# mii-tool --force=10baseT-FD eth0 (Full duplex 10 base T)
# mii-tool --force=10baseT-HD eth0(Half duplex 10 base T)

By using ethtool also we can change the duplex

The next command enables Auto-Negotiate feature :
# ethtool -s eth0 autoneg on

The next command disables Auto-Negotiation, enables Half Duplex and sets up Speed to 10 Mb/s :
# ethtool -s eth0 speed 10 duplex half autoneg off

The next command disables Auto-Negotiation, enables Full Duplex and sets up Speed to 100 Mb/s :

# ethtool -s eth0 speed 100 duplex full autoneg off

LAN card or NIC is use to send and receive data. Technically, we use word Duplex for this functionality. Full duplex means you are able to send and receive data (files) simultaneously. In half duplex, you can either send or receive data at a time (i.e. you cannot send receive data (files) simultaneously). Obviously, full duplex gives you best user experienc

7)

Linux logout user

If you would like to logout other users, you must login as root user. Next you need to use pkill command.
pkill command syntax

pkill -KILL -u {username}
#who
#pkill -KILL -u naveen

8)
/sbin/service vsftpd status ------------for checking the status of service

9)
[root@server ~]# /usr/sbin/sendmail -t < mail.txt ----------------send email from command

Where the contents of the mail.txt file are:
Date: Thu Nov 11 08:41:54 2007
To: you@somewhere.com
Subject: The subject of the message
From: whatever@somewhere.com

Body of message goes here

10)
Linux renew ip command
The -r flag explicitly releases the current lease, and once the lease has been released, the client exits. For example, open terminal and type the command:
#sudo dhclient -r
Now obtain fresh IP:
#sudo dhclient
There is no need to restart network service
                    OR
On a related note you can also try out the following commands:
# ifdown eth0
# ifup eth0
# /etc/init.d/network restart

11)
force quite or kill any appication through command
xkill

12)SENDMAIL UASGE
#sendmail nnnXXX@gmail.com
body of msgs
l
l
.------------------------->  it will send msg to spam folder and sender is  root@localhost.localdomain
#sendmail XXX@gmail.com
FROM: naveen@csc.com
Subject : optional
body of message.
j
j
.
.........................>  it will send msg to inbox if contact is exits inXXX@gmail.com account
                            other wise it will send to spam folder
# sendmail -t pasemnaveen@gmail.com < text.txt
test.txt contains
FROM : naveen@csc.com
Subject : optional
bodyyy of mail
.
#


13)

disable/enable ping
#echo 1 >/proc/sys/net/ipv4/icmp_echo_ignore_all      --------for disables ping responses
#echo 0 >/proc/sys/net/ipv4/icmp_echo_ignore_all  ---for reenable ping responce

To make this permanent set the following into /etc/sysctl.conf (if you have such a file)

net.ipv4.conf.icmp_echo_ignore_all = 1


14)
Check open ports
netstat -nlp    
netstat -apnt
netstat -tulpn
netstat -tupan

nmap -sS -O 127.0.0.1
nmap -v -sV localhost/ipaddress -p 5060

15)
Turn on / off service
#ntsysv

16)
connect through ssh with other ports
#ssh -p 4563 192.168.0.*
17)
Secure copy from server if that server using other port
#scp '-P 2222' style.css  root@IP-address:/root/
#scp '-P 5022' text.txt itadmin@gw1:/home/itadmin -------when ur copieng ur file text.txt to gw1
if 192.168.0.48 also using diff port when ur login in gw1
#scp '-P 2345' root@gw1:/home/file1 .  2345 is the port those we r connectig to that system

18)
disable user login account
vi /etc/passwd
goto selected user edit/conver /bin/bash to /sbin/nologin

19)
Tip: The fastest way to scan all your devices/computers for open ports ever! 

#nmap -T5 192.168.1.0/24 #sudo nmap -T5 192.168.1.0/24 

The command gives you a bird's eye view that shows you quick information about all open ports on all servers, routers, and other network devices connected to your 192.168.1.0/24. Pass the -v option if you want to see verbose output and replace 192.168.1.0/24 with your network.




20)Did you know? 


You can run previous command as root. Say "command /to/file" need to be run as root. But, you run it as a normal user. To run the previous command as root just type "sudo !!".

Did you know? 

You can run previous command as root. Say "command /to/file" need to be run as root. But, you run it as a normal user. To run the previous command as root just type "sudo !!".
















21)

4. Get the user login history at any time

last command will give login history for a specific username. If we don’t give any argument for this command, it will list login history for all users. By default this information will read from /var/log/wtmp file. The output of this command contains the following columns:
  • User name
  • Tty device number
  • Login date and time
  • Logout time
  • Total working time
$ last jason
jason   pts/0        dev-db-server   Fri Mar 27 22:57   still logged in
jason   pts/0        dev-db-server   Fri Mar 27 22:09 - 22:54  (00:45)
jason   pts/0        dev-db-server   Wed Mar 25 19:58 - 22:26  (02:28)
jason   pts/1        dev-db-server   Mon Mar 16 20:10 - 21:44  (01:33)
jason   pts/0        192.168.201.11  Fri Mar 13 08:35 - 16:46  (08:11)
jason   pts/1        192.168.201.12  Thu Mar 12 09:03 - 09:19  (00:15)
jason   pts/0        dev-db-server   Wed Mar 11 20:11 - 20:50  (00:39
#w 
#w root  # It will show what they are doing

22)

Quick tip: Use the following tools to terminate connection such as SSH tunnels or VPNs left by your own users or kill high bandwidth consuming connection such as P2P on Linux based router.

a) Use tcpkill command to kill specified in-progress TCP connections. To kill all outgoing ftp (21) connection type:
# tcpkill -i eth0 port 21

To kill all all packets arriving at or departing from host 192.168.1.100, enter:
# tcpkill host 192.168.1.2

b) Use cutter command to cut all connections from 192.168.1.5 to the server typ

e
# cutter 192.168.1.5

To Cut all ssh connection from 192.168.1.5 to the server enter:
# cutter 192.168.1.5 22

See the man pages for more info.


23)


a) Set a timer to 900 seconds and then say “message (back to work)” using software speech synthesizer under Linux. 
sleep 900;echo "Tea Break's Over, Back To Work"|espeak

b) Mac user try say command :
sleep 900;say "Tea Break's Over, Back To Work"

c) Find and list all shell scripts in the current directory:
find . -type f -print0 | xargs -I {} -0 file {} | grep 'shell'

d) Print your Linux / Unix / OSX bash shell path in easy to read human format:
echo -e ${PATH//:/\\n}

e) Modern web browser such as Chrome also set proxy variables (e.g.: http_proxy and friends) for bash shell. To unset all proxy variables:
unset $(env | grep -i proxy | while IFS= read -r line; do echo ${line%%=*}; done)

To save proxy settings:
env | grep -i proxy > $HOME/.myproxy

To restore proxy settings:
source $HOME/.myproxy




24)
History command With Date and Time In Linux. and history saves upto 2000 commands

[root@naveen ~]#  vi /etc/bashrc

# goto last and ADD This line 
# turn on date time stamps in history

export HISTTIMEFORMAT="%h/%d - %H:%M:%S "
export HISTCONTROL=ignoreboth
export HISTSIZE=2000 

25)Sort du -h (human-readable) Output By Size


du -h | sort -h
du --human-readable | sort --human-numeric-sort

To reverse the result of comparisons pass the -r option:

du -h | sort -h -r
du --human-readable | sort --human-numeric-sort -r

To see top 10 files pass the output to the head command, enter:

du -h | sort -h | head
du -h | sort -hr | head

du --human-readable | sort --human-numeric-sort | head
du --human-readable | sort --human-numeric-sort -r | head

To see the last modification of any file in the directory, or any of its subdirectories with --time option



du -h --time  | sort -h

26)list all repositories set up on your system

You can list all repositories set up on your system by a  yum repolist all


enabled Either '1' or '0'. This tells yum whether or not use this repository.

gpgcheck Either '1' or '0'. This tells yum whether or not it should perform a GPG signature check on the packages gotten from this repository.

27)How to kill all VNC sessions


1) ps -ef (to check Xvnc session pid) or ps -ef | grep Xvnc
2) kill -9 "Xvnc pid"
3) delete .X1-lock file under /tmp and .X1 file under /tmp/.X11-unix
      then after that can start new Vnc session for number 1.
                             or
vncserver -kill :1 
vncserver -kill :2
vncserver -kill :3




28)Adding a TCP/IP Route to the Windows Routing Table

The Routing table dictates where all packets go when they leave your system. On most environments, all packets that leave your system will be forwarded over to your router or hub, and from there out to the internet.
In some circumstances, you may have a testing network configured to duplicate another environment, or you may be configuring a more complex network topology that requires the use of additional routes. Adding routes to your machine is a useful testing tool for some of these situations.
Syntax:
route ADD xxx.xxx.xxx.xxx MASK xxx.xxx.xxx.xxx  xxx.xxx.xxx.xxx
Means:
route ADD “network” MASK “subnet mask”  “gateway ip”
For example, if you were on the 192.168.1.0 network, and you had a gateway on 192.168.1.12 configured to access the 10.10.10.0/24 network, you would use a route add statement like this:
route ADD 10.10.10.0 MASK 255.255.255.0 192.168.1.12
Your routing table should now reflect that change, and all traffic to the 10.10.10.x range will now be sent over to the gateway machine.
The route add change will only stick across reboots if you add it with the -p flag, as in the following:
route -p ADD 10.10.10.0 MASK 255.255.255.0 192.168.1.12

To add a static IP route

1.
Open Command Prompt
2.
At the command prompt, type:
route add destination mask subnetmask gateway metric costmetric if interface
where:
destination 
Specifies either an IP address or host name for the network or host.
subnetmask
Specifies a subnet mask to be associated with this route entry. If subnetmask is not specified, 255.255.255.255 is used.
gateway
Specifies either an IP address or host name for the gateway or router to use when forwarding.
costmetric
Assigns an integer cost metric (ranging from 1 through 9,999) to be used in calculating the fastest, most reliable, and/or least expensive routes. If costmetric is not specified, 1 is used.
interface
Specifies the interface to be used for the route that uses the interface number. If an interface is not specified, the interface to be used for the route is determined from the gateway IP address.
For example, to add a static route to the 10.0.0.0 network that uses a subnet mask of 255.0.0.0, a gateway of 192.168.0.1, and a cost metric of 2, you type the following at a command prompt:
route add 10.0.0.0 mask 255.0.0.0 192.168.0.1 metric 2 
Note
To open command prompt, click Start, point to All Programs, point to Accessories, and then click Command Prompt
To make a static route persistent, you can either enter route add commands in a batch file that is run during system startup or use the -p option when adding routes.
Routes added by using the -p option are stored in the Windows registry under the following key:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip \Parameters\PersistentRoutes
All symbolic names used for destination or gateway are looked up in the network and computer name database files (Networks and Hosts), which are stored in the local systemroot\System32\Drivers\Etc folder.
If a route addition fails, you can use the tracert command to verify that the gateway specified is directly reachable from the same subnet as this computer.
29) Windows Commands

netstat -aon
netstat -aon | findstr "1000"
tasklist

30) Enable Java /JRE in Linux Browsers


All we have to do is to create a symbolic link of the libnpjp2.so file inside the plugins folder of mozilla.
1
2
  cd /usr/lib/mozilla/plugins
  sudo ln -s /opt/java/jre/lib/i386/libnpjp2.so
     or
2  sudo ln -s /opt/java/jre/lib64/libnpjp2.so

To verify that Java is installed in your browser, check here.



31)How can i send an email through UNIX mailx command


[root@dns /]# echo "This is Body of mail" | mailx -s "This is subject" info@thelinuxwiki.in

it will send mail to info@thelinuxwiki.in. the from address is root@dns.thelinuxwiki.in

if you want to send mail from another user like hr@sssntech.com to info@thelinuxwiki.in 

[root@dns /]# echo "Body" | mailx -r "FROM_EMAIL" -s "SUBJECT" "To_EMAIL"

PS. Keep body and subject within double quotes. Remove quotes from FROM_EMAIL and To_EMAIL while substituting email addresses.
Example



31)How can i send an email through UNIX mailx command


[root@dns /]# echo "This is Body of mail" | mailx -s "This is subject" info@thelinuxwiki.in
it will send mail to info@thelinuxwiki.in. the from address is root@dns.thelinuxwiki.in
if you want to send mail from another user like hr@sssntech.com to info@thelinuxwiki.in 


[root@dns /]# 
echo "Body" | mailx -r "FROM_EMAIL" -s "SUBJECT" "To_EMAIL"

PS. Keep body and subject within double quotes. Remove quotes from FROM_EMAIL and To_EMAIL while substituting email addresses.

Example


[root@dns /]#echo "Body" | mailx -r hr@ssntech.com -s "SUBJECT"  info@thelinuxwiki.in


This will send mail to info@thelinuxwiki.in from hr@ssntech.com


In other words, mailx reads the content to send from standard input and can be redirected to like normal. E.g.:
[root@dns /]#ls -l $HOME | mailx -s "The content of my home directory" someone@email.adr
[root@dns /]# uptime | mailx -s "The content of my home directory" someone@email.adr
Another way to send mail from unix command promt
mail -s 'Subject-Here'info@thelinuxwiki.in< input.file
mail -s 'Uptime Report' info@thelinuxwiki.in < /tmp/output.txt
 
Where,

-s 'Subject' : Specify subject on command line.
info@thelinuxwiki.in: To email user.
/tmp/output.txt : Send the content of /tmp/output.txt file using mail command.
32)How can i send an email with attachment through UNIX mutt command
[root@dns /]# echo "Body Of the Email" | mutt -a "File_Attachment.csv" -s " This is subject" -c info@thelinuxwiki.in
[root@dns /]# echo "Body Of the Email" | mutt -a "/home/naveen/Desktop/file.zip" -s " This is subject" -c info@thelinuxwiki.in
This will send email to info@thelinuxwiki.in with attached file. From address is root@dns.thelinuxwiki.in(what mentioned in the postfix configuration file)

### Attach /tmp/filelist.tar.gz and read the content of a text using /tmp/body.txt ###
[root@dns /]# mutt -s "Backup status" -a /tmp/filelist.tar.gz you@cyberciti.biz < /tmp/body.txt
32)To see number of IP connections and IPs connected to port 80, use the following command.

[root@naveen ~]# netstat -plan|grep :80|awk {'print $5'}|cut -d: -f 1|sort|uniq -c|sort -nk 1




33) wget with authentication [closed]



Using the options:--password=PASS --user=USERNAME


ie: wget https://www.thelinuxwiki.in/file.txt --user=naveen --password=hellonaveen

But using the above option is not recommended because here we need to type password

Recommended way is.......

By specifying the option --user and --ask-password wget will ask for the credentials. Below is an example. Change the username and download link to your needs.

wget --user=username --ask-password https://www.thelinuxwiki.in/file.txt 

wget https://www.thelinuxwiki.in/file.txt --user=username --ask-password

======================================================================

34) How to convert VirtualBox VDI image to Qemu-KVM .QCOW image


Convert the VirtualBox image to a raw image format using the following command:
Code:
VBoxManage clonehd "image.vdi" "image.img" --format RAW
Convert convert the raw image to a qcow image using the following command:
Code:
qemu-img convert -f raw image.img -O qcow2 image.qcow
Test your new image image.qcow:
Code:
kvm -m 512 -usbdevice tablet -hda image.qcow
=====================================================================

fallocate command syntax

The basic syntax is:
fallocate -l Image_Size_Here /path/to/image.img

Creating a large file on a Linux using fallocate command

The following command will create 1G file:
 
fallocate -l 1G test.img
 
Verify new disk image with the ls command:
$ ls -lh test.img
Sample outputs:
-rw-r--r--. 1 root root 1.0G Nov 27 03:42 test.img

==========================================================

scp without replacing existing files in the destination


Use rsync, and pass -u if you want to only update files that are newer in the original directory, or --ignore-existing to skip all files that already exist in the destination.
rsync -au /local/directory/ host:/remote/directory/
rsync -a --ignore-existing /local/directory/ host:/remote/directory/
(Note the / on the source side: without it rsync would create /remote/directory/directory.)


No comments:

Post a Comment