I writing script to list the following details of all the files inside a folder or directory which the user gives as input

File Name
Absolute Path 
Created Date
Modified Date
Accessed Date
Version of the file

From the above details I was able get all except the version details.

So when it comes to version of files or content inside a directory which user gives as input following aspects has to be taken care to my knowledge (let me know if I am missing any points)

  1. I initailly thought to get the owner name and if it is root then to consider it as an commands but later realized that there may be some normal files with root as owner.
  2. Need to differentiate between a normal file(.txt,.sh,.conf etc) and a command (ls,grep,echo etc).
  3. And capture the version details of the command since the version place holders keep changing for different commands


$ vi --version
VIM - Vi IMproved 7.4 (2013 Aug 10, compiled Mar 31 2015 11:13:18)

$ sync --version
sync (coreutils) 8.4

$ unlink --version
unlink (GNU coreutils) 8.4

$ sleep --version
  version         sleep (AT&T Research) 2009-03-12

  $ umount --version
umount (util-linux-ng 2.17.2)
  • 3
    Getting the version of an executable can not be done in a generic way as some utilities use other flags (-v/-V) and some simply don't provide version information. – Kusalananda Feb 15 '17 at 10:05
  • On many Linux filesystems there is no "created date", only "modified date". Also, you may find that "accessed date" doesn't do what you think it should (this was a filesystem speed optimisation brought in a few years ago). – roaima Feb 15 '17 at 10:28
  • @Kusalananda can you please help me by giving some examples. – ramp Feb 15 '17 at 14:21
  • @roaima I totally agree with you but I had to extend the debusfs command to achieve that. – ramp Feb 15 '17 at 14:31
  • If this is just an exercise, the reasonable thing to do, without having to hard-code knowledge of how various commands need to be invoked to output their version names, is to run test -x $file && ./$file --version (and hope that the command is nondestructive!). You need to use ./ or the absolute pathname of the command so that you don't inadvertently invoke your shell's builtin command of the same name or something in your search path. I think that's what's happening with sleep --version; you're probably running the sleep that's builtin to ksh (or the AST version). – Mark Plotnick Feb 15 '17 at 23:41

Your Answer

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

Browse other questions tagged or ask your own question.