Monday, June 3, 2013

Netstat Command in Linux                                                               vmstat Command in Linux

It is very easy to check local network speed in Windows but if you have putty access to Linux machine then we are facing issues to check the network speed. There are some tools are available to check network speed iin Linux but it is not possible to install this tools on client machine or our secured machine.

Network speed in linux is depend on the Ethernet card or network interface card which you are using for this machine. Might be there are multiple Ethernet cards already configured, we can check network speed for each separately.

Generally, Ethernet cards are configured. If we see the the output of below command then we will get all NICs.

root@hello:~# ifconfig -a
eth0   Link encap:EthernetHWaddr 1c:6f:65:0b:00:eb
          inet addr:10.136.25.42  Bcast:10.136.25.255  Mask:255.255.255.0
          inet6 addr: fe80::1e6f:65ff:fe0b:eb/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:1133376 errors:0 dropped:0 overruns:0 frame:0
          TX packets:34516 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:11234117 (113.8 MB)  TX bytes:9056744 (9.0 MB)
          Interrupt:16 Memory:fc500000-fc520000

lo       Link encap:Local Loopback     
          inet addr:127.0.0.1  Mask:255.255.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:20442 errors:0 dropped:0 overruns:0 frame:0
          TX packets:20442 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:2356951 (2.3 MB)  TX bytes:2356951 (2.3 MB)
root@hello:~#

If we see in above output, there are two cards configured. But eth0 is the main. So we need to check network speed for it only.

For Ethernet card,

root@hello:~# ethtool eth0 | less

If this command is not found then go for below command

root@hello:~# dmesg  | grep -i duplex
[   16.773492] e100e: eth0 NIC Link is Up 100 Mbps Full Duplex, Flow Control: None
root@hello:~#

Above command will be helpful to check system is half duplex or full duplex. Dmesg command gives lots of information but it is not that much of useful for us just grep needed information.

                We can check network speed of wireless card and chipset information.

                root@hello:~#lspci | grep -i wireless

                To test internet connection speed from the console over ssh command line, we need to install lftp and iperf packages. They are easily available. We can download rpm of them or install it from yum repository.

After installation, download or upload data by lftp, pget command or check network speed between two IPs by iperf command.


I got some useful information regarding this topic on one site. Please go through it.

Check CPU usage in Linux                                                                usermod command in Linux
Posted by Machindra Dharmadhikari On 6/03/2013 08:38:00 PM 3 comments READ FULL POST
Not able to delete files in Linux                                               Find command with mtime and atime options

Find command in linux is most important for linux administrators as well as shell script developers. It is really very fast in execution speed and it is useful because of availability of wide variety options with find command.

Find has many options available like ctime i.e. creation time, type – type of file, newer – compare files and decide, it is newer or older as compared to one file, inum- inode number.
Examples:
  • Search files by inode numbers with find command: find inum
root@hello:~/ctier/examples# find . -inum 5770071
./README.txt
root@hello:~/ctier/examples#
  •  Search files newer as compared to given file: find newer
root@hello:~/ctier/examples# find . -type f -newer filename
root@hello:~/ctier/examples# find . -type f -newer README.txt

Newer option helpful to get new files as compared to given file timestamp.
  • Search files older as compared to given file: find newer
root@hello:~/ctier/examples# find . -type f !-newer README.txt

To reverse the output of 2nd example, we need to put !mark before the –newer option. It will negate the meaning of command after the mark.
  •  Search files by uid: find uid
root@hello:~#find . -type f -uidNumeric USERID
root@hello:~#find . -type f -uid 1002

  •  Search files whose creation time is older than 30 days

root@hello:~#find . -type f -ctime +30
  •  Search files whose creation time is within last 30 days

root@hello:~#find . -type f -ctime -30
  •  Search log files whose creation time is older than 30 days and delete it

In this case, we need to search files whose creation time is older than 30 days and need to provide this list of files to the rm command with the help of –exec option. We can run any file manipulation command after exec option e.g. ls –lrt, cat, wc etc.

root@hello:~#find . -type f -name "*.log" -ctime +30 -exec rm -rf {} \;


If you need more examples or facing issues with some option then please write us at linuxconcepts@gmail.com.

How to install Wine Application                                              How to install cygwin and configure

Posted by Machindra Dharmadhikari On 6/03/2013 08:30:00 PM 1 comment READ FULL POST
Find command is most powerful command in linux to find files as per our criteria. It is used  not only to search files but also to run different commands on those files. Mostly we are searching files by modification time or access time of that file. So, in this article, we will search files by this two parameters only. We will see mtime and atime in detail with examples.
  • To find files who accessed in last 7 days

To find files whose access time is newer i.e. in last 7 days only. Then we can search those files by following command.

root@hello:~/ctier/examples# find . -type f -mtime -7

This command will be helpful to get only files i.e. type option will help to get files or directories if you put d instead of f then it will search for directories. And mtime i.e. modification time should be last 7 days only then it should be -7 and if you want to do reverse i.e. you need all files whose modification time is 7 days before i.e. do not display the files whose modification time is last 7 days then use +7.

mtime option we can use with  multiple find commands option like –newer, -type, -name, -depth etc.

Examples:
  •  To find files whose access time is within last 7 days only


root@hello:~/ctier/examples# find . -type f -atime -7
  •     To search files whose access time is more than 15 days older


root@hello:~/ctier/examples# find . -type f -atime +15
  •  To search files whose modification time is within last 7 days and till the 3 depth of directory


root@hello:~/ctier/examples# find . –maxdepth 3 -type f  –mtime -7
  •  To search files whose modification time is last 30 days ok but access time should be within last 2 days only


root@hello:~/ctier/examples# find . –maxdepth 3 -type f  –mtime-30 –atime 2

- maxdepth option is available but instead of it, many times we need to use - depth option and it varies from OS to OS.


Find atime and find mtime are two mainly used options with find command. If you need more information or having some doubts regarding this then please write us at: linuxconcepts@gmail.com

Difference between Soft link and Hard link                                 Groupadd/Groupdel Command 
Posted by Machindra Dharmadhikari On 6/03/2013 08:21:00 PM 2 comments READ FULL POST

Monday, May 20, 2013


Tar command is specially designed to zip and extract the data. It helps to reduce the space while getting backed up data. It is used to store and extract files from an archive file. Let’s understand tar command with examples:

How to archive folder in tar extension by tar command

Tar command requires two arguments to archive the folder i.e. first argument is output file name with tar extension and second is source folder name which we want to archive.
root@hello:~/ctier/pkgs/apache-tomcat-5.5.28# tar -cvf logs.tar logs/
logs/
logs/catalina.2012-12-03.log
logs/localhost.2012-12-03.log
root@hello:~/ctier/pkgs/apache-tomcat-5.5.28#

-c option with tar means – create a new archive file
-v option – verbose mode
-f option – forcefully create archive.
After this command you need to use gzip command to get much archived file as compared to tar as :
root@hello:~/ctier/pkgs/apache-tomcat-5.5.28# ls
logs  logs.tar
root@hello:~/ctier/pkgs/apache-tomcat-5.5.28# gzip logs.tar
root@hello:~/ctier/pkgs/apache-tomcat-5.5.28# ls
logs  logs.tar.gz
root@hello:~/ctier/pkgs/apache-tomcat-5.5.28#

Compression ratio of this technique is very high. Generally this technique is used for backing up large data.

How to extract archive by tar command

Now extract the above archived file by tar and gunzip command. Extraction is very easy and you need to remember some options of tar only.
-x option with tar – extract the archive
And no need of any option with gunzip to extract gz file.

root@hello:~/ctier/pkgs/apache-tomcat-5.5.28# ls
logs  logs.tar.gz
root@hello:~/ctier/pkgs/apache-tomcat-5.5.28# gunzip logs.tar.gz
root@hello:~/ctier/pkgs/apache-tomcat-5.5.28# ls
logs  logs.tar
root@hello:~/ctier/pkgs/apache-tomcat-5.5.28# rm -rf logs
##removing logs folder otherwise it will overwrite the existing folder
root@hello:~/ctier/pkgs/apache-tomcat-5.5.28# ls
logs.tar
root@hello:~/ctier/pkgs/apache-tomcat-5.5.28# tar -xvf logs.tar
logs/
logs/catalina.2012-12-03.log
logs/localhost.2012-12-03.log
root@hello:~/ctier/pkgs/apache-tomcat-5.5.28# ls
logs  logs.tar
##tar files remains as it as but new extracted folder will create

We can extract tar files or gz files directly by tar command as follows with –z option.
-z option – extract gz file
root@hello:~/ctier/pkgs/apache-tomcat-5.5.28# ls
logs.tar.gz
root@hello:~/ctier/pkgs/apache-tomcat-5.5.28# tar -xvzf logs.tar.gz
logs/
logs/catalina.2012-12-03.log
logs/localhost.2012-12-03.log
root@hello:~/ctier/pkgs/apache-tomcat-5.5.28# ls
logslogs.tar.gz
root@hello:~/ctier/pkgs/apache-tomcat-5.5.28#

How to update archive file by tar commandi.e. add new file in archive

We can update archive file by tar command. It is really very useful trick to update our backup data instead of creating new backup file.

root@hello:~/ctier/pkgs/apache-tomcat-5.5.28# ls
logs  logs.tar
root@hello:~/ctier/pkgs/apache-tomcat-5.5.28#
root@hello:~/ctier/pkgs/apache-tomcat-5.5.28# touch test1
//New file created here
root@hello:~/ctier/pkgs/apache-tomcat-5.5.28# tar -uvf logs.tar test1
test1
root@hello:~/ctier/pkgs/apache-tomcat-5.5.28# ls
logs  logs.tar  test1
## test1 is already here, so we will remove it to extract tar file and then we can understand archive is updated or not
root@hello:~/ctier/pkgs/apache-tomcat-5.5.28# rm–rf  logs test1
root@hello:~/ctier/pkgs/apache-tomcat-5.5.28# ls
 logs.tar
##Now there is no logsor test1 file.
root@hello:~/ctier/pkgs/apache-tomcat-5.5.28# tar -xvf logs.tar
logs/
logs/catalina.2012-12-03.log
logs/localhost.2012-12-03.log
test1
root@hello:~/ctier/pkgs/apache-tomcat-5.5.28# ls
logs  logs.tar  test1



Posted by Machindra Dharmadhikari On 5/20/2013 12:01:00 AM 1 comment READ FULL POST

Friday, May 10, 2013

Difference between SAN and NAS                                Netstat Command in Linux

1.       What are the run levels?
There are total seven run levels as follows:
0 – halt
1—single user mode
2—multiuser mode without NFS
3—Multiuser with NFS
4 -- Unused
5 -- Multiuser mode with X11.
6 – Reboot.

2.       How to check all logged in user currently on server?
Ans.  W and who are the commands to check all logged in users on server. There many different commands to check this but mostly used w or who or finger.
root@rhel:~/rhel/shellscript# w
 01:17:45 up 12 days,  6:43,  3 users,  load average: 0.03, 0.04, 0.05
USER     TTY      FROM              LOGIN@   IDLE   JCPU   PCPU WHAT
nielsen2 pts/0    10.136.26.166    Wed20    3days  1.05s  0.69s -bash
nielsenpts/1    10.136.26.227    01:05    0.00s  0.62s  0.07s sshd: nielsen [priv]
nielsen2 pts/2    10.136.26.92     Wed20    4days  0.43s  3.39s sshd: nielsen2 [priv]
root@rhel:~/rhel/shellscript#
root@rhel:~/rhel/shellscript# who
nielsen2 pts/0        2013-04-24 20:24 (10.136.26.166)
nielsenpts/1        2013-04-30 01:05 (10.136.26.227)
nielsen2 pts/2        2013-04-24 20:26 (10.136.26.92)
root@rhel:~/rhel/shellscript# finger
Login     Name       Tty      Idle  Login Time   Office     Office Phone
nielsen   Nielsen   *pts/1          Apr 30 01:05 (10.136.26.227)
nielsen2             pts/0      3d  Apr 24 20:24 (10.136.26.166)
nielsen2            *pts/2      4d  Apr 24 20:26 (10.136.26.92)
root@rhel:~/rhel/shellscript#

3.       What is the difference between soft link and hard link?
Ans. Soft link also called as Symbolic link. Soft link means link the new file to original file without copying whole file to new location. And New files size will be the characters in filename of original file. If you want to get detailed difference then click on next link: Difference between Soft Link and Hard Link.

4.       How to change hostname permanently for server?
Ans. Generally, we are changing hostname from `hostname command` but this is not the way to change the hostname permanently. You should have to open the file `/etc/sysconfig/network` and change the hostname parameter of this file and then restart the network service.

5.       What is the command to convert dos file into unix format ?
Ans. `dos2unix` command is generally used for convert dos file into unix format and `unix2dos` command is used to vice versa.
6.       On which port DNS server is running ?
Ans. 53 Port .
7.       How to get the lines which matches pattern and 4 lines after the matched pattern ?
Ans. We can use grep command to get 4 lines after matched pattern.
root@rhel:~/rhel/shellscript# cat /etc/passwd | grep -nA 4 root
1:root:x:0:0:root:/root:/bin/bash
2-daemon:x:1:1:daemon:/usr/sbin:/bin/sh
3-bin:x:2:2:bin:/bin:/bin/sh
4-sys:x:3:3:sys:/dev:/bin/sh
5-sync:x:4:65534:sync:/bin:/bin/sync
root@rhel:~/rhel/shellscript#

To get 4 lines before the matched pattern:
root@rhel:~/rhel/shellscript# cat /etc/passwd | grep -nB 4 snmp
45-jenkins:x:120:65534::/var/lib/jenkins:/bin/bash
46-bind:x:121:131::/var/cache/bind:/bin/false
47-nagios:x:122:132::/var/lib/nagios:/bin/false
48-guest-ZI4XVo:x:123:133:Guest,,,:/tmp/guest-ZI4XVo:/bin/bash
49:snmp:x:124:134::/var/lib/snmp:/bin/false
root@rhel:~/rhel/shellscript#

8.       How to create 10 files in single command?
Ans.  You can use 10 different names after touch command.
root@rhel:~/rhel/shellscript/test# touch test{1..10}
root@rhel:~/rhel/shellscript/test# ls
test1  test10  test2  test3  test4  test5  test6  test7  test8  test9
root@rhel:~/rhel/shellscript/test#

9.       Find commans syntax to find the file by inodenumber ?
Ans. as follows:
root@rhel:~/rhel/shellscript# ls -li
total 32
5644165 -rw-r--r-- 1 root root 4922 2013-04-17 20:02 bid.log
5644164 -rwxr-xr-x 1 root root  479 2013-04-24 22:27 shellscript.sh
5770666 drwxr-xr-x 2 root root 4096 2013-04-30 01:42 test
5644159 -rw-r--r-- 1 root root 2173 2013-04-17 17:50 test1.log
5644160 -rwxr-xr-x 1 root root  353 2013-04-16 20:04 test1.sh
5644161 -rwxr-xr-x 1 root root  514 2013-04-16 18:30 test2.sh
5644117 -rw-r--r-- 1 root root 1731 2013-04-17 17:55 test.log
root@rhel:~/rhel/shellscript# find . -inum 5644164
./shellscript.sh
root@rhel:~/rhel/shellscript#

10.   Find command syntax to get files accessed within last 30 days:
Ans:
root@rhel:~/rhel/shellscript#
root@rhel:~/rhel/shellscript# find . -type f -atime -30
./test2.sh
./bid.log
./test/test1
./test/test9
./test/test5
./test/test6
./test/test10
./test/test4
./test/test2
root@rhel:~/rhel/shellscript#

Check CPU usage in Linux                                              Usermod command in Linux
Posted by Machindra Dharmadhikari On 5/10/2013 09:27:00 AM 5 comments READ FULL POST
  • RSS
  • Delicious
  • Digg
  • Facebook
  • Twitter
  • Linkedin
  • Youtube

    Chitika Ads 2

    Histat

    About

    Enter your email address:

    Delivered by FeedBurner