How to raise and take care of shell scripts: find commands
How do I find the command I need?
If one moves about the shell for some time, one is ready with a set of commands suitable for various situations - but nearly not all. And I think that nobody has learned all available options for all possible commands, isn't it? The good news: Your own systems (not only google) provides methods to get such information:
- apropos keyword: Looks for the keyword in the short descriptions of manual pages and displays a list of appropriate manuals. Sometimes the list is too long, in this case you can try to limit the result using a command like grep.
- man command: Displays the command's manual pages including it's available options,
description, exit codes, samples, related commands etc. Almost all manual pages follow a standard structure.
Sometimes you are looking for a shell command's description but see a manual of a C system call. In this case you must call the man command for the wanted section: man 1 write (or - on unix systems: (man -s 1 write). The man man command describes, which sections exist and which manuals you can find in these sections. A detailed description how to use the command you will also find there.
- info command: info is the official GNU way to present manuals, but it's not my favorite way - I like man much more. However - sometimes you will find the complete information for a command only there. To learn about the handling: Use info info.
The three commands described above are actually the only ones you really have to know ;-) but the following could be useful too, if you don't exactly know what you are dealing with:
- type command: Displays the path in case of commands, which could be found in the system's search path (variable $PATH), displays is a shell builtin in case of commands, which are part of your shell, displays is a function for a function available in your current shell, displays is aliased to ... for a defined alias (another name for a command, optionally with predefined options).
- which file: Displays the path for a file found in the search path, displays nothing in all other cases.
- file /path/to/file: Tries to identify the file type and displays it ("shell script", "executable", "ascii text", ...). The output is not 100% perfect for every single file because the program does not analyse the complete file's content, but it is useful for a quick overview. Where you can find more about it? Exactly: man file!