Introduction to UNIX

What is Unix:

  • Unix is a computer operating system . Which is set of programs that act as a link between the computer and the user.
  • It was originated around 1969 at AT&T Bell Labs
  • Unix is Multi user : That means several people can use Unix computer at the same time
  • Multi Tasking : Users can also run multiple programs at the same time
  • There are multiple flavors of Unix Like Operating systems Example: Sun Solaris, Mac , Linux (Red Hat / Ubantu)

Basic Architecture of Unix :

  • Hardware : Hardware (HW) is the physical machine with CPU, Memory and Storage
  • The Kernel of UNIX is the hub of the operating system: it allocates time and memory to programs and handles the filestore and communications in response to system calls.
  • The shell acts as an interface between the user and the kernel. When a user logs in, the login program checks the username and password, and then starts another program called the shell. The shell is a command line interpreter (CLI). It interprets the commands the user types in and arranges for them to be carried out.
  • If you are connecting remotely to a server your access will typically be through a command line shell.
  • Applications : Applications runs on top of the Unix OS and interacts with the HW through OS

Basic Unix Command Line (Shell) navigation :

  • When you log in to a unix system, it takes to a prompt (as shown below) where you to enter a command.
  • Every unix command is a sequence of letters, numbers and characters with no spaces.
  • Unix is case sensitive
  • The prompt is displayed by a special program called the Shell
  • Shells accept commands and run those commands
  • You can also write scripts, in the shell’s own language. These programs are called shell scripts
  • There are two major types of shells in unix: Bourne shells(also called bash) and C shells

Logging on to a Unix System :

  • You can login to the local unix system or you can telnet to a remote server with it’s IP address
  • The machine that we are going to connect is web based unix terminal from “”
  • Connect to your terminal until you see a login prompt (login:)

Logging in To a Unix System contd…..

  • Once you are on the terminal the system would ask for login and password
  • login: <<Enter your login>>
  • password: <<enter your password and hit enter>>
  • Once your login is successful you will get the welcome screen and will be taken to your home folder

Logging out of a Unix System :

  • It is important that you logout gracefully from an operating system
  • Logout just closes your session but does not shutdown the Unix Machine
  • To logout of Unix use the below command
  • logout : Use “logout” command on the prompt
  • exit : Alternatively you can use “exit” command as well to logout

Directory Structure :

  • All the files are grouped together in the directory structure. The file-system is arranged in a hierarchical structure, like an inverted tree. The top of the hierarchy is traditionally called root(written as a slash / )
  • For Example in the diagram full path to the file h2k is



Command Structure and Help:

  • Most commands has the key command syntax followed by options then parameters
  • command [options] [parameters]
  • Example man ls

There is a command “man” which is abbreviation of manual, can be used to get the details of any command

Example : “man ls” gives below details

Viewing/Listing folder Content:

  • ls— lists your files

  • ls -l— lists your files in ‘long format’, e.g. the exact size of the file, who owns the file and who has the right to look at it, and when it was last modified.
    ls -a — lists all files, including the ones whose filenames begin in a dot, which you do not always want to see.
    There are many more options, for example to list files by size, by date, recursively etc.

Creating / Removing Folder / Directory System

  • To create a directory
  • mkdir <<new directory name>>: makes or creates a new directory with the name provided
  • Example
  • mkdir newfolder : creates a directory named “newfolder” in the current directory

To see the directory just you have created, type “ls”

To Remove Directory

  • rmdir <<directory to remove>> the directory  name mentioned will be removed or deleted
  • Example
  • rmdir dir2remove : will delete the directory or folder named “dir2remove”

Navigating through File System :

  • cd <<directory name>>: change the directory to the “name mentioned”
  • Example
  • “cd h2k “ change the directory to the “h2k” directory
  • “cd ..” : The “.. “Represents the parent directory, so it moves to the parent directory.

Moving information:

  • cp(copy) : cp is used to copy contents of file1 to file 2

cp file1 file2(contents of file1 is copied to file 2 in the same directory)

  • rm(remove or delete files)

rmdir(remove directory)

rm filename

  • mv(move): move a file from one place to another

mv file1 file2 moves (or renames) file1 to file2

Clearing screen:

  • clear(clear screen): to clear the terminal window of the previous command

$ clear

This will clear all text and leave you with the $ prompt at the top of the window

Displaying the contents of a file on the screen :

  • cat(concatenate): cat can be used to display the contents of a file on the screen.

$ cat science.txt

Displaying with head :

  • head: The head command writes the first ten lines of a file to the screen.

so first clear the screen then type

$ head science.txt

Then type $ head -15 science.txt

It means print the first 15 lines of the file science.txt

  • tail: The tail command writes the last ten lines of a file to the screen.

$ tail science.txt

  Searching the contents of a file

  • wc(word count) simply counts the number of words, lines and characters in the files.

wc [-clw] [file1 file2 … fileN]

The three parameters,  clw, stand for character,  line, and word respectively, and tell  wc which of the three to count.

  • grep is the generalized regular expression parser.

This is a fancy name for a utility which can only search a text file.

grep [-nvwx] [-number] { expression} [file1 file2 … fileN]


Command Example Description
1.     ls ls
ls -alF
Lists files in current directory
List in long format
2.     cd cd tempdir
cd ..
cd ~dhyatt/web-docs
Change directory to tempdir
Move back one directory
Move into dhyatt’s web-docs directory
3.     mkdir mkdir graphics Make a directory called graphics
4.     rmdir rmdir emptydir Remove directory (must be empty)
5.     cp cp file1 web-docs
cp file1 file1.bak
Copy file into directory
Make backup of file1
6.     rm rm file1.bak
rm *.tmp
Remove or delete file
Remove all file
7.     mv mv old.html new.html Move or rename files
8.     more more index.html Look at file, one page at a time
9.     lpr lpr index.html Send file to printer
10.   man man ls Online manual (help) about command
1.     who who Lists who is logged on your machine
2.     finger finger Lists who is on computers in the lab
3.     ytalk <user@place> ytalk dhyatt@threat Talk online with dhyatt who is on threat
4.     history history Lists commands you’ve done recently
5.     fortune fortune Print random humerous message
6.     date date Print out current date
7.     cal <mo> <yr> cal 9 2000 Print calendar for September 2000
8.     xeyes xeyes & Keep track of cursor (in “background”)
9.     xcalc xcalc & Calculator (“background” process)
10.   mpage <opt> <file> mpage -8 file1   |  lpr Print 8 pages on a single sheet and send to printer (the font will be small!)

  Useful for monitoring system access, or simplifying your own environment

 Key UNIX Commands
 managing your own account

Command Example Description
1.     grep <str><files> grep “bad word” * Find which files contain a certain word
2.     chmod <opt> <file> chmod 644 *.html
chmod 755 file.exe
Change file permissions read only
Change file permissions to executable
3.     passwd passwd Change passwd
4.     ps <opt> ps aux
ps aux   |   grep dhyatt
List all running processes by #ID
List process #ID’s running by dhyatt
5.     kill <opt> <ID> kill -9 8453 Kill process with ID #8453
6.     gcc (g++) <source> gcc file.c -o file
g++ fil2.cpp -o fil2
Compile a program written in C
Compile a program written in C++
7.     gzip <file> gzip bigfile
gunzip bigfile.gz
Compress file
Uncompress file
8.     mail
mail < file1
Send file1 by email to someone
Read mail using pine
9.     telnet <host>
ssh <host>
ssh -l dhyatt
Open a connection to vortex
Open a secure connection to jazz as user dhyatt
10.   ftp <host>
ncftp <host/directory>
Upload or Download files to station1
Connect to archives at UNC

Write a Reply or Comment

Your email address will not be published.