The shell, the prompt and moving around
The shell is the program that reads the commands you type and runs them. Everything on Linux lives in one tree of folders that starts at /, and three commands get you around it: pwd shows where you are, ls shows what is there, and cd moves you.
What you are looking at
When you open a terminal or connect to a server, a shell starts and shows a prompt. Bash is the most common shell on Linux. The prompt usually shows your user name, the machine and the folder you are in, then $ for a normal user or # for the all-powerful root user. You type a command, press Enter, and the shell runs it.
asha@build01:~$ pwd /home/asha asha@build01:~$ ls notes.txt projects scripts asha@build01:~$ cd projects asha@build01:~/projects$ ls -la drwxr-xr-x 4 asha devs 4096 Oct 9 10:02 . drwxr-xr-x 9 asha devs 4096 Oct 9 09:40 .. -rw-r--r-- 1 asha devs 220 Oct 9 09:41 .gitignore drwxr-xr-x 3 asha devs 4096 Oct 9 10:02 payroll
One tree, starting at /
Linux has no drive letters. Everything hangs off a single root directory written /. Folders are separated by forward slashes, so /home/asha/projects means the folder projects, inside asha, inside home, inside the root. Names are case-sensitive: Report.txt and report.txt are two different files.
| You type | It means |
|---|---|
/ | The root of the whole file system |
~ | Your home directory, for example /home/asha |
. | The directory you are in now |
.. | The parent directory, one level up |
/var/log/app.log | An absolute path: starts with / and works from anywhere |
logs/app.log | A relative path: starts from wherever you are now |
The three commands you use most
pwd(print working directory) shows the folder you are in.lslists what is there.ls -ladds sizes, owners, dates and permissions.ls -aalso shows hidden files, whose names start with a dot.cd foldermoves into a folder.cd ..goes up one level,cdon its own goes home, andcd -returns to where you were before.
Getting help
Most commands explain themselves. man ls opens the manual page for ls (press q to quit), and ls --help prints a shorter summary. Options usually come in a short form with one dash (-a) and sometimes a long form with two (--all). Short options can be combined: ls -la is the same as ls -l -a.
You are in /home/asha/projects/payroll. Which command takes you up to /home/asha/projects?
Show a hint
Two dots mean the parent directory.
Show the solution
cd .. moves up one level. cd /home/asha/projects or cd ~/projects would also work.
Examples are for learning. Run commands and jobs only on a system you are authorised to use, such as a training or test system, and never on production without approval.
Common mistakes
/ is the root of the whole system and ~ is your own home directory. cd / and cd ~ take you to very different places.
Build.sh and build.sh are different files. If a file 'is not there', check the capital letters first.
A # prompt means you are root, and nothing will stop a mistake. Use your own account and sudo for the single command that needs it.
What you will see at work
- Build servers, Jenkins agents and most cloud machines are Linux, and you will reach them through a terminal far more often than through a desktop.
- Runbooks often give absolute paths so that the commands work whatever folder you start in. Copy them exactly.
- On z/OS UNIX the same commands work, but files can be EBCDIC or ASCII. If the text looks like rubbish, it is usually an encoding question, not a broken file.
Key terms
Check your understanding.
Take this lesson's quiz and save your progress. Free.