Views:
87,187β
Votes: 10β
Tag :
command-line
Link:
π See Original Answer on Ask Ubuntu β§ π
URL:
https://askubuntu.com/q/1037165
Title:
How to run a file in a different directory
ID:
/2018/05/16/How-to-run-a-file-in-a-different-directory
Created:
May 16, 2018
Edited: May 24, 2018
Upload:
September 15, 2024
Layout: post
TOC:
false
Navigation: false
Copy to clipboard: false
No you donβt need to use:
cd home/directoryA/directoryB/directoryC/DirectoryD
./somefileΒ
You can simply run the command by prefixing it with its path:
/home/directoryA/directoryB/directoryC/DirectoryD/somefile
Because you are already in the /home/directoryA
you can use the current directory shortcut .
and run the command like this:
./directoryB/directoryC/DirectoryD/somefile
I noticed OP has expanded scope via comments under other answers. Here is some additional information:
- To find out where
somefile
is located use:locate somefile
. - If
somefile
was added today you need to first update the locate database by runningsudo updatedb
. - When there are multiple versions of
somefile
located in the PATH you can find out which one is executed first usewhich somefile
. - If you want to run
somefile
without specifying a directory name in front put it in the path. To check the path useecho $PATH
. Common path locations to putsomefile
are/usr/local/bin
(if it uses sudo powers) and/home/your_user_name/bin
(you might have to create the directory first). - You can also add
/home/directoryA/directoryB/directoryC/DirectoryD/
to your path but that would be highly unusual. However you could then simply typesomefile
no matter what directory you are in and it will run. - Of course
somefile
must be executable which you set with the command:chmod a+x /home/directoryA/directoryB/directoryC/DirectoryD/somefile