Most commands have a --help option, which prints a short message about how to use the command and exits:
Syntax
$ command_name --help
$ cd --help
A man or manual page is a form of documentation that explains what the command does, examples of how we run the command, and what arguments it accepts.
The man command is used to display the manual page of a given command.
$ man command_name
$ man cd
who is a command-line utility that prints a list of currently logged in users. It can also show the current run level, time of the last system boot, and more. The basic syntax for the who command is as follows:
Example
$ who
root pts/0 2020-11-17 20:10 (10.10.0.2)
user1 pts/1 2020-11-17 20:11 (10.10.0.8)
Each line contains four fields separated by one or more spaces:
If you want to print the column headings, add the -H option:
Example:
$ who –H
NAME LINE TIME COMMENT
root pts/0 2020-11-17 20:10 (10.10.0.2)
user1 pts/1 2020-11-17 20:11 (10.10.0.8)
who accepts two non-option arguments. When invoked with two arguments the command prints information only about the terminal associated with the current user. The same output is displayed when the -m option is used.
You can use any two arguments:
$ who am i
[or]
$ who –m
Both the commands will print the same information:
Output:
user1 pts/1 2020-11-17 20:11 (10.10.0.8)
The echo command is one of the most basic and frequently used commands in Linux. The arguments passed to echo are printed to the standard output.
echo is commonly used in shell scripts to display a message or output the results of other commands.
Display a line of text on standard output.
Example:
$ echo Hello, World!
Hello, World!
Display a line of text containing a double quote.
Example:
$ echo 'Hello "World"'
Hello "World"
Display a line of text containing a single quote.
Example:
$ echo "I'm a Linux user."
I'm a Linux user.
Display a message containing special characters.
Example:
$ echo -e "India is great.\n\t- Sachin"
India is great.
- Sachin
Pattern matching characters.
Example:
$ echo The PHP files are: *.php
The PHP files are: index.php contact.php functions.php
Redirect to a file.
Example:
$ echo -e 'The only true wisdom is in knowing you know nothing.\nSocrates' >> /tmp/file.txt
The current working directory is the directory in which the user is currently working. Each time we interact with our command prompt, we are working within a directory.
We use the pwd command to find out what directory we are currently in:
$ pwd
/home/user1
The cd (“change directory”) command is used to change the current working directory in Linux. When used without any argument, cd will take us to our home directory:
Example
$ cd
To change to a directory, we can use its absolute or relative pathname.
Relative pathname:Assuming that the directory dir1 exists in the directory from which we run the command, we can navigate to it by using the relative path to the directory:
Example
$ cd dir1
Absolute pathname:We can also navigate to a directory by using its absolute path:
Example
$ cd /home/apple/Downloads