Fedora Linux Support Community & Resources Center

Go Back   FedoraForum.org > Fedora 17/18 > Using Fedora
FedoraForum Search

Forgot Password? Join Us!

Using Fedora General support for current versions. Ask questions about Fedora and it's software that do not belong in any other forum.

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 13th June 2009, 05:39 PM
pingpong's Avatar
pingpong Offline
Registered User
 
Join Date: Jul 2007
Posts: 51
How to use direct command

Hi, I am not sure why I have to type ./ before a command to excute it. Why can't I use direct command? What should I do so I don't have to type ./ before a command. I couldn't find any thread relating to this issue so I post it here. Could someone please explain this and tell me what to do.

Thank you
__________________
Where Am I ???
Reply With Quote
  #2  
Old 13th June 2009, 05:44 PM
Hlingler's Avatar
Hlingler Offline
Administrator
 
Join Date: Sep 2006
Location: Connellsville, PA, USA
Posts: 11,289
Depends upon the PATH environment variable set inside your user's ~/.bashrc file. Executables must be located somewhere in that $PATH. Executables NOT located in that $PATH require specific calls, such as full or abbreviated PATH in the command line. Search for: path environment variable.

V
Reply With Quote
  #3  
Old 13th June 2009, 09:40 PM
Min Offline
Registered User
 
Join Date: Jun 2009
Location: Melbourne
Posts: 246
That to prevent malicious script named "cd" (or any common command) being executed unintentionally. Let's say you're in a folder that have malicious script named "ls", you could not run it unintentionally by typing ls, because you need to type ./ls to run that script. if you want, i think you can add ./ in path to make it like you want but i don't think it is recommended
__________________
Macbook aluminum 5,1
Snow Leopard, Constantine, Seven
Reply With Quote
  #4  
Old 14th June 2009, 05:04 AM
gogalago Offline
Registered User
 
Join Date: Sep 2007
Location: Japan
Posts: 81
When you tell linux to execute a command it doesn't know where to find it, so you need to tell it. If you were trying to run something in your home directory, you might use:
/home/pingpong/thecommand
ie you are telling it to look in /home/pingpong for thecommand.
"./" has a special meaning - its the directory you are currently in which is why it needs to be there. (Similarly "../" means the directory above you.)

There are some places where system commands are commonly stored, so linux will check these places first, if you don't tell it where to look. These places are stored in a variable called PATH. If you want you can add other places to that, and yes you can even add "." to it if you want to, but there are a few reasons why its not a good idea and which is why its not set up like that by default, so you need to type the ./ first. The simplest of the reasons is that there's a good chance you might have a file with the same name as a system command, in which case the OS won't know which one to use. It doesn't really take a lot of time to type and you'll stop forgetting to type it soon!
Reply With Quote
  #5  
Old 14th June 2009, 05:59 AM
pingpong's Avatar
pingpong Offline
Registered User
 
Join Date: Jul 2007
Posts: 51
Thank you for your help. I did not have a basic knowledge of linux . I just happen to use it sometimes. I remember my classmate did something very easy to fix it. For eg I create a folder and then have a program to execute in it. I tried to search but turn out to get no answer. Unfortunately my friend is on holiday so I can't contact him. Could you please tell me more in detail (and as a safe way as possible). Would it be global? I mean to execute a command from any where, not necessary to be in the folder where the program is? And if so what particular text should I add in and to which file? I would greatly appreciate.
__________________
Where Am I ???

Last edited by pingpong; 14th June 2009 at 06:07 AM.
Reply With Quote
  #6  
Old 14th June 2009, 06:35 AM
scottro's Avatar
scottro Offline
Retired Community Manager -- Banned from Texas by popular demand.
 
Join Date: Sep 2007
Location: NYC
Posts: 8,142
Well, what you can do, if you have some special commands that only you will run, is create a script in your home directory called bin.

This will actually be in your path. If you type

echo $PATH

(The $ in front of it means, give me the value of the variable known as PATH) you'll see that included in places to look for commands is your own home directory--so, if your username is pingpong, you'll see something like /usr/bin:/usr/local/bin:/home/pingpong/bin (plus other stuff.)

Now, after you do that, when you create a command like this, you have to make it executable. You can do that by typing

chmod 700 /home/pingpong/bin/command

Now, it won't be global. Only you can use it. That 7 means that the programs owner can read, write and execute the program.

I'm just giving you the how here and not the why. It's very late here, and I've got to get some sleep.
__________________
--
http://home.roadrunner.com/~computertaijutsu

Do NOT PM forum members with requests for technical support. Ask your questions on the forum.


"I don't know why there is the constant push to break any semblance of compatibility" --anon
Reply With Quote
  #7  
Old 14th June 2009, 07:07 AM
pingpong's Avatar
pingpong Offline
Registered User
 
Join Date: Jul 2007
Posts: 51
Hope you sleep well. Thank you so much for the "late" effort, I just edited my previous post and may be that is why you only gave me this answer. I asked which particular text to put in and to which file? As I said I don't have a basic knowledge so I am not clear how to "create a script in your home directory called bin".

Other thing is what if I copy the program to a folder in my USB drive, how to also execute the command without typing ./ there.

This may be a small issue for people who know smt about linux, but for me I really still cant get out of it.
__________________
Where Am I ???
Reply With Quote
  #8  
Old 14th June 2009, 09:47 AM
markkuk Offline
Registered User
 
Join Date: Apr 2005
Location: Finland
Posts: 5,076
You don't put any particular text in any specific file, you must move the program itself to a directory that's in the $PATH if you want it to be executable anywhere without specifying the full location. The "bin" directory inside your home directory is one such place, that's what scottro meant.
Reply With Quote
  #9  
Old 14th June 2009, 10:17 AM
gogalago Offline
Registered User
 
Join Date: Sep 2007
Location: Japan
Posts: 81
Maybe you could tell us some details about what it is you are doing that makes typing the ./ such a problem?

If you are really typing a lot, soon you'll do it without thinking, but if its just an annoying little thing that you forget sometimes and you are trying to avoid that, then maybe its better to wait until you know more about linux before changing the system too much, because it can cause other problems.... as others have said there are good reasons that the system is set up that way, and you might get into other difficulties if you just try to "cheat" it.
sometimes part of learning linux is learning the linux way of doing things, and just getting some new habits. and you also don't want to end up doing too many changes that you will need to set up again as soon as a new version comes out...

(I'm not trying to be difficult, but could help more if I could understand your problem better and if I knew some kind of background)
Reply With Quote
  #10  
Old 14th June 2009, 11:26 AM
pingpong's Avatar
pingpong Offline
Registered User
 
Join Date: Jul 2007
Posts: 51
Yeah Thanks for your advice. I will spend time to learn more, however I also have too many other things to learn .
I typed $PATH I get /usr/lib/qt-3.3/bin:/usr/kerberos/bin:/usr/local/bin:/usr/bin:/bin:/usr/X11R6/bin. I created a bin folder in home/pingpong and put my program in there but I still cannot execute it without ./ so do I need to log out and back in? I notice that in the above PATH doesn't have /home/pingpong/bin. How do I add it in?

This is really a great community. I am surprised that many of you still look at my thread and try to help me out even with a very small issue (not small to me though).
A classmate of mine told me to use Ubuntu or OpenSus smt, but it seems I only like Fedora coz I have some good feeling about it and I believe I am right even though I know I have to become root by typing su if necessary while in other OS, I can do so by a sudo command.
__________________
Where Am I ???

Last edited by pingpong; 14th June 2009 at 11:45 AM.
Reply With Quote
  #11  
Old 14th June 2009, 12:11 PM
gogalago Offline
Registered User
 
Join Date: Sep 2007
Location: Japan
Posts: 81
Add this to the file /home/pingpong/.bash_profile
Code:
PATH=$PATH:$HOME/bin

export PATH
If that file doesn't exist yet, there may be a few other things you should put in there... and note the "." before the filename - that means its a hidden file.
Reply With Quote
  #12  
Old 14th June 2009, 12:46 PM
pingpong's Avatar
pingpong Offline
Registered User
 
Join Date: Jul 2007
Posts: 51
Hi, I check the file and it already has the code that you gave me at the end.
__________________
Where Am I ???
Reply With Quote
  #13  
Old 15th June 2009, 05:56 AM
gogalago Offline
Registered User
 
Join Date: Sep 2007
Location: Japan
Posts: 81
hmmm... not too sure.

What shell are you using?

try putting it in ~/.bashrc then ( "~" means your home directory)

Some other things I thought of that you might not know that make time in the shell easier:
- you can use the up and down keys to go through a list of previously typed commands
- tab completion: if you hit tab after starting to type a command the shell will try to finishing typing for you ie if you type "/h" and hit tab it will become "/home/". If it can't work out what you mean (maybe you have 2 directories starting with "h") it won't do anything, but hitting tab again will give you a list of possible completions - you'll have to type enough for it to be able to tell them apart.
Reply With Quote
  #14  
Old 15th June 2009, 09:09 AM
pingpong's Avatar
pingpong Offline
Registered User
 
Join Date: Jul 2007
Posts: 51
I got it running, I cp the program to the /home/pingpong/bin and log out and back in and now it work, now I can use the command from anywhere, I don't have to edit or add any thing, just create a bin folder and place a copy of the program in it as Scottro advised. Thanks, you all are very nice. I learn something from you.
__________________
Where Am I ???
Reply With Quote
  #15  
Old 11th July 2009, 09:37 AM
pingpong's Avatar
pingpong Offline
Registered User
 
Join Date: Jul 2007
Posts: 51
Hi, Its me again. I realize that whenever I need to use a command directly I need to put that command into the bin folder /home/pingpong/bin. However I remembered my friend did not have to copy the file into this folder to use direct command from USB drive where the file is. I am sure there is another way. Could someone please help me out with this issue?
__________________
Where Am I ???
Reply With Quote
Reply

Tags
command, direct

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
No Direct Rendering Axiom119 Hardware & Laptops 2 15th June 2008 01:57 AM
Direct Rendering jbrowne Hardware & Laptops 6 1st March 2008 09:22 PM
No direct rendering anthony_de Hardware & Laptops 7 17th January 2007 04:05 AM
please direct me goldstar1 Servers & Networking 4 10th October 2006 09:36 PM
Direct Connect (dc++) on FC4 suv Using Fedora 6 5th September 2005 05:08 AM


Current GMT-time: 06:37 (Friday, 24-05-2013)

TopSubscribe to XML RSS for all Threads in all ForumsFedoraForumDotOrg Archive
logo

All trademarks, and forum posts in this site are property of their respective owner(s).
FedoraForum.org is privately owned and is not directly sponsored by the Fedora Project or Red Hat, Inc.

Privacy Policy | Term of Use | Posting Guidelines | Archive | Contact Us | Founding Members

Powered by vBulletin® Copyright ©2000 - 2012, vBulletin Solutions, Inc.

FedoraForum is Powered by RedHat