The shape of a command
Most commands follow the same pattern:
command -options arguments
- The command is the program to run, for example
ls. - Options (also called flags) change how it behaves. They start with a dash:
-l. - Arguments tell the command what to work on, for example a file or folder name.
The parts are separated by spaces. Let's see it with ls, the command that lists files.
Just the command
lsIn the terminal
student@vulntech:~$ ls Documents Downloads notes.txt projects
ls on its own lists what is in the folder you are in. Folders are shown in blue in a real terminal.
Adding an option
The -l option asks for the long format, with details about each item:
ls -lIn the terminal
student@vulntech:~$ ls -l total 2 drwxr-sr-x 2 student student 0 Oct 16 19:04 Documents drwxr-sr-x 2 student student 0 Oct 16 19:04 Downloads -rw-r--r-- 1 student student 30 Oct 16 19:04 notes.txt drwxr-sr-x 2 student student 0 Oct 16 19:04 projects
Don't worry about all the columns yet; you will learn to read them in module 2. For now notice that the same command shows more because of the option.
The -a option shows all files, including hidden ones. On Linux, a file is hidden when its name starts with a dot:
ls -aIn the terminal
student@vulntech:~$ ls -a . .bash_profile .hidden_note Documents notes.txt .. .bashrc .hushlogin Downloads projects
. and .. are special: they mean this folder and the folder above. You will use them a lot in module 2.
Combining options
You can give several options separately, or squeeze them together after one dash. These two commands do exactly the same thing:
ls -l -a
ls -laIn the terminal
student@vulntech:~$ ls -l -a total 6 drwxr-sr-x 5 student student 0 Oct 16 17:44 . drwxr-xr-x 3 root root 0 Oct 16 17:44 .. -rw-r--r-- 1 student student 32 Oct 16 17:44 .bash_profile -rw-r--r-- 1 student student 669 Oct 16 17:44 .bashrc -rw-r--r-- 1 student student 7 Oct 16 19:04 .hidden_note -rw-r--r-- 1 student student 0 Oct 16 17:44 .hushlogin drwxr-sr-x 2 student student 0 Oct 16 19:04 Documents drwxr-sr-x 2 student student 0 Oct 16 19:04 Downloads -rw-r--r-- 1 student student 30 Oct 16 19:04 notes.txt drwxr-sr-x 2 student student 0 Oct 16 19:04 projects student@vulntech:~$ ls -la total 6 drwxr-sr-x 5 student student 0 Oct 16 17:44 . drwxr-xr-x 3 root root 0 Oct 16 17:44 .. -rw------- 1 student student 9 Oct 16 19:04 .bash_history -rw-r--r-- 1 student student 32 Oct 16 17:44 .bash_profile -rw-r--r-- 1 student student 669 Oct 16 17:44 .bashrc -rw-r--r-- 1 student student 7 Oct 16 19:04 .hidden_note -rw-r--r-- 1 student student 0 Oct 16 17:44 .hushlogin drwxr-sr-x 2 student student 0 Oct 16 19:04 Documents drwxr-sr-x 2 student student 0 Oct 16 19:04 Downloads -rw-r--r-- 1 student student 30 Oct 16 19:04 notes.txt drwxr-sr-x 2 student student 0 Oct 16 19:04 projects
Long options
Many options also have a long, readable name that starts with two dashes. --all is the long name of -a:
ls --allIn the terminal
student@vulntech:~$ ls --all . .bash_profile .hidden_note Documents notes.txt .. .bashrc .hushlogin Downloads projects
Adding an argument
An argument tells ls which folder to list:
ls DocumentsIn the terminal
student@vulntech:~$ ls Documents welcome.txt
Options and arguments can be used together:
ls -l DocumentsIn the terminal
student@vulntech:~$ ls -l Documents total 1 -rw-r--r-- 1 student student 16 Oct 16 19:04 welcome.txt
echo takes arguments too. Every word you give it is an argument, and it prints them all:
echo one two threeIn the terminal
student@vulntech:~$ echo one two three one two three
Common mistake: Spaces matter.
ls -lis thelscommand with the-loption, butls-l(no space) is a command calledls-l, which doesn't exist.
Remember: command -options arguments. Short options use one dash (
-a), long options use two (--all).