Linux Inode


What is Inode?

Inode is abbreviated as Index Node. As we know in Linux, whatever is there is a file. So, in order to maintain a consistency by treating everything as a file (even the hardware devices). The monitor, hard disk, printer, mouse, keyboard or directories are also treated as files in Linux. The regular files contain data such as text files, music files (mp3, mp4, audio etc.), video (multimedia files ) etc. Keeping aside the regular data, there is some other data about these files such as their size, ownership, permissions, time stamp etc. This meta data about a file is managed with a data structure known as Inode.

Where is Inode stored?

In Linux, file is stored in two different parts of a disk – the data blocks and the Inodes. The data block contains contents of a file. All other information about the file is stored in Inode.

Example1 : Rename a directory dir1 to Directory_1 which is in your current path

Syntax:

Kindly note that Inode number of dir1 will be same as Directory_1. In order to view properties of a directory, use ls –d  command.

Example2 : Prompt for confirmation before overwriting Examine.txt in /tmp directory

Syntax:

This is used while we are taking a backup so that updated file is stored and kept for use.

The input required during the prompted confirmation is:

  • For yes : YES, Y, yes, y
  • For no : NO, N, no, n

When the destination file permission is different than source file, mv –i  command will display the confirmation in following way:

Example3 :Move multiple files in specific directory. ( Let’s say  we have Linux_Lect1, Linux_lect2 and we need to move it to Linux_tuts directory). We have both Linux_lect1, Linux_lect2 in my current path:

Syntax:

Example4 : Take a backup of Destination file “Examine“ before overwriting a file:

Using a mv command  with – – suffix  option we can take a backup of destination file before overwriting .  The destination file will be moved with the specified extension:

–S

or

–suffix option.

Syntax:

Backup for Examine file is taken and changed to Examine.doc

Example5 : Suppose there are 10 files in directory d1 and we have copied any 8 files in directory d2. Now, we need to copy rest of the 2 files in directory d2.

Syntax:

-u option will perform update only if the source is newer than destination file






Leave a Reply