Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

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

If I would like to know whether a binary can be run from the command line, X Window System or both, how do I tell without access to the Internet?

share|improve this question
Wait...are you asking how to find out if the binary does utilize a GUI of any sorts? – Bobby Apr 17 '12 at 8:27
@Bobby - I am asking if a binary requires the use of a desktop environment or X Window System to run and if so how do I tell apart from the obvious use of a prefix e.g. gedit – PeanutsMonkey Apr 17 '12 at 8:30
Use ldd on the executable. – David Schwartz Apr 17 '12 at 8:38
@David Schwartz - Do you mean ldd vim? – PeanutsMonkey Apr 17 '12 at 19:48
Rather ldd $(which vim) I'd say. – Eroen Apr 17 '12 at 20:26
up vote 4 down vote accepted

Use ldd to check whether it is linked against an X11 library such as libX11 or libxcb. If either is listed, the program may use X11.

However, it does not mean it requires X11; this is impossible to determine programmatically without either examining source code or running the program. For example, a program may display a graphical window if X11 is available, and a text interface otherwise.

If the executable is statically-linked, run strings on it and look for the words "DISPLAY", ".Xauthority", "/tmp/.X" or similar. This is an even less reliable indicator, since these strings might occassionally occur even in purely textual programs.

share|improve this answer
+1. Although it doesn't do everything in the question, I don't think a better solution exists unless sources are available. – Eroen Apr 17 '12 at 9:02
@grawity - What do you mean by statically-linked? – PeanutsMonkey Apr 17 '12 at 19:47
@PeanutsMonkey: One that has library functions copied to the executable itself instead of just referencing them through /usr/lib/*.so files. – grawity Apr 17 '12 at 19:55

Read the man page.

Though you may actually have to read the fool thing rather than glancing at the usage and quickly paging through the options.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .