Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Development Tools

File PATH not working

I can't read a document named cowz wth less command, without typing the direct path.

I have saved in .bashrc PATH=/home/treehouse/tic/tac/toe/cowz:$PATH

That is the location of the nano doc cowz I made, when I type less cowz, it says no such files or directory. But I added it to the PATH as you can see, yet I have to type

less /home/treehouse/tic/tac/toe/cowz to open it, i thought the entire point of PATH was so you didn't have to write the entire path name of something you wanted to run ?

I thought the .bashrc PATH would tell the less program where the cowz file I saved was?

1 Answer

Stone Preston
Stone Preston
42,016 Points

hmm. Id say you are correct when you say

> i thought the entire point of PATH was so you didn't have to write the entire path name of something you wanted to run ?

Its used for telling your shell where programs/commands are located so that you can run them without specifying a full path to the program itself. you can just type the name and the shell goes looking for it using the directories specified in the path variable

but in this case the thing you are running is the less program. so when you type less cowz the shell goes through all the directories in your path looking for the less program file, it doesnt look for the argument you pass to the less command as well. In this case since all you pass is the file name, thats a relative path meaning that the cowz file is in the current directory (which in your case the file is not in that directory so the command wont work)

Of course I may be wrong, but the only thing ive seen the path used for is for specifying the directory of executable files, not things like text files and such

If you wanted to be able to able to reference a file without typing out the full path and what not, you might want to use a symlink to the root directory or something

Not to bug you or anything but how then does the less program run cowz if I cd to the directory first, example: cd /home/treehouse/tic/tac/toe/cowz

if I cd to that directory I can type run cowz without typing in the full path because it looks in the current directory only ?

Thank you for taking the time to correct me again stone.

I haven't learned about symlink yet, I'll look into it.

So what does PATH work for then? Like just exe programs ?

Stone Preston
Stone Preston
42,016 Points

Well using less cowz is using a relative path. so since all you wrote is the file name, less looks in the current directory for a file called cowz. if the cowz file was located in a directory above the one you are in you could have used less ../cowz and it would work as well. Bear in my mind im not a linux/command line expert or anything haha, ive just done the treehouse course and some additional reading so take this with a grain of salt

Stone Preston
Stone Preston
42,016 Points

Conquering the Command Line is a pretty good free ebook if you want more info. It covers symlinks and some stuff not covered in the treehouse course