Is there a way to get list of files created in current shell session? I can track user and timestamp, but is there a direct answer?

  • 3
    No, you can't. Unix generally does not keep track of file creation timestamps, and files are not associated with a shell session. Could you maybe specify a bit more carefully what you're attempting to achieve? The closest you would probably get is finding files that have been modified or have had their file meta information updated during the time since the shell session started. – Kusalananda Aug 9 '18 at 12:21
  • Well, I'd like to login to remote machine via ssh and run some scripts that produces some files, that are not needed after certain time. Unfortunately, scripts don't cleanup after themselves so I need to remove those files by myself (I cannot really modify scripts). – erhesto Aug 9 '18 at 12:24
  • Can you not just note down the files from the scripts and then create another script to remove the files at the end? – Raman Sailopal Aug 9 '18 at 12:43
  • Or just put all the created files in a directory and delete files by age (older than 14days in the following case) find /bar -type f -name *.foo -mtime +14 -delete. – Michael D. Aug 9 '18 at 12:48

If it's about cleaning up after scripts, at least make sure your scripts create their files in /tmp or some place where you can clean up easily.

If you really want to track all files, use strace -fefile ... to see all file operations. Note, this will slow down your scripts.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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