Invite a friend
Recommend WhyTelecom to:



Introduction to UNIX


UNIX is an operating system which was first developed in the 1960s, and has been under constant development ever since. There are many different versions of UNIX, although they share common similarities. The most popular varieties of UNIX are Sun Solaris, AIX, GNU/Linux, and MacOS X.

Files and processes

Everything in UNIX is either a file or a process.  A process is an executing program identified by a unique PID (process identifier).

File System 

Root file system and root directory of the entire file system hierarchy.
Command binaries that need to be available in single user mode e.g., cat, ls
Boot loader files
Essential devices
Host-specific configuration files (example /etc/hosts).
Users' home directories - containing saved files, personal settings etc. example /home/vishnu
Libraries essential for the binaries in /bin/ and /sbin/.
Mount points for removable media
Temporarily mounted file systems.
Optional application software.
Virtual file system documenting kernel and process status as text files (e.g., uptime, network).
Essential system binaries (e.g., init, route, ifup).
Temporary files (see also /var/tmp).
Contains the majority of multiuser utilities and applications.
Non-essential command binaries
Standard include files.
Libraries for the binaries in /usr/bin/ and /usr/sbin/.
Non-essential system binaries
Source code with its header files
Tertiary hierarchy for local data, specific to this host.
Variable files, such as logs and temporary e-mail files.
Lock files. Files keeping track of resources currently in use.
Log files. Various logs.
Users' mail-boxes.
Information about the running system since last boot
Temporary files to be preserved between reboots.
 File System Navigation
·         Return to your home directory
# cd
·         Change directory to make directory your current directory
# cd <directory>
·         List the contents of the current directory
# ls
·         List files in a long format, showing permissions, owner, size
# ls -l
·         List all files, including "hidden" files
# ls -a
Note: Hidden file names begin with a dot "."
·         Recursively, for all subdirectories
# ls -R
·         List files based on time.
# ls -t
·         Display the name of the current directory
# pwd (print working directory)
Manipulating Files and Directory
·         To Copy File
# cp <file1> <file2>
File1 is the source file
·         Copy a directory and, recursively, its subdirectories
# cp -r <dir1> <dir2>
·         Create, or "make" a directory
# mkdir <directory name>
·         Move a file
# mv <file1> <file2>
Note:move command deletes the source file
·         Move files into a directory
# mv <files> <directory>
·         Remove file
# rm <files>
·         Remove files, directories, and recursively, any subdirectories.
# rm -r <names>
·         Remove directory
# rmdir
Note:directory must be empty
·         Display a calendar of the current month
# cal
·         Display a calendar of the given month and year
#cal <month> <year>
Ex: cal 02 2008
·         To Clears terminal screen.
# clear
·         Display the current local date and time
# date
·         Display a list of users currently logged in
# who
 ·         Tee utility is used to monitor a job and keep a log file at the same time
# | tee logfile.log
# | tee logfile.log | grep R_factor
Searching for FILES
·         Search 'expr' in this dir and below.
# find -name '*.[ch]' | xargs grep -E 'expr'
·         Search all regular files for 'home' in this dir and below
# find -type f -print0 | xargs -r0 grep -F 'home'
·         Search all regular files for 'example' in this dir
# find -maxdepth 1 -type f | xargs grep -F 'example'
·         Process each item with multiple commands
# find -maxdepth 1 -type d | while read dir; do echo $dir; echo cmd2; done
·         Find files not readable by all
# find -type f ! -perm -444
Text manipulation
·         Replace string1 with string2
# sed 's/string1/string2/g'
·         Modify anystring1 to anystring2
# sed 's/\(.*\)1/\12/g'
·         Remove comments and blank lines
#sed '/ *#/d; /^ *$/d'
·         Concatenate lines with trailing \
#sed ':a; /\\$/N; s/\\\n//; ta'
·         Remove trailing spaces from lines
#sed 's/[ \t]*$//'
·         Escape shell metacharacters active within double quotes
#sed 's/\([\\`\\"$\\\\]\)/\\\1/g'
·         Print 1000th line
#sed -n '1000p;1000q'
·         Print lines 10 to 20
#sed -n '10,20p;20q'
·         Case conversion
# echo 'Test' | tr '[:lower:]' '[:upper:]'
·         Filter non printable characters
# tr -dc '[:print:]' < /dev/urandom
·         Count lines
#grep 'processor' /proc/cpuinfo | wc -l
vi commands
Each command to be preceded by pressing the escape key!
' i ' insert mode.
<esc> 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.
'<shift> g ' 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.
' / ' to perform a search in the file.