Skip to content

Commands, flags and help

Every command you will type/learn will have the same structur:

command --flags arguments
  • The command is the program you’re running, like ls.
  • Flags (also called options) change how the command works. They start with - or --.
  • Arguments are the things it works on, They are usually files or folders.

Spaces separate these parts. This would be useful in coming chapters.

Terminal window
ls -l
# -rw-r--r-- 1 obay obay 48213 Nov 9 10:12 cats_are_better_than_dogs.jpg
# drwxr-xr-x 2 obay obay 4096 Nov 8 22:40 screenshots

-l means “long format”, with permissions, owner, size and date. Short flags (one dash, one letter) can be stacked, so ls -l -a -h and ls -lah are the same thing. (-a shows hidden files, the ones starting with a dot, and -h prints sizes like 48K instead of 48213.)

Long flags use 2 dashes and a whole word, like ls --all. They’re easier to read, which will help your script be more readable!

You might forget some flags, and that’s totally fine. Luckily, most of the commands has a help flag:

Terminal window
ls --help # a quick summary of what the command does
man ls # the full manual page

man opens a long page you can scroll with the arrow keys. Press / to search inside it and q to get out.

For short examples instead, install tldr. It shows a few common ways to use a command:

Terminal window
tldr tar

In fish, type a command followed by a dash (like ls -) and press Tab. Fish shows every flag with a short description.

Error messages are short and tell you what went wrong:

Terminal window
cd Picturs
# cd: The directory 'Picturs' does not exist

Here, the folder name has a typo. When a command fails, read the error message first.