Which Linux Kernel, What Distro, 32-bit or 64-bit?

 Command Line, Linux  Comments Off on Which Linux Kernel, What Distro, 32-bit or 64-bit?
Jan 012015
 

On the terminal, there are a plethora of commands that spit out answers to questions about the Linux kernel and/or the Linux distribution underpinning your system.

Let’s take a deko at a few of them.

Some of the below commands give only the distro, others mention just the kernel version and a few provide information on the kernel, distro and whether it’s a 32-bit or 64-bit Linux OS.

Inxi

My favorite command line tool inxi provides details on kernel, distribution and whether you’re running a 32-bit or 64-bit OS.

$ inxi -S
System:    Host: Tanya Kernel: 3.13.0-24-generic i686 (32 bit) Desktop: Gnome Distro: Linux Mint 17.1 Rebecca

Some distributions like Linux Mint come with inxi pre-installed.

If inxi is not on your system, I strongly recommend you get it asap.

You can easily install inxi by running the below command:

Ubuntu/Debian Users

sudo apt-add-repository ppa:unit193/inxi && apt-get update

Once you’ve completed the above step, then run the below command to complete installation of inxi.

apt-get install inxi

CentOS/Fedora Users

$ sudo yum install inxi

Uname Commands

For a quick glance at just the kernel version on your computer, try either of the below commands.

$ uname -r
3.13.0-24-generic

or

$ uname -mrs
Linux 3.13.0-24-generic i686

The i686 notation (above) means that it’s a 32-bit OS.

$ uname -a
Linux Sasha 3.13.0-24-generic #47-Ubuntu SMP Fri May 2 23:31:42 UTC 2014 i686 i686 i686 GNU/Linux

Uname is easy to remember for kernel information but not so great for distribution details because even if you’re running Linux Mint it’ll tell you Ubuntu (the foundation of Linux Mint).

Cat /etc

For a quick glance at the Linux distribution on your computer, go for the below command.

$ cat /etc/issue
Linux Mint 17.1 Rebecca \n \l

For a more detailed explanation, try the below command:

$ cat /etc/*release
DISTRIB_ID=LinuxMint
DISTRIB_RELEASE=17.1
DISTRIB_CODENAME=rebecca
DISTRIB_DESCRIPTION="Linux Mint 17.1 Rebecca"
NAME="Ubuntu"
VERSION="14.04.1 LTS, Trusty Tahr"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 14.04.1 LTS"

If all you’re interested in is whether it’s 32-bit OS or 64-bit OS, go for the below command.

$ getconf LONG_BIT
32

Here’s annother way to find out if your computer is running a 32-bit or 64-bit Linux.

$ file /sbin/init
/sbin/init: ELF 32-bit LSB  shared object, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.24, BuildID[sha1]=c394677bccc720a3bb4f4c42a48e008ff33e39b1, stripped

Need one more way to find out if your Linux OS is 32-bit or 64-bit?

OK, here we go.

$ arch
i686

Simple as pie, right?

Lsb Method

Now before I run out steam, let me show you one more way to check your Linux distribution and its version.

$ lsb_release -a
No LSB modules are available.
Distributor ID:	LinuxMint
Description:	Linux Mint 17.1 Rebecca
Release:	17.1
Codename:	rebecca


Note
: I can get lsb_release -a to work on LinuxMint/Ubuntu computers but it does not work on CentOS.

Folks, as you’ve seen from the various options I’ve outlined above, there are several ways to bell a Linux distribution or kernel cat. 😉

Pick whichever one suits you best.

12 Cute Command Line Tricks

 Command Line  Comments Off on 12 Cute Command Line Tricks
Dec 292014
 

The command line is a vast ocean that stretches endlessly, far beyond the imagination of even the smartest guys.

A lot of systems administrators use indispensable command line tools like scp, ls, netstat, rsync etc on a daily basis as part of their work.

But the command line can also do some cute, unusual things that you wouldn’t have thought possible.

Here are 12 cute command line tricks that’ll keep you amused. Hey, some are even useful.

1. Create a 30 character alphanumeric password with upper and lower case letters:

$ strings /dev/urandom | tr -cd '[:alnum:]' | fold -w 30 | head -n 1
15WbweWRx2gUoZlsSpNybtpWSpHq4A

By varying the number next to ‘w,’ you can create longer or shorter passwords.

2. Ha ha ha. Now for a weird command that spits out quotes from the hilarious movie Borat. If you’ve seen Borat, you know that some of the jokes in the movie can be extremely crude and vulgar. 😉

$ curl -s "http://smacie.com/randomizer/borat.txt" | shuf -n 1 
Kazakhstan is more civilised now. Women can now travel on inside of bus, and homosexuals no longer have to wear blue hat.

3. Create a Telephone Pad on the terminal by running either of the two below commands:

$ printf "%s\t%s\t%s\n" {1..9} '*' 0 '#'

or

$ echo {1..9} '* 0 #' | tr ' ' '\n' |paste - - -

4. The below command displays size of all files on the system and remains one of my favorites.

$ du -h|sort -hr|less

Be patient because this command takes a few seconds to spit out the output.

5. Act busy even if you are not.

We live in a world where appearances count more than anything else. So the next time you feel like a cup of coffee or an early lunch, run the below command and anyone dropping by to your cubicle will be amazed at how hard you work while actually you’re at Starbucks enjoying a steaming Latte. 🙂

$ cat /dev/urandom | hexdump -C | grep "ca fe"

6. An extremely useful command, inxi provides a summary of the hardware specs and essential software running on your computer.

$ inxi -F

7. How about a stop watch on the screen? Sure, we can do that.

$ time read

Press ctrl-d to stop

8. Your IP address as seen by the world.

$ curl ifconfig.me
209.222.18.83

9. Download your favorite web site with the below command:

$ wget --random-wait -r -p -e robots=off -U mozilla http://www.example.com

In the above illustration, replace example.com with the URL of your favorite web site.

While a small site will take less than a minute to download, large sites with a gazillion pages could take an eternity.

Note: Remember it’s likely illegal in most jurisdictions to download someone else’s web site without permission to your local computer.

10. Put a clock in the top right corner of your terminal

$ while sleep 1;do tput sc;tput cup 0 $(($(tput cols)-29));date;tput rc;done &

11. Which applications are using the Internet?

If you’re like me, you’re forever installing the latest and greatest applications and occasionally even beta apps.

Now with so many applications on your system, I think it’d be prudent to know which ones are accessing the Internet.

The below command will give you both the application accessing the Internet and the IP address it’s connecting to.

$ lsof -P -i -n

or

$ lsof -P -i -n | cut -f 1 -d " "| uniq | tail -n +2

The above command gives just the name of the applications using the Internet.

12. Solid state drives are all the rage with IT guys now, right? A couple of weeks back, even a scrooge like me picked up a Samsung EVO 240 SSD at Best Buy for $99 (250GB version).

But how would you identify whether the hard drive inside your computer is an SSD or the oldstyle spinning disk. Simple, just run the below commanbd,

$ cat /sys/block/sda/queue/rotational
0

If the answer is 0, then you have a SSD inside. If the output is 1, then it’s a regular hard drive.

Inxi – A Nonpareil Command Line Tool

 Command Line, Linux  Comments Off on Inxi – A Nonpareil Command Line Tool
Dec 132014
 

Although there are solid GUI tools like hardinfo and sysinfo that provide a cornucopia of hardware, software and even networking information about your Linux system, nothing beats inxi for those who live, breathe and die on the command line.

The beauty of inxi is that it provides its output in an easy to read format.

How to Install Inxi

Unfortunately inxi does not come installed by default on any of the distros (Linux Mint, Ubuntu, Red Hat and Kali) I’ve explored.

But installing inxi is not a hard task.

It takes no more than a couple of minutes to get it running on your Linux system.

* Ubuntu/Debian users should run the below command to install inxi on their systems (inxi script may come pre-installed on Linux Mint):

# sudo apt-get install inxi

* CentOS/Fedora users must run the following command:

# sudo yum install inxi

inxi – Various Commands

Now let’s take a dekko at some of the key inxi commands.

Single Line
$ inxi -c 6
CPU~Quad core Intel Core2 Quad CPU Q9400 (-MCP-) clocked at 2659.881 Mhz Kernel~3.13.0-24-generic i686 
Up~2 days Mem~1350.7/3875.8MB HDD~2000.4GB(8.4% used) Procs~198 Client~Shell inxi~1.8.4

You get the essentials of your Linux system including processor, harddisk, memory etc on a single line (on your terminal, the info should be in a single line but I’ve split up the output above for lack of space).

Display Basic Information
$ inxi -b
System:    Host: Sasha Kernel: 3.13.0-24-generic i686 (32 bit) Desktop: Gnome Distro: Linux Mint 17.1 Rebecca
Machine:   System: Dell product: OptiPlex 780
           Mobo: Dell model: 03NVJ6 version: A02 Bios: Dell version: A14 date: 08/21/2012
CPU:       Quad core Intel Core2 Quad CPU Q9400 (-MCP-) clocked at 2659.881 MHz 
Graphics:  Card: Intel 4 Series Chipset Integrated Graphics Controller 
           X.Org: 1.15.1 drivers: intel (unloaded: fbdev,vesa) Resolution: 1600x900@60.0hz 
           GLX Renderer: Mesa DRI Intel Q45/Q43 x86/MMX/SSE2 GLX Version: 2.1 Mesa 10.1.0
Network:   Card: Intel 82567LM-3 Gigabit Network Connection driver: e1000e 
Drives:    HDD Total Size: 2000.4GB (8.4% used)
Info:      Processes: 199 Uptime: 3 days Memory: 1408.6/3875.8MB Client: Shell inxi: 1.8.4
Display Audio Card Info
$ inxi -A
Audio:     Card: Intel 82801JD/DO (ICH10 Family) HD Audio Controller driver: snd_hda_intel
           Sound: Advanced Linux Sound Architecture ver: k3.13.0-24-generic
Show Graphics Card Info

Check out the below command for details on graphics card in your Linux system.

$ inxi -G
Graphics:  Card: Intel 4 Series Chipset Integrated Graphics Controller 
           X.Org: 1.15.1 drivers: intel (unloaded: fbdev,vesa) Resolution: 1600x900@60.0hz 
           GLX Renderer: Mesa DRI Intel Q45/Q43 x86/MMX/SSE2 GLX Version: 2.1 Mesa 10.1.0
Show CPU Info
$ inxi -C
CPU:       Quad core Intel Core2 Quad CPU Q9400 (-MCP-) cache: 3072 KB flags: (lm nx sse sse2 sse3 sse4_1 ssse3 vmx) 
           Clock Speeds: 1: 2659.881 MHz 2: 2659.881 MHz 3: 2659.881 MHz 4: 2659.881 MHz
Information on Drives

The below inxi command provides details on both hard drives and optical drives.

$ inxi -d
Drives:    HDD Total Size: 2000.4GB (8.4% used) 1: id: /dev/sda model: SAMSUNG_ST2000LM003 size: 2000.4GB 
           Optical: /dev/sr0 model: N/A dev-links: cdrom
           Features: speed: 8x multisession: yes audio: yes dvd: yes rw: cd-r,cd-rw,dvd-r,dvd-ram
Display Machine Information

The following command should give you information on system name, model, motherboard, bios

$ inxi -M
Machine:   System: Dell product: OptiPlex 780
           Mobo: Dell model: 03NVJ6 version: A02 Bios: Dell version: A14 date: 08/21/2012
Display WAN IP Address
$ inxi -i
Network:   Card: Intel 82567LM-3 Gigabit Network Connection driver: e1000e 
           IF: eth1 state: up speed: 100 Mbps duplex: full mac: 84:2b:2b:ba:ec:21
           WAN IP: 213.238.170.107 IF: eth1 ip: 10.0.1.5
Show Partition Information
$ inxi -p
Partition: ID: / size: 1.8T used: 158G (10%) fs: ext4 ID: /boot size: 236M used: 44M (20%) fs: ext2 
           ID: swap-1 size: 4.12GB used: 0.02GB (1%) fs: swap
Display Full Information

Of all the inxi commands, inxi -F provides the maximum data covering all aspects of the computer.

$ inxi -F
System:    Host: Sasha Kernel: 3.13.0-24-generic i686 (32 bit) Desktop: Gnome Distro: Linux Mint 17.1 Rebecca
Machine:   System: Dell product: OptiPlex 780
Mobo: Dell model: 03NVJ6 version: A02 Bios: Dell version: A14 date: 08/21/2012
CPU:       Quad core Intel Core2 Quad CPU Q9400 (-MCP-) cache: 3072 KB flags: (lm nx sse sse2 sse3 sse4_1 ssse3 vmx)
Clock Speeds: 1: 2659.881 MHz 2: 2659.881 MHz 3: 2659.881 MHz 4: 2659.881 MHz
Graphics:  Card: Intel 4 Series Chipset Integrated Graphics Controller
X.Org: 1.15.1 drivers: intel (unloaded: fbdev,vesa) Resolution: 1600x900@60.0hz
GLX Renderer: Mesa DRI Intel Q45/Q43 x86/MMX/SSE2 GLX Version: 2.1 Mesa 10.1.0
Audio:     Card: Intel 82801JD/DO (ICH10 Family) HD Audio Controller driver: snd_hda_intel
Sound: Advanced Linux Sound Architecture ver: k3.13.0-24-generic
Network:   Card: Intel 82567LM-3 Gigabit Network Connection driver: e1000e
IF: eth1 state: up speed: 100 Mbps duplex: full mac: 84:2b:2b:ba:ec:21
Drives:    HDD Total Size: 2000.4GB (8.4% used) 1: id: /dev/sda model: Samsung_ST2000LM003 size: 2000.4GB
Partition: ID: / size: 1.8T used: 158G (10%) fs: ext4 ID: /boot size: 236M used: 44M (20%) fs: ext2
ID: swap-1 size: 4.12GB used: 0.02GB (1%) fs: swap
RAID:      No RAID devices detected - /proc/mdstat and md_mod kernel raid module present
Sensors:   System Temperatures: cpu: 30.0C mobo: N/A
Fan Speeds (in rpm): cpu: N/A
Info:      Processes: 194 Uptime: 2 days Memory: 1113.1/3875.8MB Client: Shell inxi: 1.8.4

Go ahead, take inxi for a spin on your Linux system.

You’ll be surprised at how much information you can gather on your system via the inxi command.

Don’t forget to check the man pages for inxi by running:

$ man inxi

on the command line to get a list of the various inxi options.

Related inxi Content
Information about Inxi
Inxi Installation

Netstat Cheat Sheet for Newbies

 Command Line, Linux  Comments Off on Netstat Cheat Sheet for Newbies
Dec 132014
 

Of the several command line tools available to Linux administrators, netstat ranks among the most useful.

Netstat displays network connections for Transmission Control Protocol (incoming and outgoing), routing tables, and several network interface and network protocol statistics.

Although some Linux administrators are known to grumble that ss is a newer, better and faster tool performing similar chores, netstat still rules with the majority of Linux systems administrators including yours truly.

Besides helping to resolve networking issues, the other reason netstat is a valuable tool for Linux systems administrators is because it can serve as a first line of defense in identifying potentially hostile visitors harboring malicious intentions.

Besides Linux, netstat can be used on BSD, Windows XP, Windows Vista, Windows 7 and Windows 8 operating systems.

Netstat – Key Commands

The various options available for netstat are far too numerous to be detailed in full here.

In this post, we’ll consider the most important netstat commands. These are commands no Linux administrator can do without.

Display All Connections
$ netstat -a

Above command lists all connections from different protocols like tcp, udp and unix sockets

List Only TCP connections
$ netstat -at
List Only UDP Connections
$ netstat -au
Show IP Address without Reverse DNS lookup
$ netstat -ant
List All Listening Conditions
$ netstat -l
List Only Listening TCP Ports
$ netstat -lt
List only listening UDP Ports
$ netstat -lu
Display Summary Statistics
$ netstat -s

The above command spits out a wealth of information including total packets received, incoming packets delivered, active TCP connections, failed TCP connection attempts etc.

You can spend the better part of a day analyzing the output. 😉

To print out statistics of only select protocols like TCP or UDP use the corresponding options like t and u along with the s option.

Display Statistics for TCP
$ netstat -st
Display Statistics for UDP
$ netstat -su
Displays Domain Name Where Possible for IP Address
$ netstat -F
Display Only IP address
$ netstat -n

Above command will display output without resolving host, port and user name.

Get Netstat Output Continuously
$ netstat -c

The -c option can be combined with other netstat options like -t (see below).

$ netstat -ct
Displays TCP Connections Continuously
$ netstat -tcp

Above command will output TCP connections along with PID continuously.

Display Process Identifier (PID)
$ netstat -p

Above command adds PID/program name to output.

The -p option can be combined with other options (see below).

Show Service Name with PID Number
$ netstat -tp

Continue reading »

Memory – Ultimate ‘Free’ Cheat Sheet

 Command Line, Linux  Comments Off on Memory – Ultimate ‘Free’ Cheat Sheet
Dec 122014
 

There’s nothing more crucial to a computer or server than memory.

Information on memory installed, memory used and memory free are indispensable data to any Linux system administrator.

Should memory on your system be inadequate for the load, the results will be most unpleasant to users.

The best way to understand memory use and availability on your Linux system is via the ‘free‘ command, a feature that comes with most Linux installations.

Understanding Memory

Before jumping into the nuances of the “free” command, let’s spend a few seconds to understand the basic memory concepts.
* Physical Memory – Amount of memory installed and currently used
* Real Memory – How much memory is used by the applications
* Swap Memory – Portion of virtual memory on hard disk that’s used when RAM is full (high swap memory usage is not good)
* Virtual Memory – Combination of RAM and disk space that running processes can leverage

Free – Basics

On the command line, we use free to get information about memory use on a Linux desktop or server.

In this post, let’s consider the various options for free.

usage: free [-b|-k|-m|-g] [-l] [-o] [-t] [-s delay] [-c count] [-V]
-b,-k,-m,-g show output in bytes, KB, MB, or GB
-l show detailed low and high memory statistics
-o use old format (no -/+buffers/cache line)
-t display total for RAM + swap
-s update every [delay] seconds
-c update [count] times
-V display version information and exit

Free – Various Commands

Let’s start with the basic command.

jason@ChristyPC ~ $ free
             total       used       free     shared    buffers     cached
Mem:       3968848    3352196     616652     200544     225512    2040400
-/+ buffers/cache:    1086284    2882564
Swap:      4022268       2016    4020252

In the above example from my Linux Mint desktop, the three lines represent physical memory, real memory and swap memory respectively.

The “used” memory in the first line is misleading because Linux systems take into account even buffer and cache.

So when you run the free command, the second line representing real memory is the most important line in understanding memory use on your computer.

In the above example, there’s still 2.88GB of free memory available, which means I’m in a comfortable zone on my Linux Mint desktop.

Display Free Output in Human Understandable Format

Sometimes command line outputs are needlessly complicated.

Thankfully, there are simple ways out.

jason@ChristyPC ~ $ free -h
             total       used       free     shared    buffers     cached
Mem:          3.8G       3.4G       387M       217M       219M       2.0G
-/+ buffers/cache:       1.1G       2.6G
Swap:         3.8G        68K       3.8G

The above command worked fine on Ubuntu and Linux Mint and by extension should work on all Debian systems.

Note: Unfortunately, on Red Hat Linux systems the free -h command does not work.

I got an an error message (see below) when I ran the free -h command on a Red Hat system:

jason@ChristyPC ~ $ free -h
free: invalid option -- h
Display Memory in Gigabytes

You have the option to display in gigabytes, megabytes etc.

Let’s look at the command for free in gigabyte format since it’s easy to understand at just a glance.

jason@ChristyPC ~ $ free -g
             total       used       free     shared    buffers     cached
Mem:             3          3          0          0          0          1
-/+ buffers/cache:          1          2
Swap:            3          0          3

Continue reading »

Tar It, Baby! Just Tar It

 Command Line  Comments Off on Tar It, Baby! Just Tar It
Dec 082014
 

As a Red Hat Linux server administrator, one command I’ve frequently resorted to is tar.

Tar (the command originates from tape archive) is also one of the first commands a Linux newbie must quickly learn.

Uses of Tar

Now why would anyone need to learn to use tar?

Tar is used to combine multiple files/directories into a single file that can then be moved, downloaded or copied.

Tar is also a convenient tool to backup key files on the server to your local system.

I’ve relied on tar to backup multiple web sites on my Linux server and download them to my local computer.

You can use tar with or without compression.

The benefit of compression is that in most cases it reduces file size significantly and thus facilitates faster downloads.

Tar – Basic Syntax

Before jumping into the nitty gritty of creating a tar file, let’s try to understand the basic syntax of creating and extracting a compressed tar file.

Create a tar of [directory-name]

$ tar -zcvf archive-name.tar.gz directory-name

-z: Compress archive using gzip program
-c: Create archive
-v: Verbose i.e display progress while creating archive
-f: Archive File name

Extract a tar file

$ tar -zxvf archive-name.tar.gz

-z: Uncompress archive using gzip program
-x: Extract archive
-v: Verbose i.e display progress while creating archive
-f: Archive File name

Use of the v option (above) is not compulsory.

Here are a bunch of tar commands you’ll find useful as a Linux administrator or if you’re just tinkering on the command line:

1. Create a Tar file without zipping

$ tar -cvf tommy.tar inputfile1 inputfile2 inputfile3 inputfile4

In the above example, we’re creating an unzipped (uncompressed) tar file called tommy.tar that includes four input files. We will continue to use our fictional tommy.tar for the other tar commands too.

2. Extract an uncompressed tar file

$ tar -xvf tommy.tar

where tommy.tar is the tar file we created earlier.

3. Create a Tar file with compression (zipping)

$ tar -zcvf tommy-december-2014.tar.gz december-2018

Above command will create an archive called tommy-december-2018.tar.gz in current working directory

4. Extract (Restore) a Compressed (zipped) Tar file

$ tar -zxvf tommy-december-2018.tar.gz

The above command will restore files in current working directory

5. Extract into Different Directory
There are two ways to extract files into a particular directory (for example in /Bobby):
a) Here’s the first method:

$ tar -xvf tommy.tar.gz -C /Bobby

To test if the files have been extracted properly, head over to the “bobby” directory and then run the ls command:
cd /Bobby
ls

b) cd to the destination directory /Bobby and then untar our tommy.tar.gz file there

$ tar -zxvf tommy.tar.gz

Peek Inside Tar Files

Now for some reason or the other you might want to see what’s inside a tar file before extracting it.

You can peer inside regular (unzipped) tar files as well as inside zipped tar files before extracting them.

6. To see, what’s inside a plain (unzipped) tar file, run the below command:

$ tar -tf tommy.tar

where tommy.tar is the tar file you want to look inside and option -t lists the files in the archive.

7. To see what’s inside a zipped tar file, the below command should do the trick:

$ tar -ztf tommy.tar.gz

where tommy.tar.gz is the tar file you want to look inside

8. But what if you’re playing with a tar.bz2 file.

Not to worry, sweetie. To peer inside a bzip2 tar file, you’d run the following command:

$ tar -jtf tommy.tar.bz2

Continue reading »