Browse Courses

Informational Commands

This document provides an overview of informational commands in Linux including how to use commands like whoami, id, uname, df, ps, top, echo, date and man to retrieve system and user information.

This document explores essential Linux informational commands used to retrieve system and user data. It covers commands for finding user details, examining operating system information, monitoring disk usage and running processes, and printing text or variables. The practical applications of each command are demonstrated with examples.


User Information Commands

Informational commands in Linux provide essential details about the system and its users. These commands are particularly useful for verifying user identity or determining which user account is running specific processes.

The whoami Command

The whoami command displays the current user’s username. It takes no arguments and has no options, making it one of the simplest commands to use.

1$ whoami
2john_doe

The id Command

The id command returns the user or group ID, which is a numerical identifier assigned to each user or group in the Linux system. It can be used with several options:

  • id -u: Returns only the numerical user ID
  • id -un: Returns the username corresponding to the numerical user ID
1$ id -u
21000
3$ id -un
4john_doe

System Information Commands

The uname Command

The uname (Unix name) command provides operating system information, such as the kernel name and version number. This is useful for identifying the type of system or diagnosing system-related issues.

OptionDescriptionExample Output
(no option)Returns OS nameLinux
-sReturns kernel nameLinux
-rReturns kernel release5.4.0-42-generic
-vReturns detailed version information#46-Ubuntu SMP Fri Jul 10 00:24:02 UTC 2020

For example, using uname -sr would display both the OS name and its version:

1$ uname -sr
2Linux 5.4.0-42-generic

Disk Usage Commands

The df Command

The df (disk free) command displays the system’s disk usage. It’s particularly useful for monitoring storage space or checking available space on a particular file system.

The most common usage is with the -h option, which makes the output “human-readable” by expressing disk space in units like gigabytes and terabytes instead of bytes:

1$ df -h ~
2Filesystem      Size  Used Avail Use% Mounted on
3/dev/sda1       100G   30G   70G  30% /home

In this example, df -h ~ displays disk information specific to the home directory (represented by the tilde symbol). The output shows all disks mounted on the home directory, including their size, used space, available space, and usage percentage.

To view disk usage across all filesystems, simply use df -h without specifying a directory.


Process Monitoring Commands

The ps Command

The ps (process status) command displays currently running processes on the system. This is helpful when monitoring or managing processes.

Common usage includes:

  • ps: Shows processes associated with the current user and terminal
  • ps -e: Lists all processes running on the system, regardless of which user started them

The output includes the process ID, terminal associated with the process, CPU time used, and the command name:

1$ ps -e
2  PID TTY          TIME CMD
3  1   ?        00:00:01 systemd
4  2   ?        00:00:00 kthreadd
5  3   ?        00:00:00 rcu_gp
6  ...

The top Command

The top (table of processes) command functions as a task manager, showing a real-time view of running processes and their resource usage. It’s invaluable for monitoring system performance or identifying resource-heavy processes.

By default, top displays processes sorted by CPU usage. The output includes details such as:

  • Process ID (PID)
  • User who started the process
  • CPU usage percentage
  • Memory usage
  • Process start time
  • Command name

The -n option can limit the display to a specific number of processes:

1$ top -n 3
2Tasks: 3 of 234 total
3%CPU  PID USER     PR  NI  VIRT   RES   SHR S   %MEM  TIME+   COMMAND
410.2  123 john     20  0   2.0g   400m  20m  R   4.9   1:23   chrome
55.0   456 john     20  0   20m    8.0m  4.0m R   0.1   0:05   top
62.5   789 john     20  0   1.5g   300m  30m  S   3.7   0:45   spotify

Text and Variable Display Commands

The echo Command

The echo command is a simple yet powerful tool for displaying text or variables in the terminal or in shell scripts.

Basic usage examples:

  • echo: Returns a newline
  • echo hello: Prints “hello”
  • echo "Learning Linux is fun!": Prints the quoted string

While quotes are not strictly necessary for simple strings, they are best practice for strings with spaces or special characters.

To view the value of a variable, prefix the variable name with a dollar sign:

1$ echo $PATH
2/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin

The date Command

The date command displays the current system date and time:

1$ date
2Wed Jul 2 09:15:30 EDT 2025

The output can be customized using format controls, which are indicated with the % symbol:

Format ControlDescriptionExample
%AFull weekday name“Wednesday”
%jDay of year (001-366)“183”
%YYear“2025”
%HHour (00-23)“09”
%MMinute (00-59)“15”

Custom date formats can be created by combining these controls with text:

1$ date "+Today is %A, day %j of %Y"
2Today is Wednesday, day 183 of 2025

Documentation Commands

The man Command

The man (manual) command displays the reference manual for any specified command. This is essential for learning how to use commands and understanding their options.

Usage is straightforward:

1man date

This would display the complete manual page for the date command, including all options, examples, and related information.


Conclusion

Linux informational commands provide valuable insights into user identity, system characteristics, resource usage, and running processes. Mastering these commands is essential for effective system administration and troubleshooting. From simple user identification with whoami to comprehensive process monitoring with top, these tools form the foundation of Linux system management.


FAQs

The primary purpose of the whoami command is to display the username of the current user. It’s a simple command that takes no arguments or options and is useful for verifying user identity, especially in scripts or when multiple terminal sessions are open.

  1. They are identical commands with no functional difference
  2. id -u returns the numerical user ID, while id -un returns the username corresponding to that ID
  3. id -u is for regular users, while id -un is exclusively for system administrators
  4. id -u works on all Linux distributions, while id -un only works on Debian-based systems
(2) The id -u command returns only the numerical user ID assigned to the current user in the system, while id -un returns the username that corresponds to that numerical ID. These options provide different representations of the same user identity.

The command will display disk usage information for all mounted filesystems in a human-readable format. This includes the size, used space, available space, and usage percentage for each filesystem on the system. The -h option ensures that storage units are displayed in kilobytes, megabytes, or gigabytes rather than just bytes.

  1. whoami
  2. uname
  3. top
  4. date
(3) The top command should be used first as it provides a real-time, dynamic view of system processes sorted by resource usage. It displays information about CPU and memory consumption for all running processes, making it the ideal tool for identifying which processes are consuming excessive memory.

  1. It can display the kernel name with the -s option
  2. It can show the kernel version with the -r option
  3. It stands for “Unix name”
  4. It can directly modify system information when used with root privileges
(4) The uname command is only used to display system information and cannot modify any system parameters or settings, regardless of user privileges. It is strictly an informational command used for retrieving details about the operating system.

When using the echo command, quotation marks are always required around strings with spaces to ensure proper output.

False. While it’s considered best practice to use quotation marks around strings with spaces when using the echo command, they are not strictly required. The echo command will still correctly display strings with spaces even without quotation marks, though using quotes is recommended to avoid potential issues with special characters or complex strings.

CommandPrimary Function
A. ps1. Displays disk usage information
B. df2. Shows current date and time
C. date3. Lists running processes
D. man4. Displays command documentation
A-3, B-1, C-2, D-4. The ps command lists running processes, df displays disk usage information, date shows the current date and time, and man displays command documentation.

  1. Command output can sometimes be difficult to interpret without formatting options
  2. The df command is only useful with the -h option
  3. The -h option stands for “help” and provides documentation
  4. Human-readable output is less precise than raw output
(1) The existence of the -h (human-readable) option for the df command suggests that the default output (in bytes) can be difficult to interpret, especially for large storage values. This option converts the output to more easily understood units like KB, MB, GB, which indicates that command designers recognized the need for more intuitive output formatting.

The Linux user would use the command date "+%j %Y" or date "+Day %j of %Y". This utilizes format controls where %j represents the day of the year (001-366) and %Y represents the four-digit year. The + symbol indicates that what follows is a format string, and quotation marks ensure that the entire format is treated as a single argument.

When the top command is run without options, it displays a real-time, continuously updating view of system processes sorted by CPU usage by default. The display includes information such as process ID (PID), user, CPU usage percentage, memory usage, and command name for all running processes. The display refreshes every few seconds, showing the most resource-intensive processes at the top of the list.