How to locate a file in the system path?

J

joe99

Guest
How to locate a file in the system path?
I want to search for a file within the PATH environment variable.
How can this be made?
 


A

arochester

Guest
Not sure that I fully understand this.

PATH is an environmental variable in Linux and other Unix-likeoperating systemsthat tells the shell which directories to search for executable files (i.e., ready-to-runprograms) in response to commands issued by a user.
http://www.linfo.org/path_env_var.html

2 useful commands are: whereis and which.

E.g.
whereis chromium
chromium: /usr/bin/chromium /etc/chromium /usr/lib/chromium /usr/bin/X11/chromium /usr/share/man/man1/chromium.1.gz

and

which chromium
/usr/bin/chromium

"which" finds the executable.
 
J

joe99

Guest
Hi Arochester,

This is a quiz question. What is requested is to show how can we locate a generic file in the system path.

"How to locate a file called “HelloWorld.java” in the system path?"

I would appreciate your help on this question.
 
S

Snipert

Guest
This is a odd question. which & whereis are specified commands for finding files along the PATH variable..
But for a generic file that otherwise wouldn't come up, I'd try using find. A quick idea is this:
#find $(echo $PATH | tr : " ") -iname filename.ext

It's a hack, but here's my reasoning:
The PATH variable contains : to seperate each path. We need to change that to spaces as the find syntax is --> find /path/dir /path/dir2 -commands searchterm
tr(anslate) does this, so by getting the output of tr by using $() we get all the paths needed, without needing to "hard-code" it.
 


Members online


Latest posts

Top