Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Given a shell script, is there an easy way to extract what files it manipulates explicitly (so not like concatenating some command and than eval-ing it)? E.g.


. /etc/someconfig.cfg

    cat /somedir/somefile.txt

    cp /otherdir/file1.txt /tmp/fileABC.txt

    rm -f ~/stupidfile.txt


Is there a command that would extract the explicit dependencies so that I don't have to parse the script or do it manually and get output like:




share|improve this question
It's not possible in general to examine source code in a reasonably powerful programming language and deduce what external resources it will attempt to use if it is run. – Celada Dec 26 '12 at 22:02
OK. i thought there could be a shell interpreter option to extract script metadata dependencies – amphibient Dec 26 '12 at 22:04

Parsing the program is a reasonable approach to solve this (especially in an interpreted language).

If you have a static script without branches, you could do an strace -e open -f for the script to see which files it does open.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.