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

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



-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

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"

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
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.12 (GNU/Linux)

iEYEARECAAYFAljZCdMACgkQBcgs9XrR2kYn2ACcD3n8rX7DGK6ODY+XYt+ni6+N
0pAAn0IiFfFlpgrcGgAwb52n/9Uypqch
=B3UM
-----END PGP SIGNATURE-----


Reply to: