Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place! |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
06-22-2012, 07:17 PM
|
#1
|
Member
Registered: Aug 2009
Posts: 349
Rep:
|
run program from any directory
I have a small script that i use to check the name of processes.
I can oly use it in my home directory.
So when i am in another directoy, I have to type in
Code:
/home/casper/my_program
or cd to my home directory and then type ./my_program
Is there a way that I could configure my path so I could run the program from any directory?
|
|
|
06-22-2012, 07:30 PM
|
#2
|
Member
Registered: Jan 2009
Location: New England
Distribution: Arch Linux
Posts: 719
Rep:
|
Edit your
~user/.bashrc
if you want the change to only effect that user
/etc/bash.bashrc
if you want to make it system wide
Code:
sudo vim ( or whatever text editor you perfer ) /etc/bash.bashrc
look for a line like this
PATH=/usr/local/sbin:/usr/lib:/usr/lib64:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/X11R6/bin:/home/user/Scripts:/opt/java/jre
add the directory where your script is. Seperate the previous entry with :
The same method for ~user/.bashrc
|
|
|
06-22-2012, 10:13 PM
|
#3
|
Member
Registered: Aug 2009
Posts: 349
Original Poster
Rep:
|
So yeah - I don't see a ~user/.bashrc in my work directory
or a /etc/.bashrc
casper@casperbox /home/casper $ ls -ltr /.bashrc
ls: /.bashrc: No such file or directory
my bash seems to work just fine without it.
So I could just create a file /home/casper/.bashrc
add the example that you wrote, and it wont effect other users.
this is a work host - so I really can't screw around.
|
|
|
06-23-2012, 07:18 AM
|
#4
|
LQ 5k Club
Registered: Jan 2008
Location: Copenhagen DK
Distribution: PCLinuxOS2023 Fedora38 + 50+ other Linux OS, for test only.
Posts: 17,519
|
Quote:
casper@casperbox /home/casper $ ls -ltr /.bashrc
|
Wrong. There is no /.bashrc, but .bashrc
These commands will show your .bashrc :
$ ls -al .bash*
$ ls -ltr .bashrc
$ ls -ltr /home/casper/.bashrc
$ find . -name "*bashrc*"
.
|
|
|
06-23-2012, 07:57 AM
|
#5
|
Member
Registered: Jan 2009
Location: New England
Distribution: Arch Linux
Posts: 719
Rep:
|
The path (location of bashrc) is relative to where you are.
If you are in /home/user then .bashrc (dot is default to hide filesa)
If you are not in your home directory then /home/usr/.bashrc
Modifications to your bashrc in your home directory will only impact you and nobody else so you should be safe. If you don't like the changes you can always modify.
|
|
|
06-23-2012, 10:45 AM
|
#6
|
LQ Guru
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573
|
While you're in the process, you should probably move my_program out of your base home directory and into a subdir that will only contain other programs you've written. You don't want to just add your entire home directory to your PATH or things can get ugly. Make a new folder such as ~/bin, move my_program into there, and then add that directory to your PATH in ~/.bashrc
|
|
|
06-23-2012, 10:49 AM
|
#7
|
LQ Guru
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573
|
Quote:
Originally Posted by casperdaghost
So yeah - I don't see a ~user/.bashrc in my work directory
|
That's because it's not ~user/.bashrc. Maybe it was a typo in jv2112's post, not sure, but ~user/ isn't even a valid location. The file is located in either /home/user/.bashrc or ~/.bashrc (~ is a shortcut to /home/user).
Quote:
Originally Posted by casperdaghost
casper@casperbox /home/casper $ ls -ltr /.bashrc
ls: /.bashrc: No such file or directory
|
That's because you put a slash in front of it. "/.bashrc" is referencing a .bashrc file located in /, which doesn't exist. If you want to look in your current directory then leave the leading slash off: "ls -ltr .bashrc"
|
|
|
06-24-2012, 06:54 AM
|
#8
|
Member
Registered: Jan 2009
Location: New England
Distribution: Arch Linux
Posts: 719
Rep:
|
~usr/.bashrc is a valid location. I mean usr as in jim , larry , jane et cettera. ~ shortcut for /home/Name_of_usr/.bashrc......
|
|
|
06-24-2012, 07:23 AM
|
#9
|
Member
Registered: Sep 2011
Location: Italy
Distribution: Slackware
Posts: 651
Rep:
|
EDIT: this is actually wrong. See below
Quote:
Originally Posted by jv2112
~usr/.bashrc is a valid location. I mean usr as in jim , larry , jane et cettera. ~ shortcut for /home/Name_of_usr/.bashrc......
|
It is not, as ~ already contains the username part of the home path.
~usr, issued by the hypothetical user usr, would expand as /home/usrusr, not as the valid location /home/usr.
Last edited by 414N; 06-25-2012 at 04:04 AM.
Reason: Wrong assumption
|
|
|
06-24-2012, 07:48 AM
|
#10
|
Member
Registered: Jan 2009
Location: New England
Distribution: Arch Linux
Posts: 719
Rep:
|
blah blah blah ...... splitting hairs.... That is what the user would type.............
|
|
|
06-24-2012, 08:11 AM
|
#11
|
Member
Registered: Sep 2011
Location: Italy
Distribution: Slackware
Posts: 651
Rep:
|
EDIT: this is actually wrong. See below
Quote:
Originally Posted by jv2112
blah blah blah ...... splitting hairs.... That is what the user would type.............
|
Beg your pardon if I had the "arrogance" of pointing out that the notation you previously used was technically wrong, but I think one should strive to be as correct as possible especially in this section of the forum, where new users come seeking answers to their first Linux questions and would be additionally confused by wrong answers.
Last edited by 414N; 06-25-2012 at 04:05 AM.
Reason: Wrong
|
|
|
06-24-2012, 11:21 AM
|
#12
|
LQ Guru
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573
|
Quote:
Originally Posted by jv2112
blah blah blah ...... splitting hairs.... That is what the user would type.............
|
I just tested this, and you're right, you can use that syntax, I didn't realize that. I don't know why anybody would, since it's much faster to just use ~, but I suppose if you really wanted to you could.
~/.bashrc, and
~usr/.bashrc
will end up going to the same place.
Learn something new every day.
Last edited by suicidaleggroll; 06-24-2012 at 11:24 AM.
|
|
|
06-25-2012, 04:01 AM
|
#13
|
Member
Registered: Sep 2011
Location: Italy
Distribution: Slackware
Posts: 651
Rep:
|
Very interesting. I've never encountered this syntax so I thought it was wrong.
My sincere apologies to jv2112.
For completeness, here's the relevant portion of the bash manpage:
Code:
Tilde Expansion
If a word begins with an unquoted tilde character (`~'), all of the characters pre‐
ceding the first unquoted slash (or all characters, if there is no unquoted slash)
are considered a tilde-prefix. If none of the characters in the tilde-prefix are
quoted, the characters in the tilde-prefix following the tilde are treated as a pos‐
sible login name. If this login name is the null string, the tilde is replaced with
the value of the shell parameter HOME. If HOME is unset, the home directory of the
user executing the shell is substituted instead. Otherwise, the tilde-prefix is
replaced with the home directory associated with the specified login name.
|
|
|
06-25-2012, 04:20 AM
|
#14
|
LQ Guru
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and CentOS
Posts: 6,726
|
Quote:
Originally Posted by suicidaleggroll
I don't know why anybody would, since it's much faster to just use ~,
|
Because *nix is a multiuser system and ~foo and ~bar can be used to reference the home dir of different users. Just using ~ is good when you are referencing your own home dir, but ~foo and ~bar can be used for others home dirs.
In addition to this there is no requirement that a users home directory has the same name as the user it self. For example the user foo, could have the home directory "/home2/foobar", and ~foo would still reference /home2/foobar". Generally the location of the users home directory is set in /etc/passwd and it is only convention that it is usually /home/username
Evo2.
|
|
|
06-25-2012, 09:14 PM
|
#15
|
LQ Guru
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,415
|
Everything evo2 said; seen it, broke it !
I've even seen a system where all users had the one shared home dir that was also the 'home'/install dir of the APP they used ...
Needless to say, someone managed to delete it ... that was a fun morning...
|
|
|
All times are GMT -5. The time now is 09:35 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|