Command line interface type
The command line interface is primarily designed according to the POSIX and GNU specifications.
This article cites a significant portion of the reference page description below. If you would like to see more details, please visit the reference site directly.
Reference: [Linux Command Option Customs (General Option List)](https://debimate.jp/2019/02/23/linux-command-option%E3%81%AE%E6%85%A3%E7 % BF% 92% E4% B8% 80% E8% 88% AC% E7% 9A% 84% E3% 81% AAoption% E4% B8% 80% E8% A6% A7 / # Command_Option% E3% 81% AB% E9% 96% A2% E3% 81% 99% E3% 82% 8BPOSIX% E8% A6% 8F% E6% A0% BC)
POSIX
POSIX 【 Portable Operating System Interface 】 POSIX is a standard that defines standards such as how to call from a program, mainly for functions common to UNIX-based OSs.
API specifications and standard library functions for using system calls that call kernel functions from C language are defined, and programs developed using only POSIX specifications are the same for any POSIX-compliant OS. Can be operated.
In addition to the API, standards are also set for the shell command system, process and thread specifications, file and directory configurations, system database formats such as password files, and archive file formats.
POSIX optional standards
—Options start with «-» and the option string is one alphanumeric character —When using multiple options, you can omit «-» and connect (example: «-a -b -c» can be written as «-abc») —Put a space between the option and the option argument —Options must exist before command line arguments —Options can be omitted when executing the command line
GNU
**GNU 【 GNU is Not Unix 】 ** GNU is a project to develop and publish a group of software related to UNIX-like OS using only free software (especially open source software). It was founded by Richard M. Stallman and is being promoted by the Free Software Foundation (FSF), which he represents.
The names of software provided as part of GNU often include «GNU» as part of it (GNU Emacs, etc.) or begin with «g» (gcc, glibc, etc.).
GNU optional standard
In addition to recommending compliance with the POSIX standard, the following specifications have been added.
-“–” And optional long name support (eg “–version” corresponding to “-v”) —Support for concatenated options and optional arguments (eg –test = path) —Minimum support for «–version» (version display) and «–help» (help or Usage display)
List of common options
Short Option | Long Option | Function (Command that implements the option) |
---|---|---|
a | all | Processing for all files and all users (du, nm, uname) |
b | bytes、blocks | Set the size of bytes and blocks (du, df) |
c | cmd | Set Command and Option to pass to subprocess (bash, python) |
d | debug | Output debug message (many Commands) |
e | exclude | Set exclusion target (example: file)(rync) |
f | file | Set the file to use (awk, make, sed, tar) |
g | group | Set group (install) |
h | help | Show help on using Command (many Commands) |
i | inodes | Show inode information instead of block usage(ls、df) Besides inodes, interactive also exists (rm, mv) |
j | jobs | Set the number of jobs (make) |
k | keep | Suppress deletion of files, messages, resources, etc. (passwd, bzip) |
l | list | Show list of files, directories, etc. (unzip, ls) |
m | mode | Permission settings (install, mkdir) |
n | number | Display numbers (example: line numbers)(head、tail、grep) |
o | output | Output file name and output file path settings (many Commands) |
p | a diversity of | See references |
q | quiet | Suppress message output (many Commands) |
r | recursive | Perform processing recursively (grep, chgrp, choose, cp, ls, diff, rm) |
s | silent | Suppress message output (many Commands) |
t | a diversity of | See references |
u | update | Perform update (apt, yum, cp, mv, tar) |
v | version | Display program version information (many Commands) |
w | width | Width setting (ls, ptx) |
x | extract | Display a list of files extracted from archives (tar, zip) |
y | yes | In the user confirmation process, it is considered that the user answered yes to all confirmation items (apt, yum). |
z | zip(compress) | Enable compression (tar) |
Command Line Options and Arguments Briefly
This is part 3 of the series Linux Command Line Interface. Please check earlier articles to get the grasp of current one.
Introduction
Commands are generally followed by one or more options, followed by arguments. Options describes the command behaviour and arguments are generally files and folders. Every command associates with its own options. The general format for commands looks like this.
$ command options arguments
Linux commands options and arguments examples
Let us consider the ls command. Most commonly used options that comes with ls command are
Now Let’s use those options. Don’t forget that default working directory is your home directory when you open the terminal. When using ls command, it shows files and folders of current working directory.
[email protected] ~ $ ls Desktop Downloads Pictures Templates Documents Music Public Videos
ls with -a option
Using ls command with -a option shows following result. It is same for both -a and –all. –all is called long option of -a.
[email protected] ~ $ ls -a . .config .gconf .mozilla Videos .. .dbus .gnome2 Music .Xauthority .bash_history Desktop .gnome2_private Pictures .xsession-errors .bash_logout .dmrc .ICEauthority .profile .cache Documents .linux Public .cinnamon Downloads .local Templates
Files or directories that starts with period (.) are hidden. You can’t see these through file manager. Take another example for which we list the contents in /usr directory.
[email protected] ~ $ ls -a /usr . .. bin games include lib local sbin share src
Multiple arguments can be used with options like the command ls -a ~ /usr. Here arguments are home directory ~ and /usr directory.
ls with -l option
Let’s get to another option -l. Using -l with ls command shows long description of listing.
[email protected] ~ $ ls -l /usr total 120 drwxr-xr-x 2 root root 49152 Apr 11 22:56 bin drwxr-xr-x 2 root root 4096 Nov 27 03:15 games drwxr-xr-x 19 root root 4096 Apr 8 09:52 include drwxr-xr-x 178 root root 32768 Apr 8 10:41 lib drwxr-xr-x 10 root root 4096 Nov 27 02:59 local drwxr-xr-x 2 root root 12288 Apr 8 09:53 sbin drwxr-xr-x 293 root root 12288 Apr 8 21:10 share drwxr-xr-x 5 root root 4096 Nov 27 03:15 src
Long format has nine fields. The first field/column drwxr-xr-x is the indication of file permissions by different users. First character (d) indicates file type (d means directory). Next three characters indicate file permissions for owner. Next three characters are access rights for group users and the last three characters for other users permissions existed on your computer. rwx stands for read, write and execute. About file permissions comes in later chapters.
The second field/column (2) indicates no. of hard links that file/folder consists of. The concept of hard links comes later.
The third field/column (root) is file owners name.
The fourth field (root) is group name to which this file associates.
The fifth field indicates (49152 bytes) size of file/folder.
Next three fields indicates modified time for file/directory.
Last column is file/directory name.
ls with -h option
The third option is -h or –human-readable. It is often used in conjunction with other options. Using it with -l option gives result in human readable format.
[email protected] ~ $ ls -lh /usr total 120K drwxr-xr-x 2 root root 48K Apr 11 22:56 bin drwxr-xr-x 2 root root 4.0K Nov 27 03:15 games drwxr-xr-x 19 root root 4.0K Apr 8 09:52 include drwxr-xr-x 178 root root 32K Apr 8 10:41 lib drwxr-xr-x 10 root root 4.0K Nov 27 02:59 local drwxr-xr-x 2 root root 12K Apr 8 09:53 sbin drwxr-xr-x 293 root root 12K Apr 8 21:10 share drwxr-xr-x 5 root root 4.0K Nov 27 03:15 src
Notice that the fifth field is expressed in Kilo Bytes rather than in bytes.
ls with -S option
The next option -S sorts result by size. Let’s use this command in conjunction with -lh for better understand.
[email protected] ~ $ ls -lhS /usr total 120K drwxr-xr-x 2 root root 48K Apr 11 22:56 bin drwxr-xr-x 178 root root 32K Apr 8 10:41 lib drwxr-xr-x 2 root root 12K Apr 8 09:53 sbin drwxr-xr-x 293 root root 12K Apr 8 21:10 share drwxr-xr-x 2 root root 4.0K Nov 27 03:15 games drwxr-xr-x 19 root root 4.0K Apr 8 09:52 include drwxr-xr-x 10 root root 4.0K Nov 27 02:59 local drwxr-xr-x 5 root root 4.0K Nov 27 03:15 src
Notice that files/folders are sorted by size.
ls with -t option
The -t option is used to show result by modification date.
[email protected] ~ $ ls -lht /usr total 120K drwxr-xr-x 2 root root 48K Apr 11 22:56 bin drwxr-xr-x 293 root root 12K Apr 8 21:10 share drwxr-xr-x 178 root root 32K Apr 8 10:41 lib drwxr-xr-x 2 root root 12K Apr 8 09:53 sbin drwxr-xr-x 19 root root 4.0K Apr 8 09:52 include drwxr-xr-x 5 root root 4.0K Nov 27 03:15 src drwxr-xr-x 2 root root 4.0K Nov 27 03:15 games drwxr-xr-x 10 root root 4.0K Nov 27 02:59 local
To show result in reverse order -r or –reverse option is used. Here -r is used in conjunction with the above command. The result must be in reverse order.
[email protected] ~ $ ls -lhtr /usr total 120K drwxr-xr-x 10 root root 4.0K Nov 27 02:59 local drwxr-xr-x 2 root root 4.0K Nov 27 03:15 games drwxr-xr-x 5 root root 4.0K Nov 27 03:15 src drwxr-xr-x 19 root root 4.0K Apr 8 09:52 include drwxr-xr-x 2 root root 12K Apr 8 09:53 sbin drwxr-xr-x 178 root root 32K Apr 8 10:41 lib drwxr-xr-x 293 root root 12K Apr 8 21:10 share drwxr-xr-x 2 root root 48K Apr 11 22:56 bin
To know full list of options available, there is one command called man. Using man with respective command displays all available options and their usage. The command man is short for manual. Linux comes pre-installed with necessary manual and can be accessed by man command.