A Few Useful Tips

If you are using UNIX-based system, working with the console or just writing shell scripts, below you find useful information that is presented in the form of short tips.

Here they are:

• finding host/domain name and IP address - hostname
• test network connection – ping
• getting network configuration – ifconfig
• Network connections, routing tables, interface statistics – netstat
• query DNS lookup name – nslookup
• communicate with other hostname – telnet
• outing steps that packets take to get to network host – traceroute
• view user information – finger
• checking status of destination host - telnet

hostname with no options displays the machines host name
hostname –d displays the domain name the machine belongs to
hostname –f displays the fully qualified host and domain name
hostname –i displays the IP address for the current machine

It sends packets of information to the user-defined source. If the packets are received, the destination device sends packets back. Ping can be used for two purposes

1. To ensure that a network connection can be established.
2. Timing information as to the speed of the connection.

If you do ping it will display its IP address. Use ctrl+C to stop the test.

View network configuration, it displays the current network adapter configuration. It is handy to determine if you are getting transmit (TX) or receive (RX) errors.

Most useful and very versatile for finding connection to and from the host. You can find out all the multicast groups (network) subscribed by this host by issuing "netstat -g"

netstat -nap | grep port will display process id of application which is using that port
netstat -a or netstat –all will display all connections including TCP and UDP
netstat --tcp or netstat –t will display only TCP connection
netstat --udp or netstat –u will display only UDP connection
netstat -g will display all multicast network subscribed by this host.

If you know the IP address it will display hostname. To find all the IP addresses for a given domain name, the command nslookup is used. You must have a connection to the internet for this utility to be useful.
E.g. nslookup

You can also use nslookup to convert hostname to IP Address and from IP Address from hostname.

A handy utility to view the number of hops and response time to get to a remote system or web site is traceroute. Again you need an internet connection to make use of this tool.

View user information, displays a user’s login name, real name, terminal name and write status. this is pretty old unix command and rarely used now days.

Connects destination host via telnet protocol, if telnet connection establish on any port means connectivity between two hosts is working fine.
telnet hostname port will telnet hostname with the port specified. Normally it is used to see whether host is alive and network connection is fine or not.

Here are some more:

add these line at the end of this file in your home directory...

set filec # to make the filenames have tab completion.

entenv PRINTER apm3414a
# to set the default printer to the line printer in
# Sunpal. Then you can just type lpr filename to print rather
# than lpr -PAapm3414a filename

# change prompt to show the current working directory as the prompt
set prompt = "`pwd`% "
alias cd 'cd \!*;set prompt = "`pwd`% "'

add these line at the end of this file in your home directory...
alias cd.. cd .. #aliases cd to allow cd.. to change to parent directory
alias ls ls -p # print a slash after directory names in c shell
alias dir ls # make dir and ls both print the directory
quota -v #print out remaining space useage in your account
bash # start bash command shell, make this be LAST because anything
# after this command will not run until bash exits

how you do this depends what shell you are running
csh: alias newname oldname
bash: alias newname='oldname'
(to cancel any of the aliases temporarily, use unalias newname)

running a program from a terminal window so the program will not quit if you close the terminal window: add an & to the end of the program name for example, xemacs& or xemacs &

Finding a program
which program_name = gives the path to a program name
locate file_name = searches for a file on the hard disk

bash shell tips:
to start bash type bash. to quit type exit.

edit (or create) the .bashrc file with:
PS1='\W>' # changes the command prompt to show the current directory
alias ls='ls -p' # show a "/" at the end of directory names in LS
alias cd..='cd ..' # allow dos style directory changes
alias logout='exit' # allows logout to exit bash and then type
# logout again to kill a telnet connection
why run bash?

-"tab" filename completion
-"up arrow" recent command list *especially this reason*
-backspace and delete BOTH type a backspace (no more ^H) when you hit backspace instead of delete by force of habit

usage: grep -options searchstring filemask
what does grep do? searches for text in a file.
-i = case insensitive
-n = show line numbers
jwinblad>grep -n cd .login
24:alias cd.. cd ..
ucsd/acs grep reference

man flename -> gives help on a program or topic

useage example: ls -pF ~/../public
-a = show hidden files (filenames starting with a dot)
-A = show hidden files but not the current directory and parent directory
-F = indicate the filetype with symbols (directories, executables, links, etc)
-g = -l without showing file ownership
-l = long format (shows more file details)
-m = comma seperate items instead of tab alignment
-p = adds / to the end of directory names
-t = sort by time
-R = include subdirectories
-s = show size of files
-x = sort files horizontally rather than vertically

ls options are case sensitive

method 1: sum the permissions
4=read / 2=write / 1=execute
order: user, group, other
eg. chmod 755 index.html will set permissions to "- rwx r-x r-x"
method2: add/remove by name
u = user / g = group / o = other / a = all 3 groups
+ = add permission / - = take away permission
r = read / w = write / x = execute
eg. chmod ug+rw index.html will change permissions to "- rw? rw? ???" (?'s are not affected)

groups = displays the groups you are in
chgrp <groupname> <file-or-directory> = changes the group for a file

basic usage: tar cvf [output file] [files to archive]
tar -cvf backup.tar *.java *.cup will compress all the .java and .cup files in the current directory
tar -xvf filename.tar ~uncompresses the files in filename.tar to the current directory

ps -fu jwinblad ~displays all processes running by user jwinblad
kill -9 pid-number ~kills a process with pid# of pid-number

We hope you found this post useful!
Siera 21 january 2012, 16:19
Vote for this post
Bring it to the Main Page


Leave a Reply

Avaible tags
  • <b>...</b>highlighting important text on the page in bold
  • <i>..</i>highlighting important text on the page in italic
  • <u>...</u>allocated with tag <u> text shownas underlined
  • <s>...</s>allocated with tag <s> text shown as strikethrough
  • <sup>...</sup>, <sub>...</sub>text in the tag <sup> appears as a superscript, <sub> - subscript
  • <blockquote>...</blockquote>For  highlight citation, use the tag <blockquote>
  • <code lang="lang">...</code>highlighting the program code (supported by bash, cpp, cs, css, xml, html, java, javascript, lisp, lua, php, perl, python, ruby, sql, scala, text)
  • <a href="http://...">...</a>link, specify the desired Internet address in the href attribute
  • <img src="http://..." alt="text" />specify the full path of image in the src attribute