Home › Linux command line: first steps › Step 1
Lesson 1: ls, cd and mkdir
Step 1 of 5 in Linux command line: first steps · video 7:16
What you will learn
- Why ls hides dot files and how ls -a shows them
- Creating and entering directories with mkdir and cd
- What ., .. and a bare cd do
- Building relative and tilde-based paths such as ~/dir1/sub1
About this lesson
A first walk around the Linux file system from a fresh login. The lesson starts in the home directory, which is named after the user account, and shows how ls lists its contents. Plain ls hides any name that begins with a dot; these hidden files usually hold program configuration, and ls -a reveals them together with the special entries . (the current directory) and .. (its parent). Options such as -a change how a command behaves, and the manual pages describe them. You then create a directory with mkdir, enter it with cd, build a subdirectory inside it and check your position with pwd, which prints the full path back to the root of the tree. The last part covers paths: why a name that is not in the current directory gives an error, how to reach it with a relative path such as dir1/sub1, and how the tilde stands for the home directory from anywhere, including ~/.. and ~/../.. for the levels above it.
pwd prints the directory you are in (echo $HOME prints your home directory), and the root of the file system is the forward slash, /.Check yourself
1. Your home directory looks empty with ls, yet programs clearly keep settings there. Which command shows those files, and why were they hidden?
ls -a. Names that begin with a dot are hidden files, and plain ls leaves them out; they usually hold configuration that should not be changed casually. The -a option also lists the . and .. entries.
2. What happens when you type cd on its own, with no directory name?
You are taken straight back to your home directory, whatever directory you were in. That makes it the quickest way to recover when you are lost in the file system.
3. From your home directory you run ls sub1, but sub1 lives inside dir1. What happens, and what should you type instead?
ls reports that there is no such file or directory, because a bare name is looked up in the current directory only. Give the path relative to where you are, ls dir1/sub1, or use ls ~/dir1/sub1, which works from anywhere.
4. Which single command lists the directory two levels above your home directory, no matter where you currently are?
ls ~/../... The tilde expands to your home directory and each .. climbs one level towards the root, so the path works from any current directory.
Go deeper
This lesson comes from the course below - with the full set of lessons, demonstrations and practice.