Use Unix truss command to monitor all operations and activity on a file

Posted on 2004-11-02
Last Modified: 2013-12-26
Hi Guys,
Can someone please give me an example of how to use the truss command to monitor all operations on a particular file.

I know there is an -r switch and reference to a file descriptor - but sure if this is simply a name of a file which you have to pass in or something different


 B Cunney

Question by:Barry Cunney
    LVL 14

    Accepted Solution

    A file descriptor is an integer that represents the file information in the kernel.

    By convention, 0 is stdin, 1 is stdout, and 2 is stderr, so '-r 0' would mean monitoring reads to stdout.

    If a program opens a fixed set of files, you can run truss against it to figure out what file descriptor ends up going to which file (by looking at the return value of the 'open' call).

    If it opens different files based on user input, you'll proobably have to monitor all file descriptors since you won't know in advance which one goes with the file name you're interested in.
    LVL 17

    Author Comment

    by:Barry Cunney
    Cheers chris,
    I thought that there might be some trick one could use to get the truss command just to trace operations on one file
    LVL 14

    Expert Comment

    You could probably write a perl script that monitors the output of truss and figures out which lines refer to a file of a particular name...

    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    Join & Write a Comment

    Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
    Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
    This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now