How can I tell which parts of a command are the command name and its arguments?
Quick answer
Start by separating the command line into words. In a simple example such as ls -l notes.txt, ls is the command name, -l is an option, and notes.txt is an argument naming a file. More generally, after shell processing, the first remaining word is the command name and the following words are arguments; the program decides what those arguments mean. [S1] [S2]
The question, the details, the next step.
A practical checklist
Find the first word remaining after shell processing and label it the command name. [S1]
Mark file names, directory names, or other supplied values as possible target or value arguments.
Check the specific program’s documentation for what its options and arguments mean.
For a basic example, label
ls -l notes.txtas commandls, option-l, and file argumentnotes.txt. [S2]
A few more useful answers
Are options also arguments?
Does every command use `-` to mark an option?
Do not assume so. Option syntax and interpretation depend on the program; check that program’s documentation rather than relying on the ls example.
What does `ls -l` do if I do not name a file?
GNU ls acts on the current directory when no directory argument is supplied. That documented behavior is specific to GNU ls. [S2]
Sources
References used for this guide.
- [S1] Bash Reference Manual: Shell Operation gnu.org · Checked
- [S2] GNU Coreutils manual: ls invocation gnu.org · Checked
