FoundationLesson 1 of 3 in Shell BasicsFree preview

Navigation

The shell always has a current directory. Relative paths start from there.

pwd                 # print working directory
cd /var/log         # absolute path
cd nginx            # relative: /var/log/nginx
cd ..               # parent directory
cd ~   (or just cd) # your home directory
cd -                # back to the previous directory
ls -la              # long listing, including hidden files

Creating, copying and moving:

mkdir -p app/config/env    # -p creates missing parents, no error if it exists
cp file.txt backup/        # copy a file
cp -r src/ src-copy/       # -r for directories
mv old.txt new.txt         # rename (or move)
rm -r build/               # delete a directory tree. No recycle bin!

Globs are expanded by the shell before the command runs:

PatternMatches
*any characters
?exactly one character
[abc]one of a, b, c
{a,b}expands to both words (brace expansion, not a glob)

So rm *.log actually runs rm app.log error.log ….

The classic trap: * does not match hidden files (names starting with .). ls * will not show .env; use ls -a.

Tab completes names; press it twice to see choices. Use it all the time: it prevents typos in paths.

In interviews: "Difference between an absolute and a relative path?" An absolute path starts at / and works from anywhere; a relative path depends on the current directory.

Practice

Solve 3 of 4 to complete this lesson.

0/4 solved

Solve 3 more to complete this lesson, or move on and come back later.

Skip to next: Pipes and Redirection