Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Start a free Courses trial
to watch this video
In the shell, there are a variety of symbols that have special meanings. We've already seen a couple special symbols: `.` and `..`, which are used to indicate the current and parent directories. This video will look at those symbols a little closer. We'll also look at the tilde symbol, which represents the user account's home directory.
-
.
indicates the current directory.- It may not seem that useful, at first.
-
cd .
just changes to the same directory. - You can use
.
in the paths of files, like:cat ./bird.txt
- But
cat bird.txt
does the same thing, and takes two fewer keystrokes:cat bird.txt
treehouse:~/workspace$ pwd
/home/treehouse/workspace
treehouse:~/workspace$ cd .
treehouse:~/workspace$ pwd
/home/treehouse/workspace
treehouse:~/workspace$ cat ./bird.txt
There is a bird here, looking up at the statue with interest.
treehouse:~/workspace$ cat bird.txt
There is a bird here, looking up at the statue with interest.
- There are a few situations in which
.
is very useful, however.- One is in running executable programs.
- Let me change to a directory where I have an executable stored:
cd offices/web_agency/mcgavren/
ls
- Here I have an executable file named
hello.sh
.- On Unix-like systems, as a safety feature, you can't run an executable file just by typing its name:
hello.sh
- You have to provide the executable's name as part of a path.
- Using only what we've learned so far, that would mean that you have to change to the parent directory:
cd ..
- And then type the name of the directory that contains the executable, a slash, and the name of the executable file:
mcgavren/hello.sh
- You can see that it runs, and prints the message "Hi there!".
- But that's a pain, if you're already in the same directory as the executable.
- So you can form a path just by using
.
to represent the current directory, a slash, and the name of the executable:./hello.sh
- On Unix-like systems, as a safety feature, you can't run an executable file just by typing its name:
treehouse:~/workspace$ cd offices/web_agency/mcgavren/
treehouse:~/workspace/offices/web_agency/mcgavren$ ls
hello.sh
treehouse:~/workspace/offices/web_agency/mcgavren$ hello.sh
bash: hello.sh: command not found
treehouse:~/workspace/offices/web_agency/mcgavren$ ./hello.sh
Hi there!
Executable files are outside the scope of this course. But you can learn how to write a shell script, make it executable, and run it here.
- Another special symbol we've seen is
..
, which represents the parent directory.- We've already made extensive use of
cd ..
to change up a directory. - You can also use
..
as an argument for commands. - For example, you can list the contents of the parent directory by running
ls ..
:ls ..
- You can use
..
as part of a path. - Suppose we want to change to the
dentist
directory that's within the parent directory. - We don't have to
cd ..
and thencd dentist
. - Instead, we can type
cd ../dentist
:cd ../dentist
- The operating system will realize this means "the parent directory's
dentist
subdirectory", and change directly to it:pwd
- We've already made extensive use of
treehouse:~/workspace/offices/web_agency/mcgavren$ cd ..
treehouse:~/workspace/offices/web_agency$ ls ..
dentist lawyer web_agency
treehouse:~/workspace/offices/web_agency$ cd ../dentist
treehouse:~/workspace/offices/dentist$ pwd
/home/treehouse/workspace/offices/dentist
- Now for a symbol we haven't looked at thoroughly, the "tilde":
~
- Like
.
and..
,~
is a reference to a directory, your user account's home directory. - We can type
cd ~
to go to that home directory from anywhere on our system:cd ~
- You can see that the directory path in the prompt changes to just a
~
character. - That's not the real path of this directory. To see the real path, we can run
pwd:
pwd` - You can see we're actually in a directory named
treehouse
, which is in a directory calledhome
, which is in the root directory. - The name of the
treehouse
directory matches the name of the user account we're logged in as. - We can see that account name if we run the
whoami
command:whoami
- Each user account has its own subdirectory under the
home
directory. - Windows and Mac machines have equivalents to the
home
directory, at different paths:- On Windows, it's at
C:\Users\
(assumingC:
is your primary hard drive). Also note that in the Windows Command Prompt, the~
shortcut doesn't work. - On Mac OS, it's at
/Users/
.
- On Windows, it's at
- If we run
ls /home
, we'll see there's only thetreehouse
directory. - That's because the
treehouse
account is the only one that's been created on this system. - If there were other users, they would be listed here, too.
- Like
treehouse:~/workspace/offices/dentist$ cd ~
treehouse:~$ pwd
/home/treehouse
treehouse:~$ whoami
treehouse
treehouse:~$ ls /home
treehouse
- So what's so special about your home directory? Why is there a special shortcut for it?
- For ordinary users, their home directory is really the only one on your system that they should make changes to.
- The root directory is filled with a dozen subdirectories or more.
- Each of these directories is filled with files that the operating system relies on to run.
- If you went around making changes in these directories, you could render your operating system unusable.
- (Don't worry, Unix-like machines are set up so that ordinary users simply get an error message if they try to make changes in the root directory.)
- Your home directory is the only directory on your system that's specifically intended for you to work in and make changes.
- And that's why there's a convenient
~
shortcut to help you access it.
- Just like
.
and..
, you can use~
as part of a file or directory path.- To change to the
workspace
directory within your home folder, you can runcd ~/workspace
:cd ~/workspace/
- This will work no matter where you are on your system.
- For example, I could change to the
/etc
directory within the root directory again:cd /etc
- And if I run
cd ~/workspace/
, I'll be taken directly there. - Notice that I'm not typing out the whole directory name; that's because tab completion works with paths that start with
~
, too. - These are not absolute paths, because the home directory is in different places for different users.
- Still, using
~
does work like an absolute path, because it lets you reference files and subdirectories in your home directory from anywhere on your system. - Let's print out that Starbunks menu one more time, using a path relative to the home directory:
cat ~/workspace/mall/starbunks/menu.txt
- To change to the
treehouse:~/workspace$ cd ~
treehouse:~$ cd ~/workspace/
treehouse:~/workspace$ cd /etc
treehouse:/etc$ cd ~/workspace/
treehouse:~/workspace$ cat ~/workspace/mall/starbunks/menu.txt
Venti Iced Mocha Soy Latte (with Whip): $29.99
Grande Hot Americano: $34.99
Tall Hot Chocolate: $24.99
Before I start, I'm gonna make sure that I'm in my workspace directory. 0:00 In the shell there are a variety of symbols that have special meanings. 0:05 We've already seen a couple special symbols, dot and dot-dot, 0:08 which are used to indicate the current and parent directories. 0:12 This video will look at those symbols a little closer. 0:15 We'll also look at the tilde symbol, 0:18 which represents the user account's home directory. 0:20 Dot indicates the current directory. 0:23 It may not seem that useful at first. 0:26 Cd dot just changes to the same directory. 0:28 You can use dot in the paths of files, like cat ./bird.txt. 0:32 But cat bird.txt does the same thing. 0:38 It takes two fewer keystrokes. 0:40 There are a few situations in which dot is very useful, however. 0:43 One is in running executable programs. 0:47 Let me change to a directory where I have an executable stored, 0:50 cd offices/web_agency/mcgavren/. 0:54 Let me list the files that are here. 0:57 Here I have an executable file named hello.sh. 1:01 The sh is short for shell script. 1:04 If you come from Windows, 1:07 you're probably used to executable files all ending in .exe. 1:08 But on a Linux system like this one, 1:13 executable files can have any extension you want. 1:15 On Unix-like systems, as a safety feature, 1:19 you can't run an executable file just by typing its name. 1:21 You have to provide the executable's name as part of a path. 1:25 Using only what we've learned so far, that would mean you have to 1:29 change to the parent directory and then type the name of the directory that 1:32 contains the executable, a slash, and the name of the executable file. 1:36 But that's a pain if you're already in the same directory as the executable. 1:41 So you can form a path by using dot to represent the current directory, a slash, 1:46 and the name of the executable, ./hello.sh. 1:51 Executable files are outside the scope of this course, 1:56 but if you'd like to know more about them, see the teacher's notes. 1:59 Another special symbol we've seen is dot-dot, 2:03 which represents the parent directory. 2:06 We've already make extensive use of cd dot-dot to change up a directory. 2:09 You can also use dot-dot as an argument for commands. 2:14 For example, 2:17 you can list then contents of the parent directory by running ls dot-dot. 2:18 You can also use dot-dot as part of a path. 2:23 Suppose we wanna change to the dentist directory that's within the parent 2:26 directory. 2:30 We don't have to cd dot-dot and then cd dentist. 2:32 Instead, we can type cd ../dentist. 2:35 The operating system will realize this means the parent directory's 2:40 dentist's subdirectory and change directly to it. 2:44 Now for a symbol we haven't looked at thoroughly, the tilde. 2:49 Like dot and dot-dot, tilde is a reference to a directory, 2:53 your user account's home directory. 2:57 We can type cd ~ to go to that home directory from anywhere on our system. 2:59 You can see that the directory path in the prompt changes to just a tilde character. 3:05 That's not the real path of this directory. 3:10 To see the real path we can run pwd. 3:13 You can see we're actually in a directory named treehouse, 3:15 which is in a directory called home, which is the root directory. 3:18 The name of the treehouse directory matches the name of the user account we're 3:24 logged in as. 3:27 We can see that account name if we run the whoami command. 3:28 Each user account has its own subdirectory under the home directory. 3:33 Windows and Mac machines have equivalents to the home directory at different paths. 3:38 See the teacher's notes if you'd like more info. 3:42 If we run ls/home, we'll see there's only the treehouse directory. 3:45 That's because the treehouse account is the only one that's been created on 3:50 this system. 3:53 If there were other users, they'd directories here too. 3:55 So what's so special about your home directory? 3:59 Why is there a special shortcut for it. 4:01 For ordinary users, 4:04 the home directory is really the only one on the system you should make changes to. 4:05 The root directory is filled with a dozen subdirectories or more. 4:10 Each one of these directories is filled with files that 4:15 the operating system relies on to run. 4:17 If you went around making changes in these directories, 4:21 you could render your operating system unusable. 4:23 Don't worry, Unix-like machines are set up so that ordinary users simply get an error 4:26 message if they try to make changes in the root directory. 4:31 Your home directory is the only directory on your system that's 4:35 specifically intended for you to work in and make changes. 4:38 And that's why there's a convenient tilde shortcut to help you access it. 4:42 Just like dot and dot-dot, you can use tilde as part of a file or directory path. 4:47 To change of the workspace directory within your home folder, 4:53 you can run cd ~/workspace/. 4:56 This will work no matter where you are on your system. 5:00 For example, I could change to the /etc directory within the root directory again. 5:03 And if I run cd ~/workspace/, I'll be taken directly to the workspace directory. 5:08 You don't have to type out the whole directory name. 5:15 That's because tab completion works with paths that start with tilde too, so I 5:18 can say cd ~/wo tab and it'll complete the name of the workspace directory for me. 5:24 These are not absolute paths that I'm showing you 5:32 because the home directory is in different places for different users. 5:34 Still, using tilde does work like an absolute path 5:39 because it lets you reference files and 5:42 subdirectories in your home directory from anywhere on your system. 5:44 Let's print out that Starbunks menu one more time using a path relative 5:48 to the home directory, cat~/workspace/mall/starbunks/menu.txt. 5:53
You need to sign up for Treehouse in order to download course files.
Sign up