LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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


Reply
  Search this Thread
Old 01-13-2024, 03:11 PM   #1
theyikes
LQ Newbie
 
Registered: Jan 2024
Posts: 1

Rep: Reputation: 0
run command from anywhere


Hello! I don't know if this has been asked before but to be honest i don't really know how to ask this question. I'll try to explain. I have a command that i run on kubuntu but each time i do i have to put in the folder and file location of the command. Is there any way of running it without entering the filepath?

i tried export PATH=$PATH:/

i was trying to set the folder path, i tried setting it for each individual file and it works. but is there anyway i can just specify a folder rather than a single file?

Last edited by theyikes; 01-13-2024 at 03:18 PM. Reason: update again
 
Old 01-13-2024, 03:34 PM   #2
uteck
Senior Member
 
Registered: Oct 2003
Location: Elgin,IL,USA
Distribution: Ubuntu based stuff for the most part
Posts: 1,173

Rep: Reputation: 501Reputation: 501Reputation: 501Reputation: 501Reputation: 501Reputation: 501
You can set this in your .profile config, or you could make a folder called bin in your home and put it there, or link it. The $HOME/bin folder is for user owned binaries that do not require root access to run or install.
Another option is /opt/bin which may still need adding to your .profile.

Forgot to add that yo need to re-login or re-read the new config file with:
Code:
source .profile

Last edited by uteck; 01-13-2024 at 03:36 PM.
 
1 members found this post helpful.
Old 01-13-2024, 04:29 PM   #3
maybeJosiah
Member
 
Registered: Jan 2024
Location: USA
Distribution: Ubuntu, Android, Ubuntu Touch, Jolla Sailfish maybe
Posts: 195
Blog Entries: 2

Rep: Reputation: 5
You could also maybe use .bashrc in your home directory. Just write a line at end to export whatever script you want like you were exporting but this makes it always exported. You need to access a hidden file to do this.
Quote:
export PATH=$PATH:/path/to/your/file.sh
If you do not want to log out and log back in:
Quote:
source ~/.bashrc
Otherwise you will need to log out then relogin. Hope this helps. X E.
 
Old 01-13-2024, 05:36 PM   #4
enigma9o7
Senior Member
 
Registered: Jul 2018
Location: Silicon Valley
Distribution: Bodhi Linux
Posts: 1,388

Rep: Reputation: 560Reputation: 560Reputation: 560Reputation: 560Reputation: 560Reputation: 560
Alternatively, if you don't want to add another directory to your path, you could add a simlink in a directory that's already in your path.

For example, if "~/.local/bin" is in your path (check with "echo $PATH") and what you want to run from anywhere is in "~/foldername" and called "appname" then
Code:
ln -s ~/foldername/appname ~/.local/bin
No restart of anything required.

Last edited by enigma9o7; 01-13-2024 at 05:37 PM.
 
1 members found this post helpful.
Old 01-13-2024, 06:14 PM   #5
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,708

Rep: Reputation: 5898Reputation: 5898Reputation: 5898Reputation: 5898Reputation: 5898Reputation: 5898Reputation: 5898Reputation: 5898Reputation: 5898Reputation: 5898Reputation: 5898
As another alternative depending on if you want your commands accessible by all users would be to put them in /usr/local/bin. Its in the default PATH environment so nothing to change.
 
2 members found this post helpful.
Old 01-17-2024, 03:10 AM   #6
MadeInGermany
Senior Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 2,796

Rep: Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201
@maybeJosiah
There is a mistake: PATH contains the directories of executables.
If you have an executable /path/to/your/file.sh
then it must be
Code:
export PATH=$PATH:/path/to/your
for bash.
This is good for .profile (common to bash and sh) or .bash_profile (bash only).
It depends on your distro if/when a .profile is used.

Otherwise put it in .bashrc that is always run when a bash starts. To avoid multiple addings in nested shells I would go for

Code:
addp=$HOME/bin
case ":$PATH:" in
( *":$addp:"* )
;;
( * )
  export PATH=$PATH:$addp
  mkdir -p "$addp"
esac
unset addp
It only adds $HOME/bin to the PATH if it's not yet there.

Many distros have $HOME/bin by default. Then you simply move your executables there.
Code:
mv myexecutable $HOME/bin/

Last edited by MadeInGermany; 01-17-2024 at 03:12 AM.
 
1 members found this post helpful.
Old 01-17-2024, 11:18 AM   #7
maybeJosiah
Member
 
Registered: Jan 2024
Location: USA
Distribution: Ubuntu, Android, Ubuntu Touch, Jolla Sailfish maybe
Posts: 195
Blog Entries: 2

Rep: Reputation: 5
Ah yes MadeInGermany, thank you. Sorry for that last error. X E.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to run my C program from anywhere within the System (Ubuntu 10.10)? anis_huq Programming 8 05-02-2011 02:17 AM
IPTables has a "drop all anywhere" and "accept all anywhere" Zero187 Linux - Security 4 06-18-2009 07:09 PM
LXer: VMware: REAL Write Once, Run Anywhere LXer Syndicated Linux News 0 09-17-2008 06:20 AM
LXer: Platform promises "write-once, run anywhere" Linux apps LXer Syndicated Linux News 0 06-01-2007 08:01 AM
Run a command from anywhere ToothlessRebel Linux - Newbie 4 03-05-2005 01:36 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:14 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration