4

I am using a Mac OS 10.10.3 and I am new to using linux commands. This is the doubt I have-

The present working directory: /dir_name

when I run this command: cd ~

The directory path changes to: ~dir_name

What does the ~ or / change in the directory path mean?

Keith Thompson
  • 254,901
  • 44
  • 429
  • 631
Alex Jose
  • 278
  • 3
  • 17
  • 1
    Mac OS does not use the Linux kernel and is not a Linux system. `cd` is a shell command, not a Linux command. Both Mac OS (version 10 and later) and Linux are UNIX-like systems. – Keith Thompson Apr 30 '15 at 18:31
  • Thanks @KeithThompson for clearing up my fundamentals – Alex Jose Apr 30 '15 at 19:26

4 Answers4

5

~ by itself is equivalent to $HOME. It refers to your home directory, typically something like /home/yourname.

~foo refers to the home directory of the user foo.

Both these uses of ~ are handled by the shell. That means, for example, that if you call fopen("~/foo/file.txt", "r") in a C program, it won't expand ~ to your home directory; rather, it will look for (and probably not find) a directory literally named ~ in the current directory.

/ is the root directory.

Invoking cd with no argument is equivalent to cd ~ or cd $HOME.

Keith Thompson
  • 254,901
  • 44
  • 429
  • 631
2

cd ~ redirect you to home directory. It is equivalent to cd $HOME

cd / redirect you to root directory

Steephen
  • 14,645
  • 7
  • 40
  • 47
1

~ is shorthand for your home directory. / will change to the root directory. So

cd ~ changes directory to your home directory

cd / changes to root directory.

Dan Field
  • 20,885
  • 5
  • 55
  • 71
0

~ is shorthand for current user's home directory or that is yours.

/ is shorthand for root directory

You can pwd command (outputs the path) to see what's the difference.

cd ~
pwd
cd /
pwd
roxxypoxxy
  • 2,973
  • 1
  • 21
  • 28