Anda di halaman 1dari 5

Working in UNIX / LINUX environment

Brief introduction

Starting session
(activate putty on your window desktop . Give server address)
login <- enter your login name (case sensitive)
password <- enter password (case sensitive) , nothing will display , if wrong entry press enter till login
prompt appears (back space key may work to delete entered chars.)
Once you log in, the system may displays some information about the system . The command prompt
may appears as a dollar sign ($) . Now you are inyour home directory.
to finish session -type exit or logout at command prompt. (or Ctrl+D)
shell is command interpreter . Commands are gateway to OS. Here only Bash shell is covered .
(other shell are C shell(csh), tc shell(tcsh), Z shell (zsh), k shell etc).
The eight most important shell commands in UNIX are:
ls
lists file names. (can use dir also)
cat
displays the contents of files
cp
copies files
mv
renames and moves files
rm
deletes files
chmod
grants and revokes access to files
mkdir
creates subdirectories
rmdir
removes subdirectories
many commands uses hyphen (-) to indicate options, or switches that say how a command should
operate.
when you type a wrong command name it give message-looked for a program called x and couldn't
find it. Many of the switches can be given with single -. there should be space between command and
hyphen and parameters.
If you do not provide complete (required)/wrong parameter with command the system displays the
Usage of the command or error message.
Online help is available for commands. You can use info and man. format is
man commandname
info commandname
(to come out , back to shell, of man or info back to prompt press q .)
File naming- any combination of alphanumeric except <, >, |, -, ?, [, ], and *. Names are case sensitive.
first character if . means a hidden file (name will be displayed by ls only with specific option).
You can use wild card (* (for many characters and ? For one character) in filename when listing.
ls my* ;
ls *6* ;
ls ??test* ; ls my*6 ; for file name mytestfile68
if file name has a space then it is accessed using for example my file
file organization based on nested directory structure
main directory is called root /
;subdirectories are separated by /
following are subdirectories of root(/) in linux
bin
boot dev etc
home lib
lost+found
media misc mnt net opt
root sbin sys
tmp usr
var
Important directories in file structure

proc

/ - root of filesystem
/bin essential command binaries- files needed to boot and run time (common programme)
/sbin- essential system binaries used in system administration (root)
/boot files related to boot loader (kernel )
/etc system configuration files
/dev files related to peripheral devices
/home- user's home directory is one of the subdirectory of home
/lib shared libraries files
/mnt mount point of temporary partition or removable storage
/opt - Option installed programs
/proc- contains kernel and process information files (processor pseudo files)
/root home directory of root (super user)
/tmp temporary files of programmes
/usr files and programmes used by system and all users
/var- files whose contents varies as the system runs (changing files)
/usr/doc- documents
/usr/bin- more shared programmes
/usr/lib - Specialize libraries
/usr/man online manual
/usr/src- kernel source code
/usr/include- header files of c programmes
/mnt/cdrom - Cd-ROM drive
/mnt/floppy - Floppy drive
/cdrom - Same as mnt/cdrom
/dev/null - Null device
/dev/tty - Current display device
/home/uos10/ - your home directory folder
pathname tells the location of a file or subdirectory starting from / (root)
path name can be absolute or relative. Absolute complete path from root to file/subdirectory is written.
In relative path ../ or subdirectoryname is used to move parent or child subdirectory in command
parameters (relative path never starts with /)
format of command
command [option] [source] [destination]
(source / destination objects can be given with absolute/relative path)
When files of directory is listed it gives information about files
first field is access right
d rwxrwxrwx
or
- rwxrwxrwx
or
l rwxrwxrwx
or
p rwxrwxrwx
the first character tells
whether it a subdirectory or a file or some special file
if first character is - it is a normal file , if d it is subdirectory else other special files
remaining nine characters give the right of the file
r right to read(read or copy);
w right to write(edit);
x right to execute(if programme)
these rights are for owner (creator) , owner's group and others (from left to right order)
if any of these nine field is it means that right is not available to individual (owner, group, other)
directory has different meaning for access rights
r right to read(list the files in);
w right to write(create files in);
x right to execute cd
command to change into that directory

with chmod access right can be modified as per permission.


the permission right of a file can be changed by
chmod [ugo] +/-rwx filename or directory name
u owner ; g group ; o others; + add delete rwx file rights
chown is used to change owner and/or group of a file or directory
chown root.g3 filename : change the owner and group to root and g2 respectively
Simple text file can be created with cat command.
Type cat > filename to be created at prompt
(system is ready to get characters from keyboard)
type your text
in last line press Ctrl+D
file is created by given name
using ls or cat command file can be listed or displayed respectively.
long file can be displayed on screen one screenful at a time using pipe (symbol is |) more
cat filename | more
Press the space bar (or, if you piped your output to pg, the Enter key) and another screenful appears, if
you want to quit, type "q" instead of pressing the space bar.
pwd gives the absolute path of present working directory
if you are at other than your home directory use cd ~ to return to your home directory (tilde)
current directory is identified as . and its parent directory as ..
When you refer to a file without its directory location, UNIX assumes that it's in the current directory.
copy / remove file ; directory (with -r option)
format of cp , mv cp source destination
rm source
mv source destination (it also works like rename)
source / destination can be same or different directory
tree - gives the nested directory structure.
Kill- terminate a process (by id)
killall- terminate all processes (by name)
uname -a gives information of OS
date display time and date
finger- information of user(s)
who- information of user(s)
cd - change directory to given path (absolute or relative), ~ home, .. parent
ls -List the contents of current or any directory (give absolute or relative path)
(-a, -A, -l, -R,-r,-d,-t,-i -F,-X)
mkdir - make directory in current or at any directory (give absolute or relative path) (-p)
rmdir - remove ditectory in current or at any directory (give absolute or relative path)
mv - move file/direcory to destination (rename is source/destination is same) (-b,-f,-i,-u)
cp - copy file/direcory to destination (-b,-i,-p,-r)
rm - remove file/direcory to destination (-i,-f,-r)
cat - joins two or more files or display files
cat file1 file2 file3 > file4 :(concatenate > or >> append)files in that order
find -locate a file/directory based on expression
echo - display on screen/file

echo a test sentence > filename : puts a test sentence in filename


echo a test sentence >> filename : appends a test sentence in filename
which commnand-name : shows the full path of the command-name (whereis cmd)
touch filename- create (up date time of existing) filename
ln links existing filename to symbolicname: hard link (softlink with option -s) : creates soft/hard link
of a file
df - list mounted directories, its size and free space
du - list size of files in pwd and its subdirectories (-a)
free - list memory usage, free space
ps - list process in system (-a,-m,-u,-e,-l,-f , -)
grep -(general regular expression print) : displays line containing expression in or more files
head - display first ten lines of a file
tail - display last ten lines of a file
sort - sorts a file in order (ASCII) by lines
uniq - display by skipping adjacent duplicate lines
diff - compare two files (file1 file2) and displays a list of differences between them.
(It display the line to be added (a), deleted (d) or changed (c) with line number of file1 then file2; usese
< for file1 and > for file2 (add , delete or chnage to make identical files))
split - Split a file into pieces
join - Joins two tabular files
file - gives type of file
sum - Compute checksum of files
history - display past commands (past command can be access using up arrow key)
more - displays the file file-n one page at a time (press space for next)
less - similar but more powerful than more command
sort - sort and/or merge files (sort the lines of a file, o option output file and m merge files)
(-r,-f,-i,-n,-c,-m,-u,-o) +column-number as sort rule (multi pass sort in one command )
clear - clear screen
man manual that displays the contents of a system command
passwd - change user password
exit - exit the current shell (logout or ctrl+d )
redirection symbols
(<
Redirect input; >
Redirect output; >>
Concatenate output to file; |
cmd1 | cmd2 : output of cmd1 to cmd2
cmd1 > filename : output of cmd1 to file name (existing filename overwritten)
cmd1 >> filename : output of cmd1 to file name (existing filename appended with)
filename < cmd1 : input for cmd1 from filename
*
Wildcard for character(s)
?
Wildcard for single character
[charset] Wildcard for character in charset
[^charset ] Wildcard for not the characters in the charset
[!charset ] Wildcard for not the characters in the charset
CTRL C terminates command
CTRL \ more powerful than Control-C
CTRL Z suspends program execution
complition
gcc
GNU C compiler

pipe )

g++
g77

GNU C++ compiler


GNU Fortran 77 compiler

to run more than one commands in serial order use semicolon - cmd1 ; cmd2 ;.....cmd n
compress / archieve
tar -tvzf mytarball.tgz : show table of contents(t)of gzipped(z) tarball with filename(f) mytarball.tgz
tar -xzf tarball.tgz :untar (extract x) contents of gzipped(z) tarball tarball.tgz
tar -cz mydir f mytarball.tgz :create(c) a tarball mytarball.tgz from directory mydir
gzip filen : compress the file filen using GNUzip (-v,)
gunzip filen.gz : unzip the file filen.gz(compress with GNUzip)
zcat : displays the compressed file as it were compressed
disk mounting/partition commands
mount to mounte filesystems
mount -t msdos /dev/fd0 /mnt/floppy
mount -t iso9660 /dev/cdrom /mnt/cdrom
mount ro -t vfat /dev/sda1 /mnt/windows ( Windows partition on sda1)
( directory must already exists in /mnt before mounting)
umount
Unmount a file system
fdisk disk partition table (old type , for new type GPT use different command)

Anda mungkin juga menyukai