Linux Classes
Share This With a Friend  

How Do I Use the Linux Command Prompt?

Linux Commands

When you enter a command in Linux, you type a command at a prompt and then press enter. Commands can be more than one word--some require switches (which modify the command's behavior ) and/or file names (which tell the command what data to act on). Let's dissect the command shown here: $ ls -l sample.doc

Linux Commands Are Case Sensitive

One of the most important things to remember about entering commands in any Unix environment is that case matters. In DOS, you can type DIR or dir or even DiR and get the same result, but not in Linux. Linux will be quite put out if you type LS instead of ls to list your files. With file names, you have to be even more careful, since nearly identical files (save for capitalization) can exist in the same directory, though they may have completely different contents--Cookie_Recipe and cookie_recipe would appear as distinctly different files to Linux, though they may look pretty much the same to you except for the capital letters.

The best rule to follow is this: Almost everything in Linux is lowercase, so avoid capital letters when naming your files.

Command Prompts Can Vary

When the Linux shell is ready for a command, you see a command prompt. Just as in DOS, Linux's command prompts vary. For example, when you log in as root, your default command prompt is the pound (#) sign, but if you log-in as a regula r user (like hermie), the prompt changes to a dollar sign ($).

Bash uses the different prompts to clue you in to your user privileges. Pay attention to the prompts so you don't inadvertently wipe out important files while logged in to the root account with superuser privileges, for example.

It's especially important to mind the prompts if you use the su (switch user) command, which allows you to act temporarily as the root user while you're logged in as a regular user. Watch how the prompt changes in the following example. (User input is in boldface.)

$ whoami
$ su - root
Enter password for root: xxxxxxx
# whoami
# exit
$ whoami

In this example, entering the command whoami tells you who the system thinks you are--hermie. Then the su - root command switches you to the root user (note the prompt change to the pound sign). The < STRONG>exit command exits the root user account and brings you back to hermie; the prompt changes back to a dollar sign. (See "Important Linux Commands" for more information on the su comma nd.)

This example used the prompt and the whoami command to show the logged-in user, but customizing your prompt is a better way to keep track of where you are.

For example, the command

PS1="\u \$ "

changes the prompt so that it displays the user name (\u), followed by the dollar sign (or pound sign, if you're a superuser). You can use other characters to insert the current time, date, or working directory (\t, \d, and \w, respectively). Here's how to use these various options:

PS1="\t \$ " yields 09:15:24 $.

PS1="\u (\d) \$ " yields hermie (Wed Nov 4) $.

PS1="\u (\w) \$ " yields hermie (/home/hermie) $.

All you're actually doing here is setting the variable PS1 (prompt string number 1) to a special string of characters. The bash shell interprets the value of the PS1 variable each time it's ready to build the prompt string.

In the "Environment Variables" section, you'll learn more about special variables such as PS1 and how to set them automatically each time you log in.

Previous Lesson: Choosing a Shell
Next Lesson: Wildcards



Comments - most recent first
(Please feel free to answer questions posted by others!)

venkatagiri hegde     (19 Feb 2013, 09:48)
in fedora16 when logged in as root user immediately terminal is closing ,why sir?
ep0ch     (24 Aug 2012, 16:21)
Access to root is locked in Ubuntu. You can use many root commands as the admin user by typing "sudo" before the command.
anders     (12 Apr 2012, 09:24)
I can't remember my root password, is it the same as the password to my admin account? I'm using ubunto 11.10
Ranjana     (16 Nov 2011, 09:58)
Hi Bob,

I am looking to switch between user(from normal to root user) with in the script, run the command as root user and then again exit to normal user. Could you please please please help me in this.

shashi     (18 Oct 2011, 01:59)
when i type any cmd ex: ls , but it will show cmd not found, please advice what setting need's to be change.
rtyecript     (22 Aug 2011, 21:45)
I really liked the article, and the very cool blog
beekeeper     (22 Apr 2011, 02:16)
This site should not be called lowfat its big in lesson .... love this site...
Bob Rankin     (17 Feb 2011, 07:57)
@YUGAL - Let's make a deal... if you provide me guidance all about the Brain Surgery, I'll provide you guidance all about the Linux.
yugal ksihor     (15 Feb 2011, 01:42)
Please provide me guidance all about the Linux with programming.
Steve     (07 Feb 2011, 10:57)
Hi can someone pls tell me what "sudo-s" means in the Terminal window Thanks
chintan     (08 Jan 2011, 20:45)

I keep getting this error when I try executing the PS1 command
p11: command not found
Bob Rankin     (19 Oct 2010, 09:32)
For more on who versus "who am i" see //
Bob Rankin     (19 Oct 2010, 09:16)
@Mohan - You've discovered the difference between the "who" and "whoami" commands! The whoami command will work as you might expect.
Mohan Goud Thalla     (19 Oct 2010, 05:35)
Hi Bob. I tried logging in as root and typed in "who am i", the answer was expected root.
But when i changed to "tester" using su - tester command and typed in "who am i", the answer was an unexpected "root".
When the command "who am i" is typed in, the initial logged in user name is displayed.

Aadil     (19 May 2010, 23:14)
@ ang ...
Try booting your system from a DOS bootable CD and run the command

fdisk /mbr

it should start recognising your hard drive.
Matt     (18 Feb 2010, 19:50)
What Americans call the "pound" sign (#) is referred to as the "hash" sign elsewhere. But what do you expect from a nation who put their dates backwards and are still using a stone-age measuring system...

Bob Rankin     (17 Feb 2010, 22:52)
Maybe in the UK... :-)
Peter     (17 Feb 2010, 14:39)
I think the pound sign is '' rather than '#'.
ang     (07 Feb 2010, 09:10)
My computer, which was built for windows xp, was running linux. Well I hate to admit I wasn't very adept at linux and must have made a very bad change, now it won't boot, won't even recognize the hard drive? can I fix this? I don't want to give up on it, I'd actually like to reinstall windows xp? any suggestions? I would greatly appreciate any advice.

I welcome your comments. However... I am puzzled by many people who say "Please send me the Linux tutorial." This website *is* your Linux Tutorial! Read everything here, learn all you can, ask questions if you like. But don't ask me to send what you already have. :-)

NO SPAM! If you post garbage, it will be deleted, and you will be banned.
Notify me about new comments on this page
Hide my email

Ask Bob Rankin - Free Tech Support

Copyright © by - Privacy Policy
All rights reserved - Redistribution is allowed only with permission.