[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: When specifying path to file - confused about ./ and ~/



On 03/27/2017 07:47 AM, tomas@tuxteam.de wrote:

On Mon, Mar 27, 2017 at 11:25:30PM +1100, David wrote:
On 27 March 2017 at 22:39, Richard Owlett <rowlett@cloud85.net> wrote:
On 03/27/2017 01:14 PM, Richard Owlett wrote:
 *Please avoid trying to briefly explain.*
 *_Please refer me to a good web page._

Sorry, richard: no web page, but perhaps something to start:

  ./ means "HERE"
  ~/ means "HOME"

True, but <grin or groan as appropriate ;>
my learning style is often dependent on examples more than definitions.

I learned that as a freshman engineering student in Fall 1961.
Only engineers and declared math majors took a specific calculus sequence. Our Teaching Assistant was a first semester grad student. His specialization was *PURE* mathematics. Our section [one of > 20] had 20 engineers and 2 math majors. He lectured rigorously on the theory. On the first of 3 course-wide exams we set some sort of record for the lowest class average [even the 2 math majors acing the exam didn't help;]. During a post-mortem, he asked for suggestions. The engineers replied "Give us examples!" He replied that's now to teach math, you need theory. We all but chanted "Give us examples!" He partially partially caved saying "Till the next exam. Then we'll go back to the right way [implication of lots of remedial homework]."
The next exam had us not at the top, but having a respectable class average.




You can move to other places with "cd" and ask where you
are currently with "pwd" or "echo $CWD", but your home
stays at "/home/richard" -- or wherever it is.

http://www.ee.surrey.ac.uk/Teaching/Unix/unix1.html
http://www.ee.surrey.ac.uk/Teaching/Unix/unix2.html

Sections 1.4, 1.6 part 2, and 2.1 demonstrate use of '.' and '~' to
represent directory names.

To the best of my knowledge, '.' is intrinsic to the filesystem

Yes and no (see below)

design, whereas expansion of '~' is handled by your shell.

Yes. The shell expands ~ to your current *home* directory (and it
expands ~foo to foo's home directory).

Now to the "yes and no": yes: every directory has two entries: ".",
which resolves to the directory itself, and "..", which resolves
to the directory's parent. This is the "intrinsic" part, i.e.
the "yes" part.

To the "no" part: in the shell, names of files are often resolved
using some default mechanism. If you invoke a command, then (unless
it's a shell builtin), the shell looks for this command as an
executable in one of the directories listed in the shell environment
variable PATH. Unless you give an explicit directory, as in
"foo/command", where the shell would look in directory foo (relative
to the current working directory, CWD [1]). Thus, ./command would
look in the current working directory.

I hope someone else here will correct or elaborate that statement if necessary.

So yes, correct, but some further explanation might help in
understanding how to use it in a shell.

regards

[1] Of course, if you start your path with /, it's an absolute
   path, like /usr/local/bin/foo/command.

- -- tomás




Reply to: