Unit 2: Reading and checking files · Lesson 3 of 6 · 12 min
Getting help
--help, help and type: answers without leaving the terminal.
mission
- You are
- You are working on a server with no internet and no manual pages.
- Situation
- You need an option you cannot remember, and you want to be sure which program actually runs when you type a name.
- Goal
- Get usage help for programs and builtins, and find where commands live.
Where help lives
- typeWhat will run: builtin, alias or program
- --helpUsage for programs
- helpUsage for builtins
- manFull manuals, when installed
Programs and builtins
Some commands are programs on disk. Others are built into bash. type tells you which.
type cd cd is a shell builtin type ls ls is /usr/bin/ls type -a echo echo is a shell builtin echo is /usr/bin/echo echo is /bin/echo
you should see type -a lists every match in order. The first one wins.
Read the usage
ls --help | head -n 1 Usage: ls [OPTION]... [FILE]... help cd | head -n 1 cd: cd [-L|[-P [-e]] [-@]] [dir] ls --version | head -n 1 ls (GNU coreutils) 9.4
defender tip Pipe long help into grep: ls --help | grep -i time finds the sorting options in a second.
Search inside help text
Help text is plain text, so grep finds the one option you need. compgen -b lists every builtin.
ls --help | grep -- '--sort=' use of --sort=none (-U) disables grouping --sort=WORD sort by WORD instead of name: none (-U), size (-S), with --sort=time, sort by WORD (newest first) compgen -b | wc -l 61
you should see The --sort option and 61 builtins.
What a defender takes away
- 1--help for programs, help for builtins.
- 2type and which show what will really run.
- 3Grep the help text instead of reading all of it.
Questions
0 of 2 solved
Answer each one from what you find on your lab machine.