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.
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.
- 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.
- 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 thecdcommand 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 typels, you're actually runningls --color=tty. An alias is like a shortcut or nickname for a command. In this case, thelscommand 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.
- Try using the
--helpoption with thelscommand:
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.
- 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.
- 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.
- Use the
mancommand to view the manual page for thelscommand:
man ls
Type this command and press Enter. You'll see a detailed description of the ls command.
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
bkey to move back one page. - Use the
/key followed by a word to search for that word in the document. For example,/sortwill search for "sort". - Press
nto move to the next occurrence of your search term. - Press
Nto move to the previous occurrence of your search term.
Take some time to read through the manual. Don't worry if you don't understand everything — there's a lot of information here!
When you're done exploring, press
qto quit the man page and return to the command prompt.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.
Use apropos to Find Related Commands
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.
- Use
aproposto 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.
- 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).
- 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!
- 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:
- Using the
typecommand to distinguish between built-in and external commands. - Using the
--helpoption for quick command summaries. - Using the
mancommand for detailed documentation. - Using
aproposto 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!



