Find out where $PATH is defined

7

1

I recently installed an Arch-Linux System. If I type

echo $PATH

it points (among others) to a directory inside my /home/user/dir I can remember I set up somewhere. I have it as root user also, so it cannot be in ~/.bashrc and isn't as well in /root/.bashrc. I looked also inside /etc/profile and /etc/bash.bashrc but couldn't find it there, too.

Is there a way to find where it is set?

Rafael T

Posted 2012-07-01T20:08:13.200

Reputation: 184

How are you logging in as root to get the same PATH? Even if you log in from the console, inheriting nothing from another user session? – Daniel Beck – 2012-07-01T20:12:31.100

yes, even if I log in via tty1 as root or at run-level 3. I guess theres no user-session inside run-level 3?! – Rafael T – 2012-07-01T20:17:04.233

Answers

7

Try searching for the directory in all files in /etc:

sudo grep -r "/home/user/dir" /etc

The -r switch makes grep search for /home/user/dir in the contents of all files in /etc and its subdirectories.

From grep(1) - Linux man page:

-d ACTION, --directories=ACTION

If an input file is a directory, use ACTION to process it. By default, ACTION is read, which means that directories are read just as if they were ordinary files. If ACTION is skip, directories are silently skipped. If ACTION is recurse, grep reads all files under each directory, recursively; this is equivalent to the -r option.

If that fails, you could simply extend the search to all files:

sudo grep -r "/home/user/dir" /

Or you could search for all files that modify the PATH variable:

sudo grep -r "PATH=" /

Dennis

Posted 2012-07-01T20:08:13.200

Reputation: 42 934

0

It's usually a bad idea to put user directories in the global path as root ;) Did you check the /etc/environment file?

Izzy

Posted 2012-07-01T20:08:13.200

Reputation: 3 187

no, but did it now, and still no luck – Rafael T – 2012-07-01T20:32:34.777

0

@Dennis points me to a nice idea! I searched inside my /etc and found it, but with another command, as his command is only searching for filenames (as far as I understand).

The one I used succesful was

find / -type f -exec grep -i /home/user/dir '{}' \; -print

Rafael T

Posted 2012-07-01T20:08:13.200

Reputation: 184

2My command would have worked as well. The only difference is the -i switch, which should be unnecessary since the path is case sensitive. grep -r recursively searches the contents of all files in the specified folder. – Dennis – 2012-07-01T23:56:13.530