Monday, March 26, 2012

Basic Unix Commands --- Part1

Basic Unix Commands:

Unix Architecture:

                   1. Kernel
                   2. Shell
                   3. Directory Structures

Important Unix File Systems:

/ -- root
/bin
/sbin
/etc
/home
/tmp
/var
/opt
/mnt
/proc
/boot
/usr

Basic command syntax:

   command [-options] [arguments];

 Some Basic commands:

To list the date and time of the server

date

To list the calendar:

cal
cal 2011
cal 9 2012

To change the time stamp of a existing file:

 touch filename
If the file does not exist then it will create a empty file.

To see the help pages:

man command
man ls
man date
man cal

FILE NAVIGATION COMMANDS:

Parent directory(..)
Current Directory (.)
Home Directory (~)
Previous Working Directory (-)

Absolute Path  --- Any path starts from / ex: cd /opt/dest1
Relative Path   ---- ex: cd dir2

To change the directory:
cd 
cd .
cd ..
cd ~
cd -
cd  /opt/dir1/d2


To Create a new empty directory:

mkdir dirname
mkdir dir1
mkdir -p dir1/dir2/dir3
mkdir /tmp/d1
mkdir -m 777 dir3

To remove an empty directory:

rmdir dirname

rmdir dir2
rmdir -p /dir1/dir2/dir3


Copy a file:

cp source destination

cp file1 file2
cp file1 /tmp/file3
cp file1 file2 file3 dir1 ---- If you copy multiple files then destination must be a directory.
cp -i f1 f2 ---- Interactive Mode
cp -r dir1 dir2  -- Copy a directory

cp /home/senthil/f1  /tmp/f3


Removing a File:

rm filename

rm f1
rm -i f3   ---- Interactive Mode
rm f2 f3 f4  ----Remove  Multiple files
rm -rf dir1  --- Removing a whole directory (Very Dangerous command)  


Renaming a File:

mv source destination

mv f1 f3
mv -i f3 f4  -------- Interactive Mode
mv f3 f4 f5 dir1 ----------------- Moving multiple files to another location
mv /home/senthil/f1  /tmp  ---- Cut & Paste
mv /home/senthil/f3  /tmp/f4 --- Cut & Paste & Rename




File Access Permission:


User  
group
others

read (4)
write(2)
execute(1)

umask  is set the default privilege to the new file and new directory.

default umask value is 0022

The new file privilege is 0644. (0666 - 0022)
The new directory privilege is 0755. (0777 - 0022)

To change the file access privilege then use the chmod command:

chmod 777 file1
chmod g+w file1
chmod -R 777 /dir1
chmod 666 file1


To change the group:

chgrp gname  fname

chgrp team2 f2
chgrp team3 f3


To change the owner of the file then use the chown command:

chown user filename

chown senthil f2
chown senthil:g2 f4


Continuation  on Basic Unix commands -- Part2


























1 comment: