Linux get file version

Viewing Linux Library / Executable version info

The version info in not explicitly stored in an ELF file. What you have in there is the name of the library, the soname , which includes the major version. The full version is usually stored as a part of the library file name.

If you have library, say libtest.so , then you usually have:

  • libtest.so.1.0.1 — The library file itself, containing the full version
  • libtest.so.1 — Symlink to libtest.so.1.0.1 , having the same name as soname
  • libtest.so — Symlink to libtest.so.1 used for linking.

In the library file libtest.so.1.0.1 , there will be an entry called SONAME in dynamic section, that will say this library is called libtest.so.1 . When you link a program against this library, the linked program will store the soname of the library under NEEDED entry in the dynamic section.

If you want to verify, what exactly is in which ELF file, you can try to run:

where elffile can be either an library of an executable.

If you simply want to get the library version, you can play with:

readelf -d /path/to/library.so |grep SONAME 

AFAIK, there’s no such info (at least not by default) in executable files.

Or you can rely on the program itself or your packaging system, as Rahul Patil wrote.

nice info, it’s new to me never used readelf, if you don’t mind , may i ask you where & why use readelf

Readelf (and similar tools) is useful, when you want to look inside an elf file :). I use it mostly when programming to look up symbols in libraries (when something doesn’t work), or when there’s some problem with a library. (man readelf)

You can use ldconfig -v | grep libraryname , also command has option command -V or binaryfile —version

test@ubuntukrb12:~# ls --version ls (GNU coreutils) 8.13 Copyright (C) 2011 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later . This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. 

also you can use yum or aptitude based on distro you are using eg.

in RHEL5/CENTOS5/Fedora you can use yum info packagename or if it installed then use rpm —version packagename

 [root@ldap1 ~]# yum info bind97 Loaded plugins: downloadonly, fastestmirror, security Loading mirror speeds from cached hostfile * base: mirrors.sin3.sg.voxel.net * epel: mirror.imt-systems.com * extras: mirrors.sin3.sg.voxel.net * updates: mirrors.sin3.sg.voxel.net Installed Packages Name : bind97 Arch : i386 Epoch : 32 Version : 9.7.0 Release : 10.P2.el5_8.4 Size : 6.3 M Repo : installed Summary : The Berkeley Internet Name Domain (BIND) DNS (Domain Name System) server URL : http://www.isc.org/products/BIND/ License : ISC Description: BIND (Berkeley Internet Name Domain) is an implementation of the DNS : (Domain Name System) protocols. BIND includes a DNS server (named), : which resolves host names to IP addresses; a resolver library : (routines for applications to use when interfacing with DNS); and : tools for verifying that the DNS server is operating properly. 

In Ubuntu You can use aptitude show pkgname or dpkg —version pkgname

root@ubuntukrb12:~# aptitude show bind9utils Package: bind9utils State: installed Automatically installed: yes Version: 1:9.8.1.dfsg.P1-4ubuntu0.4 Priority: optional Section: net Maintainer: Ubuntu Developers Architecture: amd64 Uncompressed Size: 306 k Depends: libbind9-80, libc6 (>= 2.14), libdns81, libisc83, libisccc80, libisccfg82 Conflicts: bind9utils Replaces: bind9 ( 

Источник

Extracting version number from a filename

where XXX.XX is a version number and I need the version number only. How to do it in linux? I have this code:

#!/bin/bash current_ver=$(find /mnt/builds/current -name '*.run'|awk -F/ '') 

So this gives me just the name of the file correctly (minus the location, which I don't want). But how do I only get the XXX.XX version number into a variable such as $version

4 Answers 4

You actually don't need any external tools. You can do this entirely within bash, by chopping variables according to patterns..

[ghoti@pc ~]$ name="installer-x86_64-XXX.XX-diagnostic.run" [ghoti@pc ~]$ vers=$; echo $vers x86_64-XXX.XX-diagnostic.run [ghoti@pc ~]$ vers=$; echo $vers XXX.XX-diagnostic.run [ghoti@pc ~]$ vers=$; echo $vers XXX.XX [ghoti@pc ~]$ 

Or if you prefer, you can chop off pieces right-hand-side first:

[ghoti@pc ~]$ name="installer-x86_64-XXX.XX-diagnostic.run" [ghoti@pc ~]$ vers=$; echo $vers installer-x86_64-XXX.XX [ghoti@pc ~]$ vers=$; echo $vers XXX.XX [ghoti@pc ~]$ 

Of course, if you want to use external tools, that's fine too.

[ghoti@pc ~]$ name="installer-x86_64-XXX.XX-diagnostic.run" [ghoti@pc ~]$ vers=$(awk -F- '' <<<"$name") [ghoti@pc ~]$ echo $vers XXX.XX [ghoti@pc ~]$ vers=$(sed -ne 's/-[^-]*$//;s/.*-//;p' <<<"$name") [ghoti@pc ~]$ echo $vers XXX.XX [ghoti@pc ~]$ vers=$(cut -d- -f3 <<<"$name") [ghoti@pc ~]$ echo $vers XXX.XX [ghoti@pc ~]$ 

Источник

Linux get version of file command prompt

To visualize several old versions of one file, the simplest mean is to display its version tree ( ), and then select a version, right-click on it and ' ' an editor which accepts multiple files (like Notepad++). But to visualize several old versions of different files, I would recommend a dynamic view and editing the config spec of that view (and not the snapshot view you are currently working with), in order to quickly select all those old files (hopefully through a simple select rule like ' ')

Check PDF file version from command line

Yes. The file command covers this

$ file x1.pdf x1.pdf: PDF document, version 1.7 $ 

To get greater detail, you could try pdfinfo , part of popper-utils.

$ pdfinfo x1.pdf Title: Full page photo Author: steve Producer: Microsoft: Print To PDF CreationDate: Fri Apr 5 10:14:34 2019 ModDate: Fri Apr 5 10:14:34 2019 Tagged: no UserProperties: no Suspects: no Form: none JavaScript: no Pages: 9 Encrypted: no Page size: 841.5 x 594.75 pts Page rot: 0 File size: 5424973 bytes Optimized: no PDF version: 1.7 $ 

How to find the browser versions from command-line in Linux, In ubuntu when I just open a terminal and say "firefox -v" or "konqurer -v" it prints all the version information. Previously on Windows xp

Linux - command line to get version of terminal

echo $TERM tells you kind of terminal you are using, eg. xterm

Use the ps command with no arguments to get the processes running under the current shell.

% ps PID TTY TIME CMD 1917 pts/0 00:00:00 zsh 13659 pts/0 00:00:00 ps 

How to Find Out File Types in Linux, To find out file types we can use the file command. Syntax: file [OPTION…] [FILE…] You can run the following command to verify the version

In ClearCase, how can I view old version of a file in a static view, from the command line?

I'm trying to look at a bunch of old versions

I am not sure if you are speaking about "a bunch of old versions" of one file , "a bunch of old versions" from several files.

To visualize several old versions of one file, the simplest mean is to display its version tree ( ct lsvtree -graph File ), and then select a version, right-click on it and ' Send To ' an editor which accepts multiple files (like Notepad++). In a few click you will have a view of those old versions.
Note: you must have CC6.0 or 7.0.1 IFix01 (7.0.0 and 7.0.1 fail to 'sent to' a file with the following error message " Access to unnamed file was denied ")

But to visualize several old versions of different files, I would recommend a dynamic view and editing the config spec of that view (and not the snapshot view you are currently working with), in order to quickly select all those old files (hopefully through a simple select rule like ' element * aLabel ')

what's the idiomatic way to "cat" an earlier revision of a file?

The idiomatic way is through a dynamic view (that you configure with the exact same config spec than your existing snapshot view).

You can then browse (as in 'change directory to') the various extended paths of a file.

If you want to cat all versions of a branch of a file, you go in:

cd /view/MyView/vobs/myVobs/myPath/myFile@@/main/[. ]/maBranch cat 1 cat 2 . cat x 

' 1 ', ' 2 ', . ' x ' being the version 1, 2, . x of your file within that branch.

For a snapshot view , the extended path is not accessible , so your "hack" is the way to go.

(one line version for copy-paste, Unix syntax:)

cleartool find addon.xml -ver 'brtype(aBranch) && !version(. /aBranch/LATEST) && ! version(. /aBranch/0)' -exec 'cleartool diff -ser empty "$CLEARCASE_XPN"'

(multi-line version for readability:)

cleartool find addon.xml -ver 'brtype(aBranch) && !version(. /aBranch/LATEST) && ! version(. /aBranch/0)' -exec 'cleartool diff -ser empty "$CLEARCASE_XPN"'

(one line version for copy-paste, Unix syntax:)

cleartool find addon.xml -ver 'brtype(aBranch) && !version(. /aBranch/LATEST) && ! version(. /aBranch/0)' -exec 'cleartool diff -ser empty "$CLEARCASE_XPN"' | ccperl -nle '$a=$_; $b = $a; $b =~ s/^>+\s(?:file\s+\d+:\s+)?//g;print $b if $a =~/^>/'

(multi-line version for readability:)

cleartool find addon.xml -ver 'brtype(aBranch) && !version(. /aBranch/LATEST) && ! version(. /aBranch/0)' -exec 'cleartool diff -ser empty "$CLEARCASE_XPN"' | ccperl -nle '$a=$_; $b = $a; $b =~ s/^>+\s(?:file\s+\d+:\s+)?//g; print $b if $a =~/^>/'

That way, the output is nicer.

The " cleartool get " command (man page) mentioned below by Brian don't do stdout:

The get command copies only file elements into a view.

On a UNIX or Linux system, copy /dev/hello_world/foo.c@@/main/2 into the current directory.

cmd-context get –to foo.c.temp /dev/hello_world/foo.c@@/main/2 

On a Windows system, copy \dev\hello_world\foo.c@@\main\2 into the C:\build directory.

cmd-context get –to C:\build\foo.c.temp \dev\hello_world\foo.c@@\main\2 

So maybe than, by piping the result to a cat (or type in windows), you can then do something with the output of said cat ( type ) command.

cmd-context get –to C:\build\foo.c.temp \dev\hello_world\foo.c@@\main\2 | type C:\build\foo.c.temp 

I know this is an old thread. but I couldn't let this thrashing go by unresolved.

Static views have a "ct get" command that does exactly what you are looking for.

cleartool get -to ~/foo File@@/main/28 

will save this version of the file in ~/foo .

[ Rewritten based on the first comment ]

All files in Clearcase, including versions, are available in the virtual directory structure. I don't have a lot of familiarity with static views, but I believe they still go through a virtual fs; they just get updated differently.

In that case, you can just do:

It can get ugly if you also have to find the right version of a directory that contained that file element. We have a PERL script at work that uses this approach to analyze historical changes made to files, and we quickly ran out of command-line space on Windows to actually run the commands!

Shell - linux - command line to get version of terminal, Use the ps command with no arguments to get the processes running under the current shell. Example: % ps PID TTY TIME CMD 1917 pts/0

Источник

Thread: How can we get file version information in Linux?

payal is offlineNovice

Join Date Feb 2010 Posts 31 Qt products Platforms

DefaultHow can we get file version information in Linux?

I am porting one Qt appllication from windows to linux which is using Win32 functions like GetFileVersionInfoSize(),GetFileVersionInfo() and VerQueryValue() for getting file version information.

is there any equivalent functions in linux to get file version information?

I came to know that we are getting version info from version.dll in Windows. is it possible to make use use of that dll by installing Winelib in Linux?

Plz provide me some answers.

high_flyer is offlineWiseguy

Nokia Certified Qt Developer

Join Date Jan 2006 Location Munich, Germany Posts 4,714 Thanks 21 Thanked 418 Times in 411 Posts Qt products Platforms

DefaultRe: How can we get file version information in Linux?

I don't know for sure, but I don't think the linux file systems have such a thing as savaing file version info in them.
The way I know is by naming the libs with their corresponding version numbers.
If I am correct, then you better just put the code associated with these function under #ifdef WIN32.
Another way could be to override these function to retrieve the version number from the lib file name.

Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

Источник

Читайте также:  Linux server management system
Оцените статью
Adblock
detector