JAVA SCRIPT

RH033 14. LINUX-FILE-SYSTEM



Inode num is unique num given to file, we identify files by filename but harddisk identify files by sequential uniq num called inode lets observer what happnes to inode whne we copy/remove/move file

cp file1 file2 -->copy file1 file2
ls -li file1 file2 -->inode nums r diff,so file1 file2 occupies
seperate space in hard-disk
mv file1 file2 -->move file1 file2
ls -li file1 file2 -->inode num of file1 is given to file2
file1 no more exist
rm file2 -->remove file
ls -li file2 -->inode of file2 gets vacant,next time you creat
file inode of file2 is given to that.


LINKING FILE

when you copy a source to destination, contents of both are same, later you update source or destination, other file wotn get updated, so linkign file helps to update the file even if contents are added to file after linking.


1. Hard link

ln file1 file2      //hard link file1 file2
ll -i file1 file2    //observe inode/filesize

a. Inode nums are same
b. Size of file is same
c. If source is deleted data can be accessed from destination
d. Only files can be linked dir cant

2. Soft link

ln -s file1 file2 //soft link file1 file2
ll -i file1 file2 //observe inode/filesize

a. Inode nums are diff
b. Size of file is diff
c. If source is deleted data is lost
d. Even dir can be linked.


3. df -h   
Shows current systems partion,n used and free space mount.
Shows List of partions and which dir it is mounted fdisk -l  Also shows system partitions


du -h <file/dir> =Shows size occupied by the file/dir


4. eject    //opens cd tray put cd then
eject -t    //Close cd tray, thn to acces cd contents

To access contents of cd 

mount /dev/cdrom /media  
 (mounts contents of cd to /media dir)

cd /media   (Change dir to /media)

cp OR ls   (list contents or copy contents of cd)

cd [and press enter]  (Takes you out of /media dir)

umount /media  (Unmount /media dir before removing cd)

To access contents of pendrive or any external device

fdisk -l   (At end shows u device identity)

OUTPUT OF fdisk -l looks like this

[root@server1 ~]# fdisk -l

Disk /dev/hda: 80.0 GB, 80026361856 bytes
255 heads, 63 sectors/track, 9729 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/hda1 * 1 2 16033+ 83 Linux
/dev/hda2 3 1177 9438187+ 83 Linux
/dev/hda3 1178 1488 2498107+ 83 Linux
/dev/hda4 1489 9729 66195832+ 5 Extended
/dev/hda5 1489 1814 2618563+ 83 Linux
/dev/hda6 1815 1945 1052226 83 Linux
/dev/hda7 1946 2199 2040223+ 82 Linux swap / Solaris
/dev/hda8 2200 2215 128488+ 83 Linux
Note: sector size is 4096 (not 512)

Disk /dev/sda: 79.8 GB, 79824777216 bytes
26 heads, 50 sectors/track, 14991 cylinders
Units = cylinders of 1300 * 4096 = 5324800 bytes

Device Boot Start End Blocks Id System
/dev/sda1 1 14992 77953628 b W95 FAT32

------>> Here /dev/hda1 to /dev/hda8 are system partitions
and /dev/sda1 is external device identity

SO TO ACCESS CONTENTS OF EXTERNAL DEVICE

mount /dev/sda1 /mnt //Here identity of usb is sda1,and mounting to /mnt

cd /mnt //Change dir to /mnt
cp OR ls //list contents or copy contents of usb
cd [and press enter] //Takes you out of /mnt dir
umount /mnt //Unmount /mnt dir before removing usb



TO TAKE BACKUP USING TAR COMMAND

tar -cvf dump file1 file2 file3 //Take backup of file1,2,3 and store under
dump dir
tar -tvf dump //List all files backed up under dump dir

tar -xvf dump //Restore all contents of dump to pwd


where c->create v->verbose f->file t->list x->extract


TO COMPRESS FILE (2 utilities)

1. gzip file //compress file
gunzip file.gz //once file compressed .gz extension added so file.gz


2. bzip2 file //compress file
bunzip2 file.bz2 //once file compressed .bz2 extension added so file.gz


Before compressing and after compressing observer file size by giving ls -lh and observe file-size




If you found this post useful, I would really love it, if you can Like the Page, or share it with your Facebook/Google+/Twitter Friends... It will keep me motivated. Thank you!

No comments:

Post a Comment