Unix commands notebook

Introduction to the Unix / Linux command notebook

I first used Unix over 20 years ago when I was at college.  After that I got my first job and the company were then taking out their old Unix based system and were replacing it with a big IBM S/36 system which was later upgraded to an AS/400.  Along the way we saw DOS and Windows come and go.  Now here we are in 2009 and although AS/400 and Windows are still very important the systems which I spend most of my time managing today are Unix based; I can’t help feeling technology has gone around in a circle.  As I was getting back up to speed with Unix after all these years I’ve been keeping a few notes which I’ve typed up below.  I’ll be adding to this list from time to time as I find something else useful that I want to make a note of.  If you have any comments please get in touch.

Running commands as the Super User

It is best practice to be logged on with the minimum authority required to perform your work.  This isn’t just true on Linux but any computer platform.  There are a few reasons for this. a) If your user id and password were to become known to someone else the possible damage would be limited to whatever your user id is authorized to do b) If you visit a website or receive an attachment containing a virus, then the damage that it can cause is limited to whatever your user id can do.  Never get into a habit of logging on as Root or Administrator for your day to day work.

In Linux to Open a command window (right click on the desktop and select Open Terminal if you’re running a GUI).

The terminal will be logged on using your current user profile.

When you need to install a new package or change configuration you can switch to Super User mode by using the su command. This will prompt you for the password of the root user profile. Once you supply the correct password your terminal window will then be logged on as the root / super user.

Useful sources of installation, boot log files and configuration information for your Linux server.

In /var/log you should find a file called boot.log, this can be displayed by using the command

cd /var/log
cat boot.log

People from an AS/400 / iSeries / i5 background can think of this in terms of using DSPLOG to view the history of the last IPL.

In /root you should find a file called install.log this lists all of the installed packages and lists in errors found during the install.

dmesg (equivalent of OS/400 WRKHDWRSC) lists detailed information about your systems hardware configuration.

What is the Linux equivalent of the Windows IPCONFIG or OS/400 CFGTCP command?

The nearest equivalent command I have found so far is /sbin/ifconfig

How do I connect to my Linux server for admin purposes from a Windows system?

We have Linux running on Servers but Windows on the desktop. To save walking to the Linux servers console use a Secure Shell (ssh) client. Windows does not ship with an ssh client so you will need to download a free client. See http://www.ssh.com/products/tectia/ or download directly from ftp://ftp.ssh.com/pub/ssh/

From Windows you can then use the ssh client to connect to your Linux server.

How do I connect to my Linux server for admin purposes from a Mac OSX system?

On the Mac OSX comes with a built in SSH terminal application.   Just search for Terminal using Spotlight or locate it manually in the Applications directory.

What is the Linux equivalent of WINZIP / PKZIP / PKUNZIP or the OS/400 AS/400 Save File (*SAVF)?

The command gzip is an Open Source Linux equivalent. You should note that unlike on Windows or DOS the Linux ZIP process happens in two steps. First the files are packaged together into a single file using the tar utility and then the tar file is compressed using gzip.

gzip -d <filename> will uncompress the file to the current directory
tar -xvf <filename> will unpackage the tar file into the current directory. (X=Extract, V=Verbose, F=Filename)

The tar command lets you combine these two steps into a single command…

tar -xvzf <filename> this command will extract the tar and unzip it in one step.

How do a run an executable script file from the terminal window?

You need to type ./<filename>

How do I get more information about commands?

info <command name>
man <command name>

How do I find files on my Linux server?

Use the locate command eg

locate <filename / wildcard>

Common Linux file management commands

mkdir – Make directory

rm – remove/delete a directory / file

cp – copy eg cp <source> <destination>

mv – move file. This is also used to rename a file.

ls | more – list contents of directory a page at a time

ls | less – display contents of a directory in a scrollable list

tail <filename> – displays the last 10 entries in a file

ls >inventory.txt – outputs the results of the ls command to a text file called inventory.txt. If the file already exists it will be overwritten. To append to the end of an existing file use >> for example ls >>inventory.txt

ls -al – this lists the directory and shows the files, directories and access rights.

File Level Access Rights

Set a file to read-only.

chmod u=rwx,grwx,o=rwx <file> -R
chmod 004 <filename>

Linux text file editor commands

There are numerous editors available including nano (which seems similar to WordStar in the CPM days!) but the one to master is vi.

Use the cursor keys to move around the file.  To insert new text press the INSERT key on your keyboard, when complete press ESCAPE to go back to navigate mode.

When in navigate mode you can enter commands.  The most useful commands are:

:w – write or save the file

:q – exit

:q! – exit without saving

/<string> – find string

/ – next result

Search files

It’s often useful to be able to search large text files or log files; for example to find error messages or an IP address in a log file.  To do this use the grep command.

grep 172.16.1.1 access_log |more

Speak Your Mind

*