Wednesday, November 7, 2007

Basic GNU Screen Usage

Something you can use when performing long running processes on UNIX systems is GNU Screen.

Screen combined with SSH is to UNIX what Remote Desktop Connection is to Windows. Once you start screen, all processes you start under screen will remain running when you disconnect from a machine or are dropped by the server or network problems.

And like Remote Desktop Connection, you can start a process while connected from one machine and reconnect from another machine to resume your work.

To check whether you have existing screen sessions, type the following:

screen -ls


If the command outputs something starting with "There is a screen on ..." then you have one or more screen sessions. If the command outputs something starting with "No Sockets found in ...", then you do not have any screen sessions.

Generally you will only have one screen session. To "attach" to an existing screen session that is "detached"---if it is the only one---, type the following:

screen -r


To detach from a screen session you have open, type the following:

[CTRL]-a d (That is "Control" + "a" followed by "d")

After detaching, you can exit your terminal session.


To quit your screen session, type "exit" at your shell prompt and screen will quit.


If you do not have any screen sessions, type the following to start one:

screen


There are many more things you can do with screen but would take quite a bit to cover. If you want to learn more, please visit the "GNU screen" page at http://aperiodic.net/screen/ or read the fine manual ("man screen").

Wednesday, June 13, 2007

Windows & Its Useless Help System

I know this isn't Linux related but I figured I would rant about it because of the current Windows to UNIX DNS migration I am performing for one of our clients.

It never ceases to amaze me how 100% accurate Windows Help is but 100% useless it is.

For instance, I have around 2,000 domains to delete from the Windows primary and secondary DNS servers. I figured it would be easier to filter by TLD or ccTLD and delete all the domains for those TLDs that have been migrated over to the UNIX DNS server.

I brought up the filter dialog, which has limited filtering capabilities but usable, and tried to filter by names containing the TLD or ccTLD in the same manner as performing a find files in Windows Explorer, however, once I clicked OK it just refreshed the display and showed all domains on the server.

I figured I would pull up the help to see if there is a special syntax that has to be used for filtering but I didn't find any (no surprise). The only thing I found in the help is basic knowledge that all sys admins or experienced computer users should know. For instance, how to click on a menu and select the item you want.

The sad thing is Windows Help has been 100% useless since I used my first PC in 1993.

Tuesday, May 22, 2007

Using the Bash Shell Efficiently

Here are some Linux/UNIX GNU Bourne-Again SHell (bash) tricks for the beginners out there, as well as, the casual shell users.

The following text was based on the capabilities of GNU bash version 3.2.15(1). If you're using a different version of bash, your mileage may vary. Please, consult the bash man page if your bash shell does not work as described here.

Remember, dog is not your friend... man is.


Most Linux distributions come with bash and is the default login shell for user accounts on the box. You can check which shell you are using with the following command in your shell:

echo $SHELL



If this simple command returns "/bin/bash", "/usr/bin/bash", or "/usr/local/bin/bash", then you are using bash and can use the below tricks in your shell.


1. Searching through your command line history

Say you're working in the shell and previously ran a command but get tired of scrolling back through hundreds of commands in the history to find it. Here comes readline support to the rescue.

To find the command you're looking for, press '[CTRL]-r' then type a portion of the command and the readline support will seach backward through the history for the command.

Once you find the command, you can press '[ENTER]' to run it or press '[ESC]' to place the displayed command on the command line for editing before running it. If you change your mind and don't want to run the command you're searching for, press '[CTRL]-c' to abort the search.

If the command displayed is not the one your looking for, press '[CTRL]-r' again and bash will seach backward through the history for the next match. Likewise, if you passed the command you wanted to run, press '[CTRL]-s' to seach forward through the history for the command.

If the portion of the command you typed is too broad to find the command you are looking for, you can continue to type out the command to narrow the search.

You can read more about this and more in the "Commands for Manipulating the History" section of the bash man page (type 'man bash').


2. Moving around on the command line

It can get quite annoying to move the cursor around on the command line at times with the arrow keys---especially if the command is 3 or more lines long.

To move to the beginning of the line, press '[Home]' or '[CTRL]-a'.

To move to the end of the line, press '[End]' or '[CTRL]-e'.

To move to the next word, press '[ALT]-f'. You can provide a count of words by pressing '[ALT]-#' before this key combination where '#' is the number for words.

To move to the previous word, press '[ALT]-b'. Again, you can provide a count of words by pressing '[ALT]-#' before this key combination where '#' is the number for words.


3. Manipulating your typed command

a) Say you typed a command in the shell then realize you transposed two characters. Instead of moving your cursor to the transposed characters deleting them and typing them in the correct order, do the following.

Move your cursor to the second character and press '[CTRL-t]'. The readline support will swap the two characters for you.

The same thing can be done with words. If your transposed two directory names (i.e. /log/var/messages instead of /var/log/message), options, or commands in a command list; move your cursor into the second word and press '[ALT]-t'. The readline support will swap the two words for you and is smart enough to do the right thing for the most part. If you want to swap long and short options, readline will not do the right thing.

b) Now, say you typed in a command but did not realize the caps lock was on. No problem.

Go to the beginning of the command then press '[ALT]-l' for all the words in the command to change them to lowercase. Or, you can provide a count of words by pressing '[ALT]-#' before this key combination where '#' is the number for words.

You can change all letters in a word to uppercase by pressing '[ALT]-u' or capitalize a word by pressing '[ALT]-c'. You can provide a count of words to change with '[ALT]-#' too.

Keep in mind, however, that '[ALT]-l', '[ALT]-u' and '[ALT]-c' operate from the current cursor position forward, which means you can change a portion of a word. You can also change words from the current cursor position backward by pressing '[ALT]--' (That's [ALT]-{Minus}) and optionally follow it by the number of words to change before pressing the above key combinations.

You can read more about this in the "Commands for Changing Text" section of the bash man page (type 'man bash').

c) OK, you ran a command previously and pulled it up from the command line history but want to change options or path(s) or want to run a different command on the same path. There are several ways to do this efficiently.

To delete everything from the current cursor position to the end of the command, press '[CTRL]-k'.

To delete everything from the current cursor position to the beginning of the command, press '[CTRL]-x' followed by '[Backspace]'.

To delete everything from the current cursor position to the end of the word, press '[ALT]-d'. You can provide a count of words by pressing '[ALT]-#' before this key combination where '#' is the number for words.

To delete everything from the current cursor position to the beginning of the word, press '[ALT]-[Backspace]'. Again, you can provide a count of words by pressing '[ALT]-#' before this key combination where '#' is the number for words.

To delete everything from the current cursor position backward but stop at white space, press '[CTRL]-w'. And yes, you can provide a count of words by pressing '[ALT]-#' before this key combination where '#' is the number for words.

You can read more about this and more in the "Killing and Yanking" section of the bash man page (type 'man bash').

d) All that text on the screen bothering you or getting in the way of reading the current command you are typing? No problem, press '[CTRL]-l' and the screen will be cleared with your current command moved to the top of the screen.

Thursday, May 10, 2007

Welcome to Experiences of a Linux / FOSS User

Thanks for visiting "Experiences of a Linux / FOSS User".

I guess I'll start off by telling you about my background so here we go.

I started using Linux in 1995. At that time, I did not know anything about Linux other than it was "like" UNIX. I remember ordering the 4 disc set of "Official" Debian 1.3.1, "Official" Debian 1.3.2, RedHat 4.2 (Biltmore), and Slackware 3.4 from CheapBytes—I still have the discs to this day. I tried installing all three distros and settled on RedHat because I actually got it installed and running.

I knew quite a bit about DOS—not like there is a lot to know in the first place—and started to poke around Linux. I found some of the DOS commands worked in Linux but too few to be useful. I did some searching on the net and found a few more commands I could use then I stumbled across "The Linux Documentation Project".

After looking around on "The Linux Documentation Project" for a bit, I found "The Linux Users' Guide" and read it. From then on, "The Linux Users' Guide" and "The Linux Documentation Project" became indispensable.

I ran RedHat for about 5 years until I got fed up with its lack of a dependency system and moved to Mandrake, which only lasted for less than a year. I finally made a jump to Debian which lasted for a few years until I got tired of very outdated packages and Debian's stance that only "free" software would be included in the distro.

I then decided to go for broke and went to Linux From Scratch (LFS). I learned a lot more about gcc, libraries, etc. while using LFS but in 2003 I made the move to Gentoo Linux and have been using it ever since.

As far as work goes, I got my first job as an Associate Systems Administrator in 2000 for a company in the Kansas City area—hint, it is the one that everyone whispers at when talking on the phone to a radio station for fear of loosing their job—until getting laid off in 2002 due to downsizing. As an Associate Systems Administrator, I got to experience DG/UX, HPUX, AIX, Sun Solaris and Debian.

Due to the market being stagnate in 2002 onward, I was either unemployed or did various contract Desktop / Help Desk support jobs until I landed an UNIX Systems Administrator contract in 2006 at an advertising agency that became a full-time position in 2007.

At my current job, we are using RedHat Enterprise Linux, SUSE Linux Enterprise, CentOS, Sun Solaris, Windows and VMware on Linux to create and provide hosting for our clients' interactive marketing solutions.