This is an iEntry.com Website
Search iEntry News

Submit Your Site For Free!

Email Address:
* URL:
*
*Indicates Mandatory Field

Terms & Conditions

LinuxProNews
SecurityProNews
ITmanagement








Releasing The Potential Of GNU Core Utilities, Part 4

By Joe Purcell
Expert Author
Article Date: 2011-08-10

Continuing in the series of coreutils, let's now look at some shell utilities: arch, uname, uptime, tty, and pinky.

Shell Utilities

arch

Have you ever needed to know whether or not you're on a 64 bit or 32 bit operating system? The arch command will tell you the architecture of the machine, which is likely the architecture of the operating system as well;
$ arch
x86_64
or perhaps:
$ arch
i386

uname

The uname command can tell you a bit more about the operating system, as well as the architecture. The above command could be done by:
$ uname -m
x86_64
Or, one can use the `a` flag to get all the info:
$ uname -a
Linux computer-name 2.6.32-33-generic #71-Ubuntu SMP Wed Jul 20 17:27:30 UTC 2011 x86_64 GNU/Linux


uptime

This command is a fun one. It will tell you how long the computer has been active as well as the computer's load for the past one, five, and fifteen minutes:
$ uptime
12:11:41 up 2 days,  3:38,  8 users,  load average: 0.16, 0.34, 0.38


This means that my computer was using 16% of the CPU in the last minute, 34% in the last five, and 38% in the last fifteen minutes. If the first number was 1.16 it would mean that my computer is running at 116% of the CPU. In other words, 16% of the processes running have to wait for a turn to be executed.

printenv

Anyone who has tried installing a Linux program that involves environment various and other various complex configuration has run into issues with environment variables. They can easily cause an application to break. Fortunately, there is a command to print the current environment variables:
$ printenv
ORBIT_SOCKETDIR=/tmp/orbit-myusername
SSH_AGENT_PID=1405
TERM=xterm
SHELL=/bin/bash
XDG_SESSION_COOKIE=3951403ecd724af36022df0b4d6271b3-1639806863.297234-39117275
WINDOWID=86219733
GNOME_KEYRING_CONTROL=/tmp/keyring-gxuknp
GTK_MODULES=canberra-gtk-module
USER=myusername
SSH_AUTH_SOCK=/tmp/keyring-gxuknp/ssh
DEFAULTS_PATH=/usr/share/gconf/gnome.default.path
SESSION_MANAGER=local/mycomputer-name:@/tmp/.ICE-unix/1371,unix/mycomputer-name:/tmp/.ICE-unix/1371
USERNAME=myusername
XDG_CONFIG_DIRS=/etc/xdg/xdg-gnome:/etc/xdg
DESKTOP_SESSION=gnome
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
PWD=/home/myusername
GDM_KEYBOARD_LAYOUT=us
LANG=en_US.utf8
GNOME_KEYRING_PID=1353
MANDATORY_PATH=/usr/share/gconf/gnome.mandatory.path
GDM_LANG=en_US.utf8
GDMSESSION=gnome
SPEECHD_PORT=7560
HOME=/home/myusername
SHLVL=2
GNOME_DESKTOP_SESSION_ID=this-is-deprecated
LOGNAME=myusername
XDG_DATA_DIRS=/usr/share/gnome:/usr/local/share/:/usr/share/
DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-C5OLUbaxo2,guid=7bc5b68c2328d1f558e4da7b4e3fd7cf
DISPLAY=:0.0
XAUTHORITY=/var/run/gdm/auth-for-myusername-n1Nuuc/database
COLORTERM=gnome-terminal
_=/usr/bin/printenv

tty

This command may not appear very useful at first. However, there are many technical situations when one needs to know whether or not the current terminal is a direct input and the like. There are two types of terminals: tty and pts. the first stands for TeleTYpewriter (TTY) and is any physical connection to the computer, such as keyboard and mice. The second stands for Pseudo Terminal Slave (PTS) and is for SSH or telnet connections. For example, on my own computer I get:

$ tty
/dev/pts/4


The reason it isn't a tty is because it isn't a direct connection, I'm using gnome-terminal. However, if I switch to the Linux console using CTRL-ALT-F1 (use CTRL-ALT-F7 to get back to the GUI terminal which is your desktop), I get:
$ tty
/dev/tty/1


And if I SSH into another computer I may get something like:

$ tty
/dev/pts/12


So, for example, if you want to run a bash script according to whether or not the terminal is a tty or pts one can do what this online example shows.

pinky

This command will tell you information about all the users logged in: their username, full name, what IP address they are coming from, how long they've been idle, and when they first logged in. Pinky is a lighter version of finger which gives basically the same information, but, I would argue, doesn't have as good formatting for output. Here is an example output:

$ finger
Login        Name      Tty      Idle  Login Time   Office     Office Phone
myusername   My Name  *tty4       13  Aug 10 12:59
myusername   My Name   tty7       2d  Aug  8 08:34 (:0)
myusername   My Name   pts/0   20:27  Aug  8 08:41 (:0.0)
myusername   My Name   pts/1      2d  Aug  8 08:41 (:0.0)
myusername   My Name   pts/2   19:43  Aug  8 08:41 (:0.0)
myusername   My Name   pts/4          Aug 10 12:00 (:0.0)
myusername   My Name   pts/5      16  Aug 10 12:05 (:0.0)
myusername   My Name   pts/6      17  Aug 10 12:05 (:0.0)


If the pts terminal were from an outside source, say over SSH, it would show the IP address under "Office".

About the Author:
Joe Purcell is a technology virtuoso, cyberspace frontiersman, and connoisseur of Linux, Mac, and Windows alike.



Newsletter Archive | Article Archive | Submit Article | Advertising Information | About Us | Contact