Search

INPUT · Slides

Looking up the tools themselves

01 / 08

When you meet a command you do not know

You have picked up over twenty commands so far. But Linux has hundreds of them. Learning them all is impossible, and you do not need to.

What matters is being able to look things up for yourself when you meet something unfamiliar. Professionals are looking things up all the time. What they remember is how to look.

This chapter closes with how to search for the tools themselves, rather than for files.

02 / 08

which — where does that tool live?

A command is in fact a file. Type ls and a file called /bin/ls is what runs.

which tells you where it lives.

which ls

This is the first move when you are told a command does not exist, because it tells you whether it is missing or you typed the name wrong.

~ $ which ls/bin/ls~ $ which sort/usr/bin/sort

03 / 08

When which says nothing

Type which cd and nothing comes out. Is cd not installed? Of course it works, though.

The truth is that cd is not a file — it is an instruction built into the shell itself. So it does not exist as a file.

type is what tells these "builtins" apart.

~ $ type lsls is /bin/ls~ $ type cdcd is a shell builtin

04 / 08

--help — the instructions are right there

Add --help to most commands and they explain themselves.

ls --helpgrep --help

What you get is a short list. Every flag (option) is laid out, so it is the fastest way to remember "what was that flag again?".

Quicker than searching the internet, and safer, because you get the description of the thing actually running here.

~ $ ls --helpUsage: ls [-1AaCxdLHRFplinshrSXvctu] [-w WIDTH] [FILE]...List directory contents

05 / 08

How to read Usage:

The Usage: on the first line of --help packs in the rules for writing it. The conventions are these.

  • [...]can be left out
  • FILE... — line up as many as you like
  • -abc — these flags are available (and can be stuck together)
  • A word in capitals — put your own word there

Read Usage: ls [-1Aa...] [FILE]... as "ls can leave out both the flags and the file names, and you can line up as many file names as you like".

06 / 08

This learning environment has 288 tools in it

What is inside this terminal is a single program called busybox. ls, grep and cat are all that one program wearing different hats.

Type ls -l /bin/ls and you can see it is a link to busybox.

You can see the list of tools available like this.

busybox --list

Unlike a real Linux, anything not in here cannot be used, so check the list when in doubt.

~ $ ls -l /bin/lslrwxrwxrwx 1 root root 7 /bin/ls -> busybox

07 / 08

There is no man here

On a real Linux the fullest instructions are man (the manual). man ls gives you dozens of lines of explanation.

But this learning environment does not carry the manual pages. All of them together run to tens of megabytes, which would make loading on a phone painfully slow.

Type it and you get no manual entry back. Use --help instead. On the Linux or Mac on your own computer you do get man, so remember it then.

08 / 08

Now have a go

The order you look things up in is roughly this.

1. which command — is it here, and where
2. command --help — how to use it, and the flags
3. busybox --list | grep name — is it available at all

Type those three and you can keep going even when you meet a command you do not know. Knowing how to look things up beats remembering them.