Monthly Archives: September 2017

ifconfig output

In this post, I brought up the command ifconfig and I promised to talk about the output. It is rather confusing, so let’s pull it apart bit by bit so we can understand that ifconfig output.

eth0      Link encap:Ethernet  HWaddr 00:1A:2B:3C:00:00
          inet addr:192.168.0.10  Bcast:192.168.0.255  Mask:255.255.255.0
          inet6 addr: fd91:ae3b:d5e8:aa85:0:0:0:0 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:41620 errors:0 dropped:0 overruns:0 frame:0
          TX packets:40231 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:21601203 (20.6 MiB)  TX bytes:6145876 (5.8 MiB)
          Interrupt:21 Base address:0xe000

Let’s begin at the beginning! The first line says

eth0      Link encap:Ethernet  HWaddr 00:1A:2B:3C:00:00

That means that the link is an ethernet link. There is an ethernet cable attached to this computer connecting it to the Internet. The next part of the line says HWaddr and has some letters and numbers after it. We talked about IP addresses before and those can change on your computer. If you have a laptop and take it to a coffee shop, you’ll get a different IP address from the one you’ll have at home or that you would get in a library. Your computer never knows what IP address is going to show up, it isn’t like your home address which never changes.

The HWaddr is the fixed address of your computer, like your home address. It doesn’t change, no matter what. It’s also known as the MAC address. It’s set by the manufacturer of your ethernet card and never changes, no matter where you take your computer. You could take it to the Triskelion and it wouldn’t change.

Oh wait, that got destroyed in Captain America: Winter Soldier, didn’t it. You can’t take it there, but you could take it to the North Pole and it wouldn’t change.

The next line:

net addr:192.168.0.10  Bcast:192.168.0.255  Mask:255.255.255.0

Is information about your IP address and we already discussed that. Next time, we’ll talk about the line that starts with ip6. This ifconfig output is extensive, isn’t it? Lots of information that tell us all about the network interface on the computer.

 

Devices

Way back at the beginning I said that Linux® treats everything as a file.  Everything!  That includes devices, like the network interface, the wireless interface, the USB port, the motherboard, the sound board, speakers, microphones, you get the idea.  Every device you could add to your computer is treated like a file.

We can’t have those files floating around willy nilly, can we?  That’d be very confusing very quickly.  Sort of like asking the Hulk to keep track of Hawkeye’s arrows.  it would go really badly.

Hawkeye and His Arrows

Hawkeye

Instead, Linux® keeps all those files in one place, known as the /dev directory.  Every device has a file in this directory that Linux® uses to communicate with it.

If I do ls -l on /dev I get 676 lines.  I know because I did this:

Alpha:~ computerlamp$ ls -l /dev |  wc -l 
676

That doesn’t mean there are 676 devices on my system!  I’d have one busy system if that was the case.   It means that there are the possibilities for that many devices.

Let’s look at some of the output from ls -l:

Alpha:~ computerlamp$ ls -l /dev/
crw------- 1 root root  10, 235 Aug 11 02:19 autofs
crw------- 1 root root   5,   1 Aug 11 02:19 console
lrwxrwxrwx 1 root root       11 Aug 11 02:19 core -> /proc/kcore
crw------- 1 root root  10,  58 Aug 11 02:19 cpu_dma_latency
drwxr-xr-x 3 root root       60 Aug 11 02:19 disk
crw------- 1 root root  10,  63 Aug 11 02:19 dlm-control
crw------- 1 root root  10,  62 Aug 11 02:19 dlm-monitor
crw------- 1 root root  10,  61 Aug 11 02:19 dlm_plock
crw------- 1 root root  10,  60 Aug 11 02:19 ecryptfs
lrwxrwxrwx 1 root root       13 Aug 11 02:19 fd -> /proc/self/fd
crw-rw-rw- 1 root root   1,   7 Aug 11 02:19 full
crw------- 1 root root  10, 229 Aug 11 02:19 fuse

That isn’t very helpful, is it.  I don’t know what dlm means and why there’s a dlm-control or a dlm-monitor  I’m going to guess that the disk directory has something to do with hard drives, but I’m not sure.  encryptfs looks interesting, I bet it has something to do with encrypting things, but I’m not sure of that either.

The other thing to pay attention to is that the ownership and permissions of a lot of the files in this directory are restricted to root.  That means that while I can use ls -l to see that they’re there, I can’t actually look at them.

cowsay

We’re going to talk about another silly Linux® command because this one is one of my favorites.  It’s not a banner command like figlet or banner, instead, it’s called cowsay.

You read that right.  This post is about a command that’s called cowsay.  How silly is that?  Let’s look at the top of the man page for this command:

cowsay(1)                                                                  cowsay(1)

NAME
       cowsay/cowthink - configurable speaking/thinking cow (and a bit more)

A configurable speaking/thinking cow.  I did promise a silly command!  Let’s try it out:

Alpha:~ computerlamp$ cowsay Hi There!
 ___________
< Hi There! >
 -----------
        \   ^__^
         \  (oo)\_______
            (__)\       )\/\
                ||----w |
                ||     ||

Yes, that’s a cow saying Hi There!   I did promise a silly command.

I want to do it again, this command is fun!

Alpha:~ computerlamp$ cowsay Commandline is fun!
 _____________________
< Commandline is fun! >
 ---------------------
        \   ^__^
         \  (oo)\_______
            (__)\       )\/\
                ||----w |
                ||     ||

What if I don’t want my cow to speak and I would rather that my cow thinks?  Well, there’s a command for that!  It’s called cowthink.

Alpha:~ computerlamp$ cowthink This is silly!
 ________________
( This is silly! )
 ----------------
        o   ^__^
         o  (oo)\_______
            (__)\       )\/\
                ||----w |
                ||     ||

Unfortunately, there isn’t a catthink or a catsay.  I think that would be a lot of fun.  Maybe one day someone will write one!

Linux® has a lot of silly commands, as we’ve seen.  Even Linux® users want to have fun with the command line!

 

More than one way to do it

There’s more than one way to do it!  I think that should be one of the mottos of Linux®.  There’s always more than one way to do it.  That’s what we’re going to talk about in this post, some of the more than one way to do the commands we’ve already learned.

We learned about ls and how it has flags.  One of the most useful flags is -l which lets us see all the group ownerships and users and everything we could need.

For example:

Alpha:~ computerlamp$ ls -l
total 164
drwxr-xr-x   3 root root 69632 Aug  9 13:15 bin
drwxr-xr-x   2 root root  4096 Jan  5  2016 games
drwxr-xr-x  82 root root 20480 Jul 17 16:18 include
drwxr-xr-x 111 root root 24576 Jul 17 16:18 lib
drwxr-xr-x   3 root root 12288 Aug  3 06:43 libexec
drwxr-xr-x  19 root root  4096 Dec 27  2016 local
drwxr-xr-x   2 root root 12288 Jul 28 18:58 sbin
drwxr-xr-x 199 root root  4096 Jul 28 18:58 share
drwxr-xr-x   2 root root  4096 Apr 19  2012 src
drwxr-x---   3 root root  4096 Jan  5  2016 var

I listed all the files and directories in /usr using ls -l.  I can do the same thing with the command vdir.

Alpha:~ computerlamp$ vdir /usr
total 164
drwxr-xr-x   3 root root 69632 Aug  9 13:15 bin
drwxr-xr-x   2 root root  4096 Jan  5  2016 games
drwxr-xr-x  82 root root 20480 Jul 17 16:18 include
drwxr-xr-x 111 root root 24576 Jul 17 16:18 lib
drwxr-xr-x   3 root root 12288 Aug  3 06:43 libexec
drwxr-xr-x  19 root root  4096 Dec 27  2016 local
drwxr-xr-x   2 root root 12288 Jul 28 18:58 sbin
drwxr-xr-x 199 root root  4096 Jul 28 18:58 share
drwxr-xr-x   2 root root  4096 Apr 19  2012 src
drwxr-x---   3 root root  4096 Jan  5  2016 var

There’s more than one way to list the files.  I can even do it with find though it’s much more work than just doing vdir or ls.

If I leave off the -l flag, I get:

Alpha:~ computerlamp$ ls /usr
bin  games  include  lib  libexec  local  sbin	share  src  var

I get the same output if I do the following two commands, just with fewer spaces:

Alpha:~ computerlamp$ cd /usr
Alpha:~ computerlamp$ echo *

In other words, there’s more than one way to do it.  I can ls -l or vdir, or I can ls or use the echo * trick.

This is certainly not the only case of more than one command to do the same thing.  It keeps things interesting when you’re learning Linux®.