Tuesday, February 10, 2015

UNIX and Basic Interactive Commands


Some years ago when I was writing batch scripts on the fly, I notice that I kept on putting the “\” and “/“ mixed up. There was a moment of embarrassment until I realized it came from having UNIX shell scripting as my first scripting language. Naturally, it was good to come back to UNIX, where “/“ is where “/“ should be. Ha. 

I am still rather proud of UNIX as my alma mater was one of first institutions that invented and developed a variant of UNIX shell scripts, back in the days, and graded me on those things. That is not to say, there aren’t frustrations when one first walks into the world of UNIX. Imagine when you first come up with the idea of learning a new language, immediately you are told that there are numerous  dialects or variants to the language, and that other party - a computer, is not going to budge if you make a mistake on the particular dialect that it speaks. 

So which dialect should you learn? Bourne shell (sh), Korn shell (kWh), C shell (csh), TENEX C shell (tcsh), Bourne-Again shell (bash), or a host of other shells? Probably the safest way is to stick with the UNIX shells and Unix-like OS that your company is using, be it AIX, HPUX, Linux, BSD, Solaris, or the like. The variants do exist, though for your immediate needs, the variants won’t work on your system anyways. 

Now comes the interactive portion of working in UNIX, where you are given a command line prompt ‘$’ or ‘%’. It looks like the system had missed the entire ‘GUI development’ hype and you’re back at an archaic machines doing command line stuff like this thing has not evolved for years. Don’t worry, it has (evolved). You’re simply not distracted by trailing graphics, moving icons, sound, and stuff. 

One way of finding out which commands are available to you is to go to the /etc/bin directory from root, and do an ‘ls’, or ‘ls |more’, which will show you all the commands available. ‘|more’ (pronounced pipe, more). You can do a ‘man <command>’ to invoke technical manual entry for the particular command, which lists detail usage with operants (the letters after the ‘-‘). 

Some of the commands in the directory could be:
- change diectory - cd <dirname>
- make directory - mkdir <dirname>
- copy a file to a different name or location - cp <file1> <dir/file2>
- remove a file - rm <file1>
- change permission on file/directory - chmod <file1> or <dir1>
- compress file - gzip <file1>
- find current location - pwd
- find a file from current location - find . -name <file1>
- use the wild card at any search string - *
- look for specific string - grep
- find out who is logged on - who
- find out who you are logged on as: whoami
- list all current running process - ps
- end a process - kill PID
- read a file - cat
- |more - stops the screen from running away, use space to scroll the pages
- check date/time - date
- show your environmental variables - printenv
- set values to variables - set or export <varname>=<value>
- invoke a shell script - ./<file1>.sh (or tsh) 
- print the value of a variable - echo $var
- invoke a text editor such as vi - vi
- logoff - exit 

Not that you’re entirely devoid of the benefit of the GUI apps, you can install X11 applications such as X-Windows and keep it running in the background while you connect to the Unix/Linux like machines via a tool such as Putty, and invoke graphical apps. These are freeware that sometimes don’t bring up the screens as fast as a commercial app.

Now at least you can sign on and poke around. You can also invoke the text editor to do some scripting. Once you become familiar with these you'll be on your way to some more advanced UNIX maneuvering. 









No comments:

Post a Comment