Get Help on Linux Commands

LinuxLinuxBeginner
Practice Now

Introduction

Linux commands are essential for working with the operating system, but some can be difficult to remember, especially for beginners. This lab will teach you how to use helpful tools and documentation to find information about Linux commands, making it easier to use and understand them.

Learning how to access help resources can enhance your problem-solving skills, benefiting your future learning and endeavors.


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL linux(("`Linux`")) -.-> linux/BasicSystemCommandsGroup(["`Basic System Commands`"]) linux(("`Linux`")) -.-> linux/TextProcessingGroup(["`Text Processing`"]) linux(("`Linux`")) -.-> linux/FileandDirectoryManagementGroup(["`File and Directory Management`"]) linux(("`Linux`")) -.-> linux/BasicFileOperationsGroup(["`Basic File Operations`"]) linux/BasicSystemCommandsGroup -.-> linux/help("`Command Assistance`") linux/BasicSystemCommandsGroup -.-> linux/man("`Manual Access`") linux/TextProcessingGroup -.-> linux/grep("`Pattern Searching`") linux/FileandDirectoryManagementGroup -.-> linux/cd("`Directory Changing`") linux/FileandDirectoryManagementGroup -.-> linux/which("`Command Locating`") linux/BasicFileOperationsGroup -.-> linux/ls("`Content Listing`") linux/BasicFileOperationsGroup -.-> linux/cp("`File Copying`") subgraph Lab Skills linux/help -.-> lab-18000{{"`Get Help on Linux Commands`"}} linux/man -.-> lab-18000{{"`Get Help on Linux Commands`"}} linux/grep -.-> lab-18000{{"`Get Help on Linux Commands`"}} linux/cd -.-> lab-18000{{"`Get Help on Linux Commands`"}} linux/which -.-> lab-18000{{"`Get Help on Linux Commands`"}} linux/ls -.-> lab-18000{{"`Get Help on Linux Commands`"}} linux/cp -.-> lab-18000{{"`Get Help on Linux Commands`"}} end

Understand Built-in and External Commands

Before we dive into getting help, let's understand the difference between built-in and external commands in Linux.

  1. Open a terminal in your Ubuntu VM. You should see a prompt similar to:
labex:project/ $

If you don't see this prompt, don't worry. The important part is that you have a command line where you can type commands.

  1. Type the following commands to check the type of two different commands:
type cd
type ls

After typing each command, press Enter to execute it.

You should see output similar to:

cd is a shell builtin
ls is an alias for ls --color=tty

Let's break down what this means:

  • cd is a shell builtin: This means the cd command is built into the shell itself. It's part of the shell's core functionality.
  • ls is aliased to 'ls --color=tty': This is a bit more complex. It means that when you type ls, you're actually running ls --color=tty. An alias is like a shortcut or nickname for a command. In this case, the ls command is set up to always use colors in its output.

If you see different output, don't panic. Different Linux distributions might have slightly different setups. The important thing is to understand the concept of built-in vs. external commands.

Use the --help Option

Many Linux commands support a --help option that provides a quick overview of the command's usage. This is often the fastest way to get basic information about a command.

  1. Try using the --help option with the ls command:
ls --help

Type this command and press Enter. You should see a summary of the ls command's options and usage. It might look overwhelming at first, but don't worry — you don't need to understand everything right away.

  1. Take a moment to read through the output. You'll see something like this at the beginning:
Usage: ls [OPTION]... [FILE]...
List information about the FILEs (the current directory by default).
Sort entries alphabetically if none of -cftuvSUX nor --sort is specified.

This tells you that ls is used to list information about files and directories. The square brackets [] indicate optional parts. So [OPTION]... means you can use zero or more options, and [FILE]... means you can specify zero or more files or directories.

  1. Now try the same with another command, like cp:
cp --help

This will show you the help information for the cp (copy) command. Again, take a moment to read through the beginning of the output.

If at any point the output is too long and you see a colon (:) at the bottom of the terminal, you can press the Space bar to see more, or q to quit and return to the command prompt.

Explore the man Command

The man command provides more detailed information about commands, including their full documentation. It's like an electronic manual for almost every command on your system.

  1. Use the man command to view the manual page for the ls command:
man ls

Type this command and press Enter. You'll see a detailed description of the ls command.

  1. You're now in the manual viewer. Here's how to navigate:

    • Use the Up and Down arrow keys to scroll line by line.
    • Use the Space bar to move forward one page.
    • Use the b key to move back one page.
    • Use the / key followed by a word to search for that word in the document. For example, /sort will search for "sort".
    • Press n to move to the next occurrence of your search term.
    • Press N to move to the previous occurrence of your search term.
  2. Take some time to read through the manual. Don't worry if you don't understand everything — there's a lot of information here!

  3. When you're done exploring, press q to quit the man page and return to the command prompt.

  4. Now try viewing the man page for another command, like grep:

man grep

grep is a powerful tool for searching text. Again, use the navigation keys to explore the manual, and press q to exit when you're done.

Remember, you can use man with almost any command to get detailed information about how to use it.

The apropos command helps you find commands related to a specific keyword. This is incredibly useful when you know what you want to do, but you're not sure which command to use.

  1. Use apropos to find commands related to "password":
apropos password

Type this command and press Enter. You'll see a list of commands that have "password" in their descriptions.

  1. The output might be quite long. Each line will show a command followed by a brief description. For example, you might see something like:
passwd (1)           - change user password

This tells you that the passwd command is used to change user passwords. The (1) indicates that this is in section 1 of the manual (user commands).

  1. Now try another keyword, like "file":
apropos file

This will show you commands related to file operations. Again, the list might be quite long — there are many commands in Linux that deal with files!

  1. If you want to narrow down the results, you can use grep to filter the output. For example:
apropos file | grep create

This will show only the commands related to "file" that also mention "create" in their description.

Remember, apropos is a great tool when you're not sure which command you need. Just think of a keyword related to what you want to do, and apropos can help you find the right command.

Summary

In this lab, you've learned several ways to get help and information about Linux commands:

  1. Using the type command to distinguish between built-in and external commands.
  2. Using the --help option for quick command summaries.
  3. Using the man command for detailed documentation.
  4. Using apropos to find commands related to specific keywords.

These tools will help you become more proficient in using Linux commands and troubleshooting issues. Remember to use these resources whenever you encounter an unfamiliar command or need more information about a command's usage.

As you continue your Linux journey, don't be afraid to experiment and explore. The more you use these help tools, the more comfortable you'll become with the Linux command line. Happy learning!

Other Linux Tutorials you may like