Oracle Consulting and Training
Home Tutorials Case Studies Training Consulting Subscribe to ezine Contact Us About Us Legal Notices
For Better, Faster, Smarter

An Introduction To The UNIX® File System

This introduction to the UNIX file system looks at the structure of the file system as a whole, how to navigate around the file system and the structure of files. All of which topics are essential if you want to learn about UNIX and how it works.

UNIX File System Hierarchy

Unlike Windows the UNIX file system is hierarchical and there is no concept of drives or devices from a user’s point of view. Instead the file system is organised as a logical tree structure with every directory being a child of the root directory (designated by ‘/’). / bin   dev   etc  lib  home  tmp  var  lost+found   proc   dev    boot                   john        chris      siobhan     bin         src        util The mapping from physical to logical is maintained by the system in the file /etc/fstab which can be read. A directory can be referenced by an absolute path (starting from root) or by a relative path from the current directory. For example: ls /home/john/src uses the absolute path and ls ../john/src uses a relative path and would reference the same directory (or file) if your current directory were /home/chris or /home/siobhan  The current directory is denoted by ‘.’ and its immediate parent by ‘..’. You can chain these shortcuts together to access any directory or file within the tree from any where else in the tree. For example to list the contents of the grandparent directory the (short version of the) command is ls ../.. and to list the contents of the great grandparent directory the (short version of the) command is ls ../../.. . From that point (or any other point) you can go down the tree again. As this can result in quite complex paths, fortunately, you can also use the absolute path instead to save having to work out how many levels up and down you need to go.

Navigating the UNIX file system

The concept of absolute and relative paths are independent of any command and either mode can therefore be used with any command that takes a file or directory name as a parameter such as the cd (change directory) command which is used to move from one directory to another (i.e. change the working directory). $ cd /home/john/src uses an absolute path to change the current directory $ cd ../../john/src would be the equivalent command starting from (for example) /home/chris/src If you lose track of where you are in the file system, the command pwd (print working directory) shows the absolute path to your current directory eg. /home/john/src. Creating a directory is achieved by use of the mkdir command, $ mkdir /home/john/src/java  - uses the absolute path to create a new directory called java $ mkdir plsql - uses the relative path to create a new directory called plsql in your current directory Each user has a default working directory - their home directory. After login this auotmatically becomes your current directory and you can return to it by issung the command cd without any parameters. $ cd  - return to your default (home) directory

Structure of Files

Everything in UNIX is a file! Of course there are different types of files - binary files, text files, directories - but no structure is imposed on files by the operating system and no meaning is attached to the contents of files except by the programs reading them. Other than executables and compiled (object) code files, all files are just text. This is the case for files on disk, files on tape, pipes, keyboard input, etc. Each file is just a series of bytes as far as the operating system is concerned. For example, assume we have a file called midsummer in our directory containing an excerpt from Shakespeare’s “A Midsummer Night’s Dream”. We can print out the text with cat. $ cat midsummer Asleep, my love? What, dead my dove? O Pyramis, arise! And we can use to produce an octal dump of the file (or use od -x for a hexadecimal dump). $ od -c midsummer 0000000    A  s  l  e  e  p  ,     m  y     l  o  v  e  ? 0000020   \n  W  h  a  t  ,     d  e  a  d  ,     m  y    0000040    d  o  v  e  ? \n  O     P  y  r  a  m  u  s  , 0000060       a  r  i  s  e  ! \n  The “- c” option displays the characters as well as the octal dump. The numbers on the left represent the position (in octal) of the next character in the file. It is important to note that only the newline (line feed) character (represented by “\n”) is stored in files. The carriage return character - generated along with line feed when you press the RETURN or ENTER keys on the keyboard - is not stored but is added when the file is printed (whether to the screen or anywhere else). There is also no end of file marker - when inputting data, ctl-d signals the end of the data but this is not stored, files just end  and the kernel keeps track of the file length. This keeps the file structure simple, so programs have the complexity of file handling,  and enables program output to be directed to a file on disk, to the screen or piped to another program. 

File Permissions

All files (including directories) in UNIX have three sets of permissions: those of the u(ser), (people in the same) g(roup) and o(thers). Each set has three individual permissions: r(ead), w(rite) and (e)x(ecute). File permissions are shown with the long (verbose) option of ls. $ ls -l midsummer -rw-r--r--. 1 john poets 128 Nov 18 23:52 midsummer File permissions are always shown in the order owner, group, world starting from the left. In the listing shown above, the user/owner (john) has read and write privileges, people in the same group can read the file and evertone else also has read access. The first “-” indicates that the file is not a directory. If it were, there would be a ‘d’ there instead. The command chmod is used to change permissions and accepts new permissions either as an octal number or symbolically and the set of permissions can be either modified or replaced completely with a new set. The command $ chmod 777 midsummer replaces the existing set of privileges and gives read, write and execute privileges to everyone. $ chmod g-w midsummer removes write privilege from members of the same group. Other options can be found in the UNIX manual. Follow this link for the introductory tutorial.  --------------------------------------- Looking to sky-rocket productivity, save time and reduce costs? Training is a highly cost-effective and proven method of boosting productivity. Smartsoft offers instructor-led training in UNIX/Linux and related technologies on or off site in cities across the UK as well as self-study online training. See our scheduled UNIX training courses, or let us know your requirements. Oracle tips and tricks Subscribe to our newsletter, jam-packed full of tips and tricks to help you slash costs, sky-rocket productivity and make your systems better, faster and smarter. © Smartsoft Computing Ltd, Bristol, England Need help? Contact Us This site uses woopra.com to gather statistical information about our visitors. This data is aggregated to show industry trends (such as browser share). However, this data shall be the average of many thousands of visits and is in no way linked to individuals. View woopra privacy policy.     View Smartsoft privacy policy Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.
Bookmark and Share
Site Menu
For Better, Faster, Smarter Oracle Consulting and Training

An Introduction To The UNIX® File

System

This introduction to the UNIX file system looks at the structure of the file system as a whole, how to navigate around the file system and the structure of files. All of which topics are essential if you want to learn about UNIX and how it works.

UNIX File System

Hierarchy

Unlike Windows the UNIX file system is hierarchical and there is no concept of drives or devices from a user’s point of view. Instead the file system is organised as a logical tree structure with every directory being a child of the root directory (designated by ‘/’). / bin   dev   etc  lib  home  tmp  var  lost+found   proc   dev    boot                   john        chris      siobhan     bin         src        util The mapping from physical to logical is maintained by the system in the file /etc/fstab which can be read. A directory can be referenced by an absolute path (starting from root) or by a relative path from the current directory. For example: ls /home/john/src uses the absolute path and ls ../john/src  uses a relative path and would reference the same directory (or file) if your current directory were /home/chris or /home/siobhan  The current directory is denoted by ‘.’ and its immediate parent by ‘..’. You can chain these shortcuts together to access any directory or file within the tree from any where else in the tree. For example to list the contents of the grandparent directory the (short version of the) command is ls ../.. and to list the contents of the great grandparent directory the (short version of the) command is ls ../../.. . From that point (or any other point) you can go down the tree again. As this can result in quite complex paths, fortunately, you can also use the absolute path instead to save having to work out how many levels up and down you need to go.

Navigating the UNIX file system

The concept of absolute and relative paths are independent of any command and either mode can therefore be used with any command that takes a file or directory name as a parameter such as the cd (change directory) command which is used to move from one directory to another (i.e. change the working directory). $ cd /home/john/src uses an absolute path to change the current directory $ cd ../../john/src would be the equivalent command starting from (for example) /home/chris/src If you lose track of where you are in the file system, the command pwd  (print working directory) shows the absolute path to your current directory eg. /home/john/src. Creating a directory is achieved by use of the mkdir command, $ mkdir /home/john/src/java  - uses the absolute path to create a new directory called java $ mkdir plsql - uses the relative path to create a new directory called plsql in your current directory Each user has a default working directory - their home directory. After login this auotmatically becomes your current directory and you can return to it by issung the command cd without any parameters. $ cd  - return to your default (home) directory

Structure of Files

Everything in UNIX is a file! Of course there are different types of files - binary files, text files, directories - but no structure is imposed on files by the operating system and no meaning is attached to the contents of files except by the programs reading them. Other than executables and compiled (object) code files, all files are just text. This is the case for files on disk, files on tape, pipes, keyboard input, etc. Each file is just a series of bytes as far as the operating system is concerned. For example, assume we have a file called midsummer in our directory containing an excerpt from Shakespeare’s “A Midsummer Night’s Dream”. We can print out the text with cat. $ cat midsummer Asleep, my love? What, dead my dove? O Pyramis, arise! And we can use to produce an octal dump of the file (or use od -x for a hexadecimal dump). $ od -c midsummer 0000000    A  s  l  e  e  p  ,     m  y     l  o  v  e  ? 0000020   \n  W  h  a  t  ,     d  e  a  d  ,     m  y    0000040    d  o  v  e  ? \n  O     P  y  r  a  m  u  s  , 0000060       a  r  i  s  e  ! \n  The “- c” option displays the characters as well as the octal dump. The numbers on the left represent the position (in octal) of the next character in the file. It is important to note that only the newline (line feed) character (represented by “\n”) is stored in files. The carriage return character - generated along with line feed when you press the RETURN or ENTER keys on the keyboard - is not stored but is added when the file is printed (whether to the screen or anywhere else). There is also no end of file marker - when inputting data, ctl-d signals the end of the data but this is not stored, files just end  and the kernel keeps track of the file length. This keeps the file structure simple, so programs have the complexity of file handling,  and enables program output to be directed to a file on disk, to the screen or piped to another program. 

File Permissions

All files (including directories) in UNIX have three sets of permissions: those of the u(ser), (people in the same) g(roup) and o(thers). Each set has three individual permissions: r(ead), w(rite) and (e)x(ecute). File permissions are shown with the long (verbose) option of ls. $ ls -l midsummer -rw-r--r--. 1 john poets 128 Nov 18 23:52 midsummer File permissions are always shown in the order owner, group, world starting from the left. In the listing shown above, the user/owner (john) has read and write privileges, people in the same group can read the file and evertone else also has read access. The first “-” indicates that the file is not a directory. If it were, there would be a ‘d’ there instead. The command chmod is used to change permissions and accepts new permissions either as an octal number or symbolically and the set of permissions can be either modified or replaced completely with a new set. The command $ chmod 777 midsummer replaces the existing set of privileges and gives read, write and execute privileges to everyone. $ chmod g-w midsummer removes write privilege from members of the same group. Other options can be found in the UNIX manual. Follow this link for the introductory tutorial.  --------------------------------------- Looking to sky-rocket productivity, save time and reduce costs? Training is a highly cost-effective and proven method of boosting productivity. Smartsoft offers instructor-led training in UNIX/Linux and related technologies on or off site in cities across the UK as well as self-study online training. See our scheduled UNIX training courses, or let us know your requirements. Oracle tips and tricks Subscribe to our newsletter, jam-packed full of tips and tricks to help you slash costs, sky-rocket productivity and make your systems better, faster and smarter. © Smartsoft Computing Ltd, Bristol, England Need help? Contact Us This site uses woopra.com to gather statistical information about our visitors. This data is aggregated to show industry trends (such as browser share). However, this data shall be the average of many thousands of visits and is in no way linked to individuals. View woopra privacy policy.     View Smartsoft privacy policy Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.
Bookmark and Share