Home > Linux, Technical > Linux Tips and FAQ

Linux Tips and FAQ


    1. How to find the Linux distribution using command line?
      $ cat /etc/*-release

      [root@linux-65 ~]# cat /etc/*-release
      Red Hat Enterprise Linux Server release 5.4 (Tikanga)
      [root@linux-65 ~]#
    2. How to find the linux Kernel version using command line?

      $ uname -a
      [root@linux-65 ~]# uname -a
      Linux linux-65.cisco.com 2.6.18-164.el5 #1 SMP Tue Aug 18 15:51:54 EDT 2009 i686 i686 i386 GNU/Linux
      [root@linux-65 ~]#
      Where 2.6.18-164.e15 is the kernel version
    3. How to find the Linux OS processor architecture using command line?
      $ uname -m[root@linux-65 ~]# uname -m
      i686
      [root@linux-65 ~]#Where i686 or in general ix86 (where x=3,4,5,6) which means this is a 32-bit proessor
      if the output is x86_64 then it indicates its a 64 bit processor.
    4. How to find out whether the processor is 32 bit or 64 bit?
      $ cat /proc/cpuinfo | grep flag

      lm flag means Long mode cpu - 64 bit CPU
      Real mode 16 bit CPU
      Protected Mode is 32-bit CPU

      [root@linux-65 ~]# cat /proc/cpuinfo | grep flag
      flags : fpu vme de pse tsc msr pae mce cx8 apic mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe nx lm constant_tsc pni monitor ds_cpl cid cx16 xtpr
      flags : fpu vme de pse tsc msr pae mce cx8 apic mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe nx lm constant_tsc pni monitor ds_cpl cid cx16 xtpr
      [root@linux-65 ~]#
    5. How to find out whether the processor supports VT
      For Intel processors
      grep vmx /proc/cpuinfo
      For AMD processors
      grep svm /proc/cpuinfo

Linux Output formatting tool tips

There are lot of powerful output formatting commands/tools available in linux as well as some routers/devices which are based on linux.

Few of them are

  1. grep
  2. egrep
  3. sed
  4. cut
  5. tr
  6. awk

Using tr and cut together to filter out a column in an output

Requirement:  Need to extract only the last column

Tools which can be used: cut

Problem: cut command has a limitation that the delimiter has to be a single character and in the example text the delimiter for columns are “multiple spaces/tabs”.

Solution: Use tr commands “-s”  option to remove duplicate delimiters and then pipe that output to cut command

Command in action

cat testfile.txt | tr -s ” ” | cut -d “” -f 4

where
Sample file content used in this example
linux > cat testfile.txt
0 1 0 0
1 1 1 0
2 1 2 0
3 1 3 0
4 1 4 0
5 1 5 0
6 1 6 0
7 1 7 0
8 1 8 0
9 1 9 0
10 1 10 0
linux >

cat testfile.txt | tr -s ” ”  will remove all the duplicate spaces in the output
linux > cat testfile.txt | tr -s " "
0 1 0 0
1 1 1 0
2 1 2 0
3 1 3 0
4 1 4 0
5 1 5 0
6 1 6 0
7 1 7 0
8 1 8 0
9 1 9 0
10 1 10 0
linux >

Now the above output we pipe it to cut command with space as the delimiter (-d ” “) and to get the 4th column alone use the -f 4
linux > cat testfile.txt | tr -s " " | cut -d " " -f 4
0
0
0
0
0
0
0
0
0
0
0
linux >

test

Advertisements
Categories: Linux, Technical
  1. No comments yet.
  1. No trackbacks yet.

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

%d bloggers like this: