Linux Interface & Getting help from Manual Pages

Afridi ShaikAfridi Shaik
5 min read

Linux Shell Interface

Root User:-

[root@localhost ~]#

root -----> root/admin user

localhost---> Serverhostname [/etc/hostname]

~ --------> Home Directory

# --------> Root/Super user prompt

Normal User:-

[user@localhost ~]$

user -----> username

localhost---> Server Hostname [/etc/hostname]

~ --------> Home Directory

$ -------> Normal User

Ever Thought about How this interface is configured and how can we customize it? Let me take you to a more detailed way

root -----> /root/.bash_profile & /root/.bashrc

user -----> /home/[user]/.bash_profile & /root/.bashrc

bash_profile

  1. if condition checks bashrc file exists or not if it exists it will get sourced

  2. PATH=$PATH:$HOME/bin

This will help us to load binaries based on user. So the user can execute the commands it store in PATH variable

  1. Export the PATH variable

bash_rc

In bash_rc we mostly declare the PS1 Variable. For better user interfaces

  1. Below PS1 Value declares the interface in my server scenario

\u -----> username

\h -----> hotname

\w ----> working directory

$ ----> Depends on User If it's root it will show '#' if it's non-root user it will show '$'

  1. You can use lot of Customization For example, while using rm command you can make alias in bashrc file It
alias rm='rm -i'

Note:- This bash_profile & bashrc comes from /etc/skel directory

Command Syntax:-

The syntax of a command generally follows the pattern:

command [options] <arguments>
  • Command: The actual command you want to execute.

  • Options: Flags or switches that modify the behavior of the command. Options are preceded by a hyphen (-) or a double hyphen (--).

  • Arguments: The input or data on which the command operates. Arguments are typically filenames, directories, or other parameters required by the command.

    1.cd - Change Directory

    The cd command is used to change the current working directory.

      cd /path/to/directory
    

    In this example, /path/to/directory is the argument, specifying the destination directory.

    To access the manual page cd, you can use:

      man cd
    
  1. df Command

    This command will display disk space usage for all mounted filesystems in a human-readable format by using options, and it will include a column indicating the filesystem type.

    • -h: Display sizes in a human-readable format (e.g., KB, MB, GB).

    • -T: Display the filesystem type.

    • -P: Output in the POSIX format, which is useful for scripting

        df -hTP
      

To access the manual page df , you can use:

    man df

To navigate to a specific section in the manual page, you can use the man command followed by the manual page name and the section number. The syntax is as follows:

man [section_number] command

For example, if you want to see the section of the manual page specifically related to the ls command, you can use:

man 1 ls

Here, 1 is the section number for user commands. Similarly, you can access different sections by changing the section number:

  • 1: User commands

  • 2: System calls

  • 3: Library functions, covering functions provided by the C library

  • 4: Device files and drivers

  • 5: File formats and conventions

  • 6: Games and screensavers

  • 7: Miscellaneous (including macro packages and conventions)

  • 8: System administration commands and daemons

Whatis :-

The whatis command in Linux is used to display a one-line description of a command. The information is sourced from the manual pages (man pages) on the system. The whatis command is useful for quickly getting an overview of a command's purpose without having to read the entire manual page.

syntax:-

whatis command

Example 1: Basic Usage

whatis ls

This command will provide a short description of the ls command, which is used to list directory contents.

Example 2: Multiple Commands

whatis ls cp mv

You can specify multiple commands in a single whatis command. In this example, it will display short descriptions for the ls, cp, and mv commands.

Example 3: Regular Expressions

whatis '^c'

You can use regular expressions with whatis to match commands. In this example, it will display short descriptions for commands starting with the letter 'c'.

Example 4: Case-Insensitive Search

whatis -i tar

The -i option makes the search case insensitive. This example will display short descriptions for the tar command, regardless of the case.

Note:- If we get any error while using man / whatis for specific command use below command to update the db of manual

mandb

The --help option is used for providing a quick overview of the usage and available options of a command. It is a useful way to get a brief summary of the command's functionality without having to consult the full manual page.

Let's take the lsblk command as an example:

lsblk --help

Running this command will display a summary of the lsblk command's usage and options. Here's a simplified example of what you might see:

Usage: lsblk [OPTION]... [DEVICE]...

List information about all available or the specified block devices.

Mandatory arguments to long options are mandatory for short options too.

  -a, --all             print all devices
  -b, --bytes           print SIZE in bytes rather than in human readable format
  -f, --fs              output info about filesystems
  -h, --help            display this help and exit
  -l, --list            use list layout (default)
  -o, --output list     define columns to display
  -p, --pairs           use key="value" output format (default)
  -P, --paths           print full device path
  -r, --raw             use raw output format
  -t, --tree            use tree layout
  -x, --exclude list    exclude devices
  -d, --nodeps          don't print dependent devices
  -S, --scsi            use SCSI output format
  -I, --include list    include only devices
  -i, --invert          invert sort order
  -T, --topology        use topology output format
  -s, --output-separator string   print output separator
  -k, --kbytes          print SIZE in kilobytes
  -K, --kibibytes       print SIZE in kibibytes
  -m, --units SIZE      print SIZE in units of SIZE
  -w, --wait            wait for devices to settle before exiting
  -y, --sync            invoke sync before getting info

In this example, you can see a list of available options with a brief description for each. The --help option is a quick reference for users who want to understand the basic functionality of a command and its available options without delving into the detailed manual page (man lsblk).

0
Subscribe to my newsletter

Read articles from Afridi Shaik directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Afridi Shaik
Afridi Shaik