Your First Commands
Talking to Your Computer
Section titled “Talking to Your Computer”Now that lash is installed, let’s type some commands. A command is just a word (or a few words) that tells the computer to do something. You type the command, press Enter, and the computer responds with text called output.
Saying Hello
Section titled “Saying Hello”Type this and press Enter:
echo "Hello, world!"You should see:
Hello, world!The echo command simply repeats back whatever you give it. It is the
computer equivalent of a parrot.
Where Am I?
Section titled “Where Am I?”Your terminal is always “standing” inside a folder on your computer. To find out which folder you are currently in, type:
pwdThis stands for “print working directory.” A directory is just another word for folder. The output might look something like:
/home/yournameThat is your home folder — the starting point for your files.
What Is in This Folder?
Section titled “What Is in This Folder?”To see the files and folders in your current location, type:
lsThis stands for “list.” You will see the names of everything in the current folder, printed out as text.
Reading a File
Section titled “Reading a File”If you want to see what is inside a text file, use cat:
cat somefile.txtThe contents of the file will be printed directly in the terminal. The name
cat is short for “concatenate,” but most people just use it to read files.
The Prompt
Section titled “The Prompt”Notice the colorful line that appears before your cursor every time lash is ready for a new command. This is the prompt. It shows you which folder you are in, so you always know where you are. When the prompt is showing, lash is waiting for you to type something.
Combining Commands with Pipes
Section titled “Combining Commands with Pipes”Here is where things get interesting. You can send the output of one command
into another command using the pipe symbol (|). Think of it as a real
pipe — data flows through it from left to right.
For example, to list your files and then sort them alphabetically:
ls | sortThe ls command produces a list, and sort puts that list in order. You can
chain as many commands as you want:
ls | sort | head -5This lists files, sorts them, and then shows only the first 5 results.
head -5 means “give me the first 5 lines.”
Running Multiple Commands
Section titled “Running Multiple Commands”Sometimes you want to run two commands one after the other. Use a semicolon
(;) to separate them:
echo "Step 1"; echo "Step 2"Both commands will run in order. The semicolon is like saying “and then.”
Did It Work? Exit Codes
Section titled “Did It Work? Exit Codes”Every command finishes with a hidden number called an exit code. If
everything went well, the exit code is 0 (zero means success). If something
went wrong, it is a number other than zero.
You can check the exit code of the last command you ran:
echo $?Try it after a successful command, and you will see 0. Now try running
something that does not exist:
nonexistent_commandecho $?You will see a number other than zero, telling you something went wrong. lash’s prompt also shows this visually — the prompt changes color when a command fails.
Stopping a Command
Section titled “Stopping a Command”Sometimes a command takes too long, or you realize you made a mistake. Press Ctrl + C (hold the Control key and press C) to cancel whatever is currently running. This brings you back to the prompt safely.
A Quick Practice Session
Section titled “A Quick Practice Session”Try these commands on your own:
echo "My name is awesome"pwdlsecho $?You just ran four commands, checked your location, listed your files, and verified that everything succeeded. That is a solid start.
Next up: navigating your files and folders like a pro.