unix / chmod question

Associate
Joined
21 Oct 2008
Posts
1,679
Location
Mooching... in your house
This is purely out of curiosity, i have a terminal app that I wanted to run... and it was sitting in my downloads folder, to get it to run I had to chmod +x it, then run it by typing ./appname

I'm curious what the "./" does... any ideas?
 
it is a run command afaik! :)

./ and then anything after this will run the file :) such as in windows you double click on .exe
 
Linux demands a directory name when executing a file.
there are a few shortcuts for common directory names :
. current directory
.. parent directory
~ the home directory of the current user

assuming there is a file called /home/steve/myfile :

/home/steve/myfile would start myfile from anywhere.
~/myfile will do the same if you're user steve
./myfile will do the same you're in the directory /home/steve already
 
I'm curious what the "./" does... any ideas?
It's just explicitly saying the program is in the current directory. If that wasn't required, and your program was called for example "cd", there'd be ambiguity about what to run when you typed "cd".
 
Just to add, the default lists of directories searched for executable files is stored in the enviromental varaible $PATH.

Code:
# echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin:/opt/kde/bin:/opt/NX/bin:/usr/bin/core_perl:/opt/qt/bin

So if you run "appname" without the ./ and it's stored (and chmod +x'ed) in one of the directories in PATH then it will run, otherwise you have to fully quantify the path to appname.
 
The . is a relative path identifier. It means "here". ".." means the parent directory. In certain versions of *nix, "..." means the grandparent directory although this is rare these days.

Any command you wish to run that is not in a directory explicitly listed in your PATH setting must have its location identified. That means you can use an absolute path - /blah/blah/command - or a relative path, which will vary according to where you are.

Knowing your directory structure is crucial to efficient use of a command shell. The advent of the GUI has made people scared of command lines but the Unix command line is far more powerful than any GUI. Through combining commands and chaining the outputs, all manner of wonderful things can be achieved that would be utterly impossible in a GUI without writing an explicit app to do each one.
 
Also be aware that chmod +x can set the executable flag for some users and not others. Depending on your UMASK. Chmod 755 or 775 is a good way to set it.
 
Also be aware that chmod +x can set the executable flag for some users and not others. Depending on your UMASK. Chmod 755 or 775 is a good way to set it.

Or just use u,g,o in front of the +x (or r or w) to set the executable flag for the owner, group or other. Much easier than remembering the bit masks (although not quite as l33t it's true). But i dont switch my machine off with 'init 6' even if it is less characters than 'reboot' :cool:
 
What's hard about remembering 4=r, 2=w, 1=x. It only gets hard when you start trying to remember how to set sticky bits and what the hell they are!
 
Back
Top Bottom