SiNgAuTaRa - Live with EMC # NetApp # Solaris # Linux # UNIX

December 28, 2005

Learn Simple Trobleshooting UNIX

Filed under: general

Troubleshooting UNIX

* File System
* CPU and Memory
* Network

What to do when you have system problems?

The basic idea is to follow an organized procedure and not just randomly jump from one idea to another and quickly loose sight of what you have checked. A good basic technique is to divide the problem into areas and check each area until you are reasonably certain that the problem is not there and then after noting what you have checked, go on to another area.
File System

Tour of Unix File system

/ is the root of the unix file system. Everything grows from here.

/bin This contains a set of binaries used when the machine is first booted. Usually only a small subset of commands are available here.

/etc This contains system configuration files and executables. The password file and boot scripts are two examples of configuration files.

/dev This contains special files that are used to communicate with disks, tape, cdrom, and terminals.

/home This usually has the users home directories.

/list+found This contains lost files. Files that are recovered by fsck are placed in this directory.

/mnt A temporary mount point directory. It should be empty. Used for temporarily mounting directories.

/tmp Temporary directory available to all users as scratch space. Used by editors for temporary working copies of files. This is why you cannot send mail, edit or such activities when /tmp is full.

/var Spool files, accounting data and other varying data.

Display Free Disk Space

To see what the file system is looking like, including free and used space, then use the df -k command to see what the space is doing.

[www]:[5:01pm]:[/var/log] > df -k
Filesystem 1K-blocks Used Avail Capacity Mounted on
/dev/da0s1a 496111 38559 417864 8% /
/dev/da0s1f 23324075 10301228 11156921 48% /usr
/dev/da0s1e 9924475 194425 8936092 2% /var
procfs 4 4 0 100% /proc
[www]:[5:01pm]:[/var/log] >

One of the more common problems that UNIX will run into but is difficult to intially see is the file system filling up. There are several prominent reasons that this can happen:

* Little system maintenance has been done in the past and the file system is simply full, most likely from temp files.
* A hard drive didn’t mount properly, either due to a configuration issue or more likely to a problem with the hard drive itself. See fsck below.
* Configuration issue where a file was supposed to go to a tape drive or remote file system, but instead was stored on the local system and filled up the hard drive.

I/O Statistics

/usr/etc/iostat 5

This reports every 5 seconds.

This gives the I/O activity for disks, by default only 4 disks. This can help determine if disk activity is causing your problems.

tin tout sps tps msps sps tps msps sps tps msps us ni sy id
0 15 2 0 2.0 2 0 23.7 16 1 13.7 4 9 3 0 84
0 0 0 0 0.0 0 0 0.0 0 0 0.0 0 0 0 0100
0 0 0 0 0.0 19 1 26.5 13 1 12.5 0 0 0 0100

Checking the Memory and CPU Environment

Top CPU use processes

top

This gives an updating display of the top 10 to 15 cpu processes and some cpu statistics. The default update interval is 5 seconds. This may not be available on some systems as if installed with privs it can kill jobs that do not belong to you.

load averages: 0.00, 0.00, 0.00 04:50:47
35 processes: 1 running, 34 sleeping

Memory: Real: 3992K/10M Virt: 8308K/112M Free: 588K

PID USERNAME PRI NICE SIZE RES STATE TIME WCPU CPU COMMAND
27519 dlq 30 0 212K 356K run 0:00 0.00% 0.00% top
27471 dlq 18 0 224K 300K sleep 0:01 0.00% 0.00% csh
27368 dlq 18 0 224K 304K sleep 0:00 0.00% 0.00% csh
25144 dlq 18 0 220K 304K sleep 0:00 0.00% 0.00% csh
27401 dlq 18 0 224K 300K sleep 0:00 0.00% 0.00% csh
94 root 18 -12 316K 216K sleep 63:15 0.00% 0.00% xntpd
27366 dlq 18 0 388K 160K sleep 0:00 0.00% 0.00% screen
13977 joe 18 0 232K 120K sleep 0:01 0.00% 0.00%
82 root 18 0 284K 108K sleep 5:11 0.00% 0.00% cron
80 root 18 0 72K 60K sleep 29:41 0.00% 0.00% update
1 root 10 0 136K 124K sleep 0:25 0.00% 0.00% init
125 root 10 0 416K 64K sleep 120:58 0.00% 0.00% httpd
98 root 10 0 72K 28K sleep 0:00 0.00% 0.00%
99 root 10 0 72K 28K sleep 0:00 0.00% 0.00%
14239 sally 3 0 224K 224K sleep 0:00 0.00% 0.00%

uptime

The uptime utility displays the current time, the length of time the system has been up, the number of users, and the load average of the system over the last 1, 5, and 15 minutes.

[www]:[5:14pm]:[/home/rnejdl] > uptime
5:14PM up 73 days, 1:39, 4 users, load averages: 0.01, 0.05, 0.03
[www]:[5:14pm]:[/home/rnejdl] >

In general, these numbers should be under 1, but a system may in general run high, so it is a good idea to have some historical information for these values before assuming that something is wrong here.

ps

As the load average is high, you need to determine the cause. Use ps -auxw to find out what processes are running on your system. Does the list of processes look normal (you really need to do this before you have problems so you can know what “normal” is)? If not look at the abnormal cases, maybe 20 copies of sendmail running. This is likely not something of your making, more likely it is a network slowness so the messages are moving v e r y s l o w l y. But you would want to check to see if that is the case.

[crimson]:[5:17pm]:[/home/rnejdl] > ps -auxw
USER PID %CPU %MEM VSZ RSS TT STAT STARTED TIME COMMAND
rnejdl 40659 1.0 0.5 1700 1340 p7 Ss 5:17PM 0:00.05 -tcsh (tcsh)
root 1 0.0 0.1 528 208 ?? ILs 20Jul01 0:04.53 /sbin/init —
root 2 0.0 0.0 0 0 ?? DL 20Jul01 0:08.92 (pagedaemon)
root 3 0.0 0.0 0 0 ?? DL 20Jul01 0:00.00 (vmdaemon)
root 4 0.0 0.0 0 0 ?? DL 20Jul01 0:37.37 (bufdaemon)
root 5 0.0 0.0 0 0 ?? DL 20Jul01 17:15.40 (syncer)
root 205 0.0 0.2 928 568 ?? Ss 20Jul01 0:37.76 syslogd -s
root 228 0.0 0.2 1048 628 ?? Is 20Jul01 0:00.75 inetd -wW

w

The w command is useful to see who is currently logged into the system and what they are doing at this time.

[www]:[5:01pm]:[/var/log] > w
5:04PM up 73 days, 1:28, 4 users, load averages: 0.07, 0.07, 0.02
USER TTY FROM LOGIN@ IDLE WHAT
rnejdl p0 rnejdl 2:42PM - vi unixtroubleshooting
rnejdl p1 tethys.ringofsat Fri07PM 1day tail -f error_log2
rnejdl p2 tethys.ringofsat Fri07PM 15:55 -tcsh (tcsh)
rnejdl p3 rnejdl 4:11PM - w
[www]:[5:04pm]:[/var/log] >

Virtual Memory Statistics

Another cause of slowness is the system doing nothing but swapping since it has run out of memory. This may be caused by a gradual increase in workload or by having a number of runaway processes consuming all available memory. Here you want to issue a vmstat. One of the fields is swap i/o, you will probably need to do a man vmstat to find out what column(s) are swapping.

This command is useful to give an overview of your system’s memory resources and paging information. With some options it gives the i/o rates to disks.

vmstat 5

This reports every 5 seconds

procs memory page disks faults cpu
r b w avm fre flt re pi po fr sr w0 s0 s1 in sy cs us sy id
0 0 0 7708 692 79 2 0 0 0 0 0 0 1 111 516 16 13 3 84
0 0 0 8288 684 2 0 1 0 0 0 0 0 0 106 26 9 0 0 100
0 0 0 8652 684 1 0 0 0 0 0 0 1 1 107 24 9 0 0 100

System Messages

Check for system errors, error recovery can just halt a system. Look at the console messages and the system log. A full file system can also radically slow a system as it is having to recover from a full file system error after each write.

The system messages are found in the file /var/log/messages and to view this real time, you can use the tail -f command.

[crimson]:[5:20pm]:[/home/awilson2/bin] > tail -f /var/log/messages
Oct 1 16:56:37 crimson sshd[40453]: fatal: Timeout before authentication for 207.55.202.98.
Oct 1 16:58:37 crimson sshd[40468]: fatal: Timeout before authentication for 207.55.202.98.
Oct 1 17:00:37 crimson sshd[40483]: fatal: Timeout before authentication for 207.55.202.98.
Oct 1 17:02:37 crimson sshd[40504]: fatal: Timeout before authentication for 207.55.202.98.
Oct 1 17:04:37 crimson sshd[40531]: fatal: Timeout before authentication for 207.55.202.98.
Oct 1 17:06:37 crimson sshd[40546]: fatal: Timeout before authentication for 207.55.202.98.
Oct 1 17:08:37 crimson sshd[40563]: fatal: Timeout before authentication for 207.55.202.98.
Oct 1 17:10:37 crimson sshd[40580]: fatal: Timeout before authentication for 207.55.202.98.
Oct 1 17:12:37 crimson sshd[40603]: fatal: Timeout before authentication for 207.55.202.98.

Networking

Interface Config

The ifconfig command is useful for viewing the current state of the Ethernet interface that a server is using to connect with. Without any command arguments, it will show all of the interfaces that a machine is configured for, but here, we are only interested in the Ethernet interface, which is listed at the top as xl0.

[crimson]:[5:25pm]:[/home/awilson2/bin] > ifconfig
xl0: flags=8843 mtu 1500
inet 209.39.6.5 netmask 0xffffff00 broadcast 209.39.6.255
inet6 fe80::2c0:4fff:fe04:e77f%xl0 prefixlen 64 scopeid 0x1
ether 00:c0:4f:04:e7:7f
media: autoselect (100baseTX ) status: active
supported media: autoselect 100baseTX 100baseTX 10baseT/UT
P 10baseT/UTP 100baseTX
lp0: flags=8810 mtu 1500
faith0: flags=8000 mtu 1500
gif0: flags=8010 mtu 1280
gif1: flags=8010 mtu 1280
gif2: flags=8010 mtu 1280
gif3: flags=8010 mtu 1280
lo0: flags=8049 mtu 16384
inet6 fe80::1%lo0 prefixlen 64 scopeid 0x8
inet6 ::1 prefixlen 128
inet 127.0.0.1 netmask 0xff000000
ppp0: flags=8010 mtu 1500
sl0: flags=c010 mtu 552
[crimson]:[5:25pm]:[/home/awilson2/bin] >

One thing to watch our for is the media line to ensure that the network card is configured for 100 Megabits and Full-Duplex, which in this case it is. With Sun servers, the media type that the Ethernet card chooses often does not match that with the Catalyst switch at the other end of the connection. With these instances, hard coding the configurations for both ends tends to solve packletloss problems that come up.
Network Statistics

/usr/etc/netstat 5

This reports every 5 seconds.

input (we0) output input (Total) output
packets errs packets errs colls packets errs packets errs colls
46779720 25 8490605 1 100434 46781383 25 8492268 1 100434
16 0 2 0 0 16 0 2 0 0
14 0 1 0 0 14 0 1 0 0

Network errors can also bring your system to an effective crawl for users not logged on via directly attached terminals or the console. Sometimes you can find these by netstat 5. This gives you a count of packets, errors and collisions. The first line is a cumulative total, so you are interested in the following lines that are 5 second interval numbers. Lots of errors is very bad news, and you need to contact your networking support folks. A number of collisions equal to the number of packets sent is also a bad sign, usually it means that you have a conflict between transceiver and system in what they want for heartbeat or sqe test signals

http://networking.ringofsaturn.com/Unix/

December 23, 2005

Testware Installation on IFLEX

Filed under: general

Today i got error. This looks like port error or apps problem. I was struggling to resolve this, it’s occur due to the testware soft been launch at the iflex pc, meanwhile the testware soft been install inside Solaris Unix Box. What to do, ask prends, google lah, looking inside msg board or something crazy, aiyakkkkk i mmg blurrrrrr…hehe

so here the logs start fail……

[klflex579tw:/testware]% cd $LOGS
[klflex579tw:/testware/logs/klflex579tw]% pwd
/testware/logs/klflex579tw
[klflex579tw:/testware/logs/klflex579tw]% tail starttester.log
User Choose To Override It And Continue To Run
Start Tester Script
.xls
Thu Dec 22 14:36:13 SGT 2005: Clean Up Probecard And Loadboard In Shared Memory
mon_upd (3.6 07/01/04): can’t get shared memory key for prober name HEAD-FLEX579, key 579
mon_upd (3.6 07/01/04): can’t get shared memory key for prober name HEAD-FLEThu Dec 22 14:36:14 SGT 2005: Proglotfile Locate At /u/TI_apps/lot/proglot1
Thu Dec 22 14:36:14 SGT 2005: Test Program Directory Locate At /twprog/PRODUCTION/INTEGRAFLEX/PF007109
Thu Dec 22 14:36:14 SGT 2005: /u/TI_apps/IntegraFlex/USP/etc/igxl_load -UseFile
Debug::UspMessage “lotinfo1″ sent to 157.87.104.153:8002
/u/TI_apps/IntegraFlex/USP/etc/igxl_load[2]: /dev/tcp/157.x.x.153/8002: cannot create
[klflex579tw:/testware/logs/klflex579tw]%

December 20, 2005

How to restore crontab file

Filed under: general

today working was teribble, i was log in at one solaris unix box. i was at [/]. tah maciam mana i tertaip ‘crontab -r’. abihhh punah semua terdelete. then i do ‘crontab -l’, it was not there, alamakkkk, what to do, arghhhhh uhhhh ahhhh ihhh uhhhhh..hehe

i wanna to tell my boss but afraid maaa, then i start thinks what to do. i telnet to another unix box, then i do ‘crontab -l’, it was there and same like the previous unix box that i deleted…..
ahhHHHhhHHhh..lega. i try restore back the scripts using vi.

here the location file :

#var/spool/cron/root/crontabs
# vi root

-restore and save

here some info regarding crontab, it might useful for u guys…..hehe

export EDITOR=vi ;to specify a editor to open crontab file.

crontab -e Edit your crontab file, or create one if it doesn’t already exist.
crontab -l Display your crontab file.
crontab -r Remove your crontab file.
crontab -v Display the last time you edited your crontab file. (This option is only available on a few systems.)

crontab/cron = jobs scheduling

http://www.adminschoice.com/docs/crontab.htm#Restrictions

December 19, 2005

Learn Basic Unix

Filed under: general

Overview of Unix Commands

This document aims to provide a core set of Unix commands to get you around.

General Unix Information
There are numerous flavours of Unix; AIX (IBM), Solaris (SUN), Xenix, Linux etc. all of which conform to the Posix standard. Unix often comes with a number of command shells, e.g. Bourne Shell ($ prompt) or C shell (% prompt with enhancements on the Bourne Shell) or Korn shell ($ prompt) which have slightly differing command syntax, although principally they are the same. The shell interprets the commands that you type. The ‘Tea Sea Shell’ (tcsh) is often used in the Linux environment and contains useful attributes such as ‘up-arrow’ and ‘down-arrow’ recall of previous command entries, and the use of the TAB key to complete commands (much like the Cisco IOS!). The shell interprets commands with the operating system kernel. The beauty of Unix is that hundreds of people can access one box at once and each one can run a number of programs, a separate shell opens for each log on that occurs, and each user can have a completely different ‘environment’ setup, different colours, priviledges, file and directory access and different shell.

Unix file names can be up to 14 characters long and include the _ and the . characters.

Every Unix command or filename is case sensitive, unlike DOS, this is the most common error to be aware of. Commands leave ‘notes’ for programs (such as printing) that are ‘buried’ in the Unix system. This is so that one user does not hog one program, many people can access it. Such a program is called a ‘daemon’.

An Absolute Pathname starts from the root directory e.g. /user/bin. The Relative pathname points to a file or directory that is relative to the position that you are in within the directory tree and this does not start with a /.

Information about users is kept in the passwd file which sits in the /etc directory along with the other configuration files. For each user there are seven fields separated by colons:

* User name (first part of e-mail address).
* Encrypted password.
* UID (Users ID) needed by the Unix system. User names can change without changing user permissions.
* GID (Group ID). A user may be a member of several groups each having different permissions.
* Comment containing more detail on the user if desired.
* User’s home directory.
* The shell to be used by the particular user.

Nowadays, when you are confronted with a Unix box you will come across an X-windows interface. To get to a command line interface, grab the three button mouse click the right button and select programs clicking on it with the left mouse button. In the list of programs that appear select either shell or command to open a command line window (much like a DOS box in Microsoft Windows). You normally need to click on the title bar or border before you can type in the window, sometimes the X-window interface has been set up such that the mouse moving over the window is enough to highlight the box. Any number of these command line windows can be opened. Resizing them is achieved by selecting the bottom right hand corner with the left mouse button (a circle appears) and dragging the window edges to the required size. Minimising a window is achieved by ‘left-clicking’ on the top left corner of the menu bar and selecting close. Selecting quit closes the window.

Keystrokes

Ctrl-c

Stops a command or program that is currently being executed.

Ctrl-d

Removes you from the current environment, this will log you out of the system if you are at a shell prompt.

Ctrl-h, Del

Deletes the last character typed and moves back one space. Unlike DOS, the backspace key does not work!

Ctrl-q

Resumes the command that was halted by Ctrl-s.

Ctrl-s

Temporarily halts the current command being executed, e.g. scrolling of text on the screen.

Ctrl-u, Ctrl-x, @

Cancels what you have just typed, so that you can start again.

Ctrl-x

Deletes the current line of text being entered.

Directory Commands

cd

Stands for change directory, e.g.

cd /user/dave

takes you to dave’s personal directory. The first / refers to root. Root is the equivalent of / in DOS. Typing cd without a path takes you back to your home directory, i.e. where you arrive when you first log on. Typing cd.. takes you up one directory, whereas typing cd ../user/dave, takes you up one directory and then right down to the ‘/user/dave’ directory.

df -k

Stands for disk free, gives you the amount of space available on the disk that you are currently on.

mkdir

Means ‘make directory’, e.g.

mkdir user

creates a directory called user in the directory you are in when you issue the command.

pwd

Stands for print working directory and prints the directory that you are in to the screen.

rmdir

Means remove directory e.g.

rmdir user

removes the directory user provided that it is empty!

System Commands

-&

Using this switch after a command causes it to operate in the background, allowing you to continue using the same command line window without having to open another one.

*

This wildcard character matches any number of characters and is useful in searches, e.g.

g*

matches all files beginning with ‘g’.

?

This wildcard character matches any single character, e.g.

g??

matches all three character files beginning with ‘g’.

>

Redirect output from a program to a file, e.g.

ls -l > listing

redirects the listing of ls -l into a file called ‘listing’.

< Redirect output from a file into a program, e.g.

mail john < hello

redirects the greeting letter called 'hello' to John, rather than you having to type it.

|

Pipe output from one program to another, e.g.

who | wc -l

gives a count of the users on the system.

>>

This append adds the input to an existing file without overwriting the original, e.g.

postcript >> letter

adds the contents of ‘postscript’ to an existing file called ‘letter’.

chsh

Means change shell and changes the shell that the user is using. The user will be prompted for a password since the ‘passwd’ file is being changed, then the user will need to type the path to the shell e.g. /bin/bash.

echo

This ‘echoes’ arguments to the screen, e.g.

echo $SHELL

displays the value of the environment variable SHELL. This could return /bin/tcsh (Linux often uses this shell) or /bin/bash. echo $PATH displays the current path.

env

The environment gives you the variables set up for the particular user that issues the command.

exit, Ctrl-d

Logs you out.

jobs

This lists the jobs running under the current shell in ‘job ID’ order. You can type bg %jobid to put a particular job running in the background. Ctrl Z also suspends a job. Typing fg %jobid brings the job back to the foreground.

kill

This kills a process e.g.

kill 5173

kill the process which has been given the temporary number 5173. This process number is found by using the ps command. Do not use kill 1 as this kills the system scheduler! If a process refuses to die you can type kill -KILL [PID] to stop a process immediately without any tidying up on exitting. Finally, kill -HUP [PID] tells the process that an event has occurred, or a configuration file change has occurred and needs to br reread.

man

The manual command is very useful for finding out comprehensive information on an individual command e.g.

man cd

gives all the information on the command cd. Typing man -k mail lists the Unix commands that relate to the word mail.

passwd

Allows you or the administrator to change passwords.

printenv

The ‘prints the environment’ variables to the screen.

ps

The process status command shows the programs currently running. ps -a shows all the processes being run by all users. An example is the following:

ps -ef | grep erpcd

where ‘-ef’ gets the process number and pipes it to grep which filters on the following word, in this case for the program ‘erpcd’.

The following information is shown:

* PID Process ID.
* TTY Each shell opened has a ‘character special’ called a ‘tty’ (held in ‘/dev’).
* STAT State, either ‘S’, sleeping, or ‘R’, running.
* TIME CPU time that the process is taking up.
* COMMAND The command running.

Typing ps x shows all the processes relating to X windows, whereas ps ax shows all the processes being run by everybody. Typing ps ux gives even more information such as the user.

setenv

The command set environment variable, sets aside a small amount of memory to hold paths etc. e.g.

setenv GUI /usr/utility/gui_r4

sets a variable ‘GUI’ with the path that follows to the actual program. This program can now be run by typing ‘GUI’.

setenv DISPLAY :0.0

sets an X window session locally.
These settings are commonly setup permanently in the user’s .profile (located in the ‘/etc’ directory). This can be edited with any text editor.

The following are common environment variables:

* SHELL The current shell.
* HOME The current user’s home directory.
* HOSTNAME The name of the computer.
* DISPLAY The X display that the applications are to use.
* LD_LIBRARY_PATH The search path for libraries.
* PATH The search path for applications.

If you wish to append directories to the path then type setenv PATH ${PATH} : /search/here. In order to use it then you need to cache the new path by typing rehash.

The DISPLAY variable is made up of three parts ‘hostname : displaynumber : screennumber’. The hostname is the computer, whilst the other variables are ‘0′ unless several machines are connected. X windows looks to this variable to find out where to send the X Windows traffic.

set path

Sets a path where regularly used programs or data are found e.g.

set path=($path /usr/utility/gui_r4/bin)

sets the path ‘/usr/utility/gui_r4/bin’.

Some commands used to set the environment come from the C shell. In order to check which shell you are running type echo $SHELL, if this does not return ‘/sbin/csh’ then you type /bin/csh.

su

The command switch user switches the login user to another user, e.g.

su root

switches to the ‘root’ login.

top

Gives a constantly updating view of the top 20 processes (a real time version of ‘ps’), i.e. those that are using the CPU the most.

who

This displays the users currently logged on the system.

whoami

Displays who you are currently logged on as. (e.g. ‘root’, a user etc.)

xhost +

Opens an X window for a program to run in. After issuing this you would then run the program (e.g. Netscape).

File Commands

.

The dot is not a command as such. If a file is spelled with a dot at the beginning, Unix treats it as a hidden file. Configuration files are often preceded with a dot.

cat

The concatenate command displays a file, e.g.

cat bankletter

displays the contents of ‘bankletter’ on the screen.

cat > newletter

takes whatever you type and redirects it into the file ‘newletter’, Ctrl-d gets you out of it.

cat >> existing

takes whatever you type and appends it to an existing file called ‘existing’ funnily enough.

chmod

The command change mode changes the mode or permissions, of a file or a directory. When you do an ls -l you will see in the first column, a line of 10 characters looking something like ‘drwx-w-rw-’. The ‘d’ means ‘directory’ (you could have ‘-’ for file, ‘l’ for link to a file, ‘b’ for a ‘block special’, ‘c’ for a ‘character special’, ‘p’ for a ‘named pipe’, or ’s’ for ’socket’). The next three characters refer to the permissions of the login user, in this case the user has read, write and execute access to the directory. The next three characters refer to the permissions of the group and the final three characters refer to the permissions of all users. The chmod command can be used in various ways as shown by the following examples:

* chmod go-rwx newletter removes read, write and execute permissions for users in the group (g), and all other users, for the file ‘newletter’. Using a ‘+’ instead of ‘-’ adds the permissions. You can also use ‘o’ for others, or ‘u’ for user.
* chmod 766 newletter causes the file ‘newletter’ to have read, write and execute permissions for the user, read and write permissions for the group members and read and write permissions for all other users. Why? Well, the 7 represents 111(binary) and 6 represents 110(binary) for each set of three ‘rwx’s. ‘r’ being set is given binary 1, ‘x’ being not set is given binary 0. Read permission is ‘4′, write permission is ‘2′, execute permission is ‘1′ and no permissions is given with ‘0′.
* chmod 700 dirname results in drwx—— for the directory which restricts access to everyone bar the owner.
* chmod 664 filename gives -rw-rw-r– that allows you and your group to read and edit the file but all others can only read the file.
* chmod 600 filename gives -rwx—— creates a private file that only you can see and edit.

You can change permissions for groups of files with one command by using wildcards such as *.

chown

Use this to change ownership of a file e.g.

chown dave myfile

changes the ownership of the file ‘myfile’ to dave. This can only be carried out by the owner of the original file. A way around this is for the recipient to copy the file, then the copied file becomes their own.

chgrp

Use this to change group ownership of a file.

compress

This compresses a file e.g.

compress myfile

results in a file called ‘myfile.Z’. The command uncompress can be used to uncompress the file.

cp

The copy command copies files from one directory to another, or to the same directory with a different name, e.g.

cp bankletter /user/dave/bankletter1

copies the file ‘bankletter’ from the directory that you are currently in, to the ‘/user/dave’ directory with a new name ‘bankletter1′.

file

This returns information on the content of a file, e.g.

file myletter

might return ‘ASCII’ to say that Unix guesses that ‘myletter’ contains ASCII.

find

This finds a file or directory, e.g.

find / -name na -print &

this finds a file with name ‘na’ starting the search from the ‘root’ and printing the result to the shell window, whilst still allowing you to carry on using it.

grep

This stands for global regular expression and print and is a search utility, e.g.

grep “325 Victory”

searches the current directory for files containing the text ‘325 Victory’.

gzip

GNU zip compresses files to create a ‘**.gz’ file.

head

This command followed by a filename, displays the first ten lines of that file.

less

This is a way of displaying a file, it will give a percentage of file so far displayed at the bottom of the screen, and you can progress through reading the file by pressing the space bar.

ln

The command link, links files and directories, e.g.

ln -s/export/home/fred usr/fred

creates a copy of ‘fred’ in the ‘/export/home/’ directory in the ‘usr/fred’ directory. A ‘hard link’ is like a Windows ’shortcut’, there can be a number of them, with different names and they take up little space. A ’soft link’ is identified with the ‘-s’ switch and creates a copy of the file elsewhere.

lp (for System V) or lpr (for BSD)

The command line printer, prints a file, e.g.

lp newletter

prints ‘newletter’.

lpstat -a all

The line printer stats command checks the printer queue in System V Unix.

ls

This lists the contents of the current directory, e.g.

ls /etc

lists the files and sub-directories of the current directory.

* ls -l gives a long list of directories including file sizes, permissions, type etc. Using the -a switch causes ‘all’ files to be listed including those hidden files starting with ..
* ls -c lists files by creation time.
* ls -p marks directories with a slash at the end of the name.
* ls -x displays the list in rows across the screen.
* Using ls | more is useful for large directories as it stops the screen scrolling, you press the ‘Return’ key to advance one line at a time, or press the space bar to advance one page at a time.

You can type ‘ls’ and then define one or more directories for it to list.

more

This is another way of displaying a file, it will give a percentage of file so far displayed at the bottom of the screen, and you can progress through reading the file by pressing the space bar. Whilst in more, if you type v you will be taken straight to the vi editor.

mv

This moves a file from one directory to another or renames it in the same directory, e.g.

mv bankletter bankletter1

renames ‘bankletter’ to ‘bankletter1′.

pg filename

Displays the content of the file one page at a time. You advance pages by pressing ‘Return’. Option -l displays one more line, option n moves you to the page number specified by n and options +n and <>-n moves you forward or backward the number of pages specified by n.

rm

‘remove’ a file, e.g.

rm oldletter

removes the file ‘oldletter’. Using rm -rf recursively removes all files and directories below the one that you are in. Using rm -i gives you the option of cancelling or confirming the command.

sort

Sorts the contents of a file, e.g.:

sort -o outfile infile

The contents of ‘infile’ are sorted in alphabetical order and fed into a new file called ‘outfile’, as defined by the switch ‘-o’.

tail

This means the tail end, this dynamically displays the file that is being written to in real time, e.g.

tail -f logfile

shows the file ‘logfile’ which is being written to.

tar

The command tape archive is an file archiving command. It creates a single uncompressed archive file from several, ideal for sending data over networks. Often files are archived, and then compressed using ‘gzip’. E.g.

tar -tvf tarfile

displays the contents of a tarfile.

tar -xvf tarfile

extracts the contents of a tarfile. ‘x’ is extract, ‘v’ means ‘verbose’ and ‘f’ means the file.

tar -xvf tarfile target

extracts the file target from the tarfile.

touch

This just creates an empty file for appending to later on e.g.

touch log

creates an empty file called ‘log’ that needs to be available for another program to write to it perhaps.

uncompress

This command uncompresses a ‘gzip’ file, e.g.

uncompress myfile.gz

uncompresses the file ‘myfile.gz’.

wc

The command word count counts the words in a particular file, e.g.

wc letter

counts the number of words in the file ‘letter’

Simple Scripting

A Unix script is the equivalent of the DOS batch file. Using vi, the following could be typed into a file called ‘new_script’:

echo These users are on the system
who
echo Here is a detailed listing of the directory you are in
ls -al

The command chmod u+x new_script makes the script file executable by the logged in user.

Networking Commands

arp

Displays the ‘Address Resolution Protocol’ table e.g.

arp -a

displays all arp entries for all connected devices.

arp -d

deletes the arp entry for that particular IP address.

ftp

The command file transfer protocol attaches you to another IP device e.g.

ftp 141.205.15.154

attaches you to the device with address 141.205.15.154. You are normally presented with a login and password screen.

Commands that are used in FTP are:

* dir - directory listing.
* quit - quit from ftp.
* cd - change directory.
* get or mget - get a file (or multiple files).
* put or mput - put a file (or multiple files).
* bin - sets up your system to receive binary files.
* hash - displays hashes whilst files are being transferred.
* lcd - local change directory changes the directory on your local machine to which you are sending and receiving files. This is useful as it saves you having to quit ftp to carry out the directory change.

The Hosts file can be found in the directory ‘/etc’.

netstat

This stands for network statistics, e.g.

netstat -r

displays the routing table of the Unix box.

netstat -a

displays alll network information.

Unix uses routed to listen to RIP in order to discover the Default Gateway.

ping

Ping an IP device e.g.

ping 141.205.51.26

rlogin

This works like telnet, e.g.

rlogin 141.205.52.16

takes you to another Unix machine only. To quit you press ‘return’, ‘~’, .’ and ‘return’ again.

telnet

Ctrl-6 and then Ctrl-] gets you to the telnet> prompt where typing close gets you out of telnet.

vstat

This displays CPU utilisation and gives a list of processes and their share of CPU utilisation, e.g.

vstat 10

displays the CPU utilisation every 10 seconds.

ifconfig

This displays the IP configuration of the box, e.g.

ifconfig -a

displays all IP configuration.

If you want to look at the routing process you can type:

ps -ef type grep routed

to send the ‘routed’ information to a file.

snoop

This command captures the network packets in a readable format, e.g.

snoop -p 23

captures all IP traffic using port 23 (Telnet). use Ctrl-C to stop the snoop.

Useful vi commands

Each command needs to be preceded by pressing the escape key!

i insert mode.
&ltesc> leave insert mode and go into command mode.
a append characters to the end of the line.
o open a line below your cursor.
O open a line above.
&ltshift&gtg go to the bottom of the file.
r replace the letter that you are on with the one you type next.
x erase the character that you are on.
dd delete the line that you are on. A number before dd deletes that number of lines.
yy copy the line you are on. A number before yy copies that number of lines.
p paste the line you are on below you.
P paste the line you are on above you.
:wq write and quit the file that you are editing.
:wq! write and quit the file that you are editing, even if it is designated as read only!
:w! write to a read only file.
:q quit.
:q! discard any editing and quit.
/ this takes you to the bottom of the window where you can type a string and return to perform a search in the file.

(The character ! is often referred to as pling)

You can use vedit which is vi with more user friendly additions and also ed, or emacs.

Hello world!

Filed under: general

Welcome to singautara at Blogsome. This is your first post. Edit or delete it, then start blogging!

An email has been sent to you giving you details how to login to the administration section. From there you can change the design by clicking on the tab MANAGE and then click on the tab THEMES. If you have any questions ask them in the forum. We are only too willing to help.

Get free blog up and running in minutes with Blogsome
Theme designed by Gary Rogers