In this post we would concentrate on the following Unix File system commands.
2nd field indicates number of hard links
3rd fiels indicatesowner of the file
4th field indicates the size of the file
5th field indicates the modification time
6th and the last field indicates the file name
2.CAT:- gives the content of the file.
>cat filename
3.CD:- change directory
>cd /tmp/unix/dir1
4.MKDIR:- make directory
>mkdir dir2
5.RMDIR:- remove directory
- LS
- CAT
- CD
- MKDIR
- RMDIR
- TOUCH
- DF
- DU
- PWD
- Hard link and Soft link
- Command to displaty the hidden files in unix?(Asked in many interview Questions)
- Command to display all the files recursively in a directory?
>ls - R
- Command to display the long listing of all the files?(Asked in many interview Questions)
>ls -lt
where l=long listing
t=sort files according to modification time.
brw-r--r-- 1 unixguy staff 64, 64 Jan 27 05:52 block
crw-r--r-- 1 unixguy staff 64, 255 Jan 26 13:57 character
-rw-r--r-- 1 unixguy staff 290 Jan 26 14:08 compressed.gz
-rw-r--r-- 1 unixguy staff 331836 Jan 26 14:06 data.ppm
drwxrwxr-x 2 unixguy staff 48 Jan 26 11:28 directory
-rwxrwxr-x 1 unixguy staff 29 Jan 26 14:03 executable
prw-r--r-- 1 unixguy staff 0 Jan 26 11:50 fifo
srw-rw-rw- 1 unixguy staff 0 Jan 26 12:00 socket
lrwxrwxrwx 1 unixguy staff 3 Jan 26 11:44 link -> dir
-rw-rw---- 1 unixguy staff 217 Jan 26 14:08 regularfile
where 1st field indicates file permission2nd field indicates number of hard links
3rd fiels indicatesowner of the file
4th field indicates the size of the file
5th field indicates the modification time
6th and the last field indicates the file name
2.CAT:- gives the content of the file.
>cat filename
3.CD:- change directory
>cd /tmp/unix/dir1
4.MKDIR:- make directory
>mkdir dir2
5.RMDIR:- remove directory
- Command to delete a directory and all the contents inside it?Directory has many sub directories?(Asked in many interview Questions)
>rmdir -R /tmp/unix/dir1
6.TOUCH:-used to create a zero byte file
>touch filename
7.DF( Disk free space):- Displays the amount of available freespace for filesystem.
df -k
where k=shows file size in 1024 bytes instead of 512 bytes
> df -k
Filesystem 1024-blocks Free %Used Iused %Iused Mounted on
/dev/hd4 32768 16016 52% 2271 14% /
/dev/hd2 4587520 1889420 59% 37791 4% /usr
/dev/hd9var 65536 12032 82% 518 4% /var
/dev/hd3 819200 637832 23% 1829 1% /tmp
/dev/hd1 524288 395848 25% 421 1% /home
/proc - - - - - /proc
/dev/hd10opt 65536 26004 61% 654 4% /opt
8.DU(Disk Usage):-Gives the filespace usage
>du -sk
where k=shows file size in 1024 bytes instead of 512 bytes
s= report only the sum of the usage in the current directory, not for each file
132456 Dir1
178645 Dir2
9.Hard link and Soft link (Asked in many interview Questions)
Firstly what is a link in Unix?
A link in UNIX is a pointer to a file. Like pointers in C , links in UNIX are pointers pointing to a file.
> cat file1
Unix
Creating Hard link:- ln file1 file2
Creating Soft link:- ln -s file1 file 3
After links are created
>cat file 2
Unix
>cat file 3
Unix
How to list the link files ?
$ ls -li
total 20
9962464 -rw-r--r-- 2 guru users 8 Mar 9 file1
9962464 -rw-r--r-- 2 guru users 8 Mar 9 file2
9962471 lrwxrwxrwx 1 guru users 5 Mar 9 file3 -> file1
If you see the idone number 9962464 is same for both the original file and the hard link file.The number of links are also mentioned as two.
Where as for the soft link file -> indicates its a soft link to the original file file1.
The size of the soft link is the length of the filename of the original file.The original file is "file1" length of 5 hence the size of soft link is 5.
If the original file i.e file1 is deleted the soft link i.e file3 would not be accessible but the hard link file2 would be accessible.
where k=shows file size in 1024 bytes instead of 512 bytes
> df -k
Filesystem 1024-blocks Free %Used Iused %Iused Mounted on
/dev/hd4 32768 16016 52% 2271 14% /
/dev/hd2 4587520 1889420 59% 37791 4% /usr
/dev/hd9var 65536 12032 82% 518 4% /var
/dev/hd3 819200 637832 23% 1829 1% /tmp
/dev/hd1 524288 395848 25% 421 1% /home
/proc - - - - - /proc
/dev/hd10opt 65536 26004 61% 654 4% /opt
8.DU(Disk Usage):-Gives the filespace usage
>du -sk
where k=shows file size in 1024 bytes instead of 512 bytes
s= report only the sum of the usage in the current directory, not for each file
132456 Dir1
178645 Dir2
9.Hard link and Soft link (Asked in many interview Questions)
Firstly what is a link in Unix?
A link in UNIX is a pointer to a file. Like pointers in C , links in UNIX are pointers pointing to a file.
> cat file1
Unix
Creating Hard link:- ln file1 file2
Creating Soft link:- ln -s file1 file 3
After links are created
>cat file 2
Unix
>cat file 3
Unix
How to list the link files ?
$ ls -li
total 20
9962464 -rw-r--r-- 2 guru users 8 Mar 9 file1
9962464 -rw-r--r-- 2 guru users 8 Mar 9 file2
9962471 lrwxrwxrwx 1 guru users 5 Mar 9 file3 -> file1
If you see the idone number 9962464 is same for both the original file and the hard link file.The number of links are also mentioned as two.
Where as for the soft link file -> indicates its a soft link to the original file file1.
The size of the soft link is the length of the filename of the original file.The original file is "file1" length of 5 hence the size of soft link is 5.
If the original file i.e file1 is deleted the soft link i.e file3 would not be accessible but the hard link file2 would be accessible.
No comments:
Post a Comment