Hacker News new | past | comments | ask | show | jobs | submit login

Very nice article. I like the coverage of "." (this directory or cwd) to show new users how to execute programs in /home, etc. One often over-looked feature of "." is that it can be used on non-executable files as well. For example, it can be used to removed a file named -f:

rm ./-f

That was actually a question for me during a Google phone interview. I kid you not.




"." can be used any place you need to explicitly indicate a file in the current directory. Your "remove file '-f' from the current directory" is a fine example, but your "...can be used on non-executable files..." makes me cringe slightly - it won't magically execute a non-executable file (I do realize this is not what you mean to say...)

It works exceptionally well if you need variables for directories in a shell script. For example, if your script needs $PKG_HOME to be defined, it could be set as "/usr/bin/pkg_home/" or "./" to be prepended to other paths in the script. Setting it to "" would surely work as well as "./" but being explicit improves readability and communicates the author's intent more clearly.

So, absolute paths start with "/", relative paths may avoid "." and ".." and "/", but an explicit relative path would use "." and/or ".."


You can easily trip up even experienced Linux users with examples (like that one) from the Unix Hater's Handbook.




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: