Tuesday, August 31, 2010

Unix File Descriptors

 Unix has 3  file descriptors:
  • 0 - Input
  • 1 - Output
  • 2 - Error
Every file descriptor is associated with a value. The above list shows the 3 file descriptors and their associated value. Before we see too much into this, let us go straight to see some examples.

Output File Descriptor:
#cat f1
I am an Indian,
And I love Unix.
 In the above example, the cat command displayed the contents of the file f1. The output of the cat command got displayed or got re-directed to the terminal which is the output file descriptor by default. To prove it, lets try this:

Monday, August 23, 2010

find files modified in the last X days and X hours and X mins

  find in Unix, as we know, is a command which nobody can live without. In this article, we are going to discuss only about finding the files with respect to the modification time, say files modified in the last X mins or Xhours. These can be done with the find command options available. However, in cases where the time is not a full hour, say to find files modified in the last 30hours, some Unix flavors do not have a direct option. Let us see in this article how to get these things done.

 The basic syntax of the find command is:

find path options
where path is the path to search
        and options are the options given to find command.

 In all our below examples, the path is our current directory and hence we use .(dot).

1. To find files modified in the last 5 days:
find . -mtime -5