Previously we looked at simple terminal commands like ls, cd. We know that ls output all files in the working directory. But in practice, command without options and parameters is almost useless. You may need to list special files or list files from the specified directory in more complex situations without going to it. This is why UNIX commands are run with options and parameters
command [options] [parameters]
There can be more than one option and parameter for a single command. For instance, we used a cd .. command to go to the previous directory. Dots .. are nothing more than parameters. Let’s see what parameters we have with the ls command.
ls -l
It displays a list of files in a long format. You can see that we get much more information by adding a simple option -l.
Let’s say we want to display files in a long format from a different than a working directory. Then we need to type in the path to the directory as a parameter.
ls -l /usr
ls command can go with several options. Additionally, we can include an -a option that will show files where the name starts with a period (hidden). So we can write:
ls -l -a
or same is
ls -la
Here is how to understand long file list:
drwxr-xr-x 2 pi pi 4096 May 25 20:47 Desktop
-rw-r--r-- 1 pi pi 5781 Feb 3 07:07 ocr_pi.png
drwxrwxr-x 2 pi pi 4096 Mar 10 12:20 python_games
-------- ------- ------- -------- ------------ -------------
| | | | | |
| | | | | File Name
| | | | |
| | | | +--- Modification Time
| | | |
| | | +------------- Size (in bytes)
| | |
| | +----------------------- Group
| |
| +-------------------------------- Owner
|
+---------------------------------------------- File Permissions
A couple handy default programs that can be helpful. First, one is called less. It is used to view text file contents. Navigating is done with Page Up and Page down buttons. Type
less –help
for more controls
Another handy program is called file. It helps to detect the file type. It looks at the file and tells what it contains. For instance, we can run
file ocr_pi.png
It displays that file is PNG, 48×48 size and 8 bit color RGBA.
I bet this information can be used in automated scripts when doing file processing.
This is by far not all that can be done with commands. Commands can be combined into long command lines with pipes. So with a single line, you can do complex tasks that would normally take some programming. But let’s leave this to later posts.