Freedom The Open Source Way Contribute Articles or News to OSForgeOSForge HomeLogout from Forums
Contacting OSForgeOSForge HomeAbout OSForge
  

Root
Contribute News
Learning Corner
Linux Distributions
Linux Common FAQ's
Discussion Forums
Community Gallery
Links Directory
Search OSForge
Networking
Industry Updates
Linux & Open Source
Opinions
Press Release
Programming
Security
Web Development

White Paper
Plat'Home Unveils Winners of “Will Linux Work?” Contest
Zenoss Core Recognized as Best Open Source Network Monitoring Solution
LinMin™ Joins Intel® Certified Software Solutions Program
xTuple™ ERP 3.0 Wins “Best Business Application” At LinuxWorld Conference & Exp
Holland Computing Center - Rocks+Moab Provides Windows/Linux Cluster Solution
LogMeIn Launches Mobile Plug-in for Linux
FuseMail Selects Funambol’s Open Source Push Email and PIM Sync Solution
Zenoss Expands IT Management Solution for Managed Service Providers
Moab Workload Manager Claims Title as World’s First Petaflop Scheduler
Moab Workload Manager Claims Title as World’s First Petaflop Scheduler

View More

Linux Newbie Guide III - Basics

Page: 3/10  [Printable Version]



How do I run a program?
Typing the name of the executable on the command line doesn't help? There are three possibilities.
The first possibility: you did not type the name of the executable correctly. Check the case--Linux is case sensitive!  For example, typing "Pico" or "PICO" will not start the pico editor.
The second possibility: maybe the program is not on your PATH.  Under Linux (or UNIX), an executable must be on your PATH to run it, and the current directory is NOT on your PATH. Type the full path to the executable before the executable name, or execute:
cd the_program_directory
./program_name
You must put the dot and slash in front of the program name or the program will NOT execute.  (This is a security feature not to put one's current directory on the path.  It makes "trojan horses" more difficult. A "trojan horse" is a malicious program that pretends to be something different than it really is.)  The dot means "the current directory", and the slash "/" is a separator between the directory name and the filename (exactly as "" in DOS).
You may check your path using:
echo $PATH
To learn how to change your PATH, or add your current directory to it, see the next answer.
If your executable is lost somewhere in your directory tree,  you may want to find it using (for example):
find / -name "netscape"
to find a file named "netscape" searching from the root directory "/". You may be able to achieve the same result faster using:
locate netscape
(Locate runs faster because it relies on a pre-built database of files on your system.  This database is updated by a background cron process that normally runs at night, so don't count on locate to find a file if you regularly switch off your computer for the night, or you are searching for a file that you just installed.)
Please note that the PATH is normally different for root than regular users (root's PATH includes /sbin and /usr/sbin whereas users' don't). Therefore users cannot execute commands located in the  "sbin" directories unless they specify the full path to the command. Also, if you become a superuser by executing the su command, you inherit the user's PATH, and to execute the command located in sbin, you need to specify the full path.
Conversely, if you need to learn where an executable which is on your PATH is located on your system (i.e., the executable runs by typing its name anywhere in the system, but you would like to know where it is), you may use something like this:
which netscape
which will show the full PATH to the executable program called "netscape".
The third possibility:  maybe the file is not executable.  If it should be, change the permissions to make it executable. E.g. (as root or the user who owns the file):
chmod a+x my_file
will make the file "my_file" executable for all users. Check if it worked using:
ls -l  my_file
Read here if you don't understand the output of this command or the whole "third possibility".

Please note that under Linux (or UNIX), it is not the file extension (for example .exe or .com or .bat) that makes a file executable.  The file needs an "executable file access mode" which is not unlike a "file attribute" under DOS.

How can I change the PATH?

Typically, you don't have to change your PATH, but it very useful to understand what PATH is.

The PATH is the list of directories which are searched when you request the execution of a program. You can check your PATH using this command:

echo $PATH
which, on my system , shows the PATH for the user "yogin" to be:
/opt/kde/bin:/usr/local/bin:/bin:/usr/bin:/usr/X11R6/bin:/home/yogin/bin
The ":" is a separator, therefore the above PATH represents a list of directories as follows:
/opt/kde/bin
/usr/local/bin
/bin
/usr/bin
/usr/X11R6/bin
/home/yogin/bin
Here is the output from the command "echo $PATH" run on my system on the account "root":
/opt/kde/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin:/root/bin
You can change the PATH for all users on the system by editing the file /etc/profile and adjusting (as root) the line starting with "PATH=".  I do it using the pico editor (as root):
pico -w /etc/profile
(The option -w turns off the wrap of long lines.)
Re-login for the change to take effect.  To set up the PATH for an individual user only, edit the file /home/user_login_name/.bash_profile (please note the dot in front of the filename--files starting with a dot are normally invisible, you have to use ls -a  to see them).
If you really want to have the current directory on your PATH, add "." (dot) to your PATH.  When used in the place when directory name is expected, a dot means "the current directory". The specification for the path in /etc/.bash_profile may then look like this:
PATH="$PATH:$HOME/bin:"."
export PATH
This command takes the contents of the environmental variable called PATH (as set for all users in /etc/profile), and appends to it the name of your home directory as set by the variable HOME with an attached "/bin"  and then a dot. Finally, the command assigns the resulting string back to the variable called PATH.  It is necessary to use the command "export" after modifying PATH or any other user-environment variable, so that the variable is visible outside of the script that sets it.
<< Previous Page << Previous Page (2/10)       Next Page >> (4/10) Next Page >>

[ Back to Linux Computing | Sections Index ]

 
Scroll Up

   About | Term of Use | Privacy | Adras | Tell a Friend | Advertise  

OSForge News RSS Feed