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.)
$ who am i
hermie
$ su - root
Enter password for root: xxxxxxx
# who am i
root
# exit
$ who am i
hermie
In this example, entering the command who am i 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 who am i 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.
LINKS TO THE OTHER TUTORIALS
Leason 1: Living in a shell
Leason 2: Root and Other Users
Leason 3: Virtual Consoles
Leason 4: Logoff and Shutdown
Leason 5: Choosing a Shell
Leason 6: The Command Prompt
Leason 7: Wildcards
Leason 8: Command History and Editing
Leason 9: Aliases
Leason 10: Redirection
Leason 11: Pipelines
Leason 12: Processes
Leason 13: Stopping a Program
Leason 14: Environment Variables
Leason 15: Help!
- Board index General Knowledge Everything Linux
-
- It is currently 03 May 2025, 18:08
- All times are UTC-04:00
Linux Basics (tutorial) #6
Discuss everything about Linux here!
Moderator: Community Moderator
- MrNiitriiX
- Premium Uploader
- Posts: 2197
- Joined: 19 Apr 2010, 14:52
- Location: between space and time
- Has thanked: 24 times
- Been thanked: 164 times
Linux Basics (tutorial) #6
Post by MrNiitriiX »
Last edited by MrNiitriiX on 31 Jul 2010, 13:05, edited 1 time in total.
Jump to
- ↳ Site Help & Support
- ↳ Site Tutorials & How To
- ↳ Site Support/Bugs
- ↳ Suggestion & Feedback
- ↳ General Discussions
- ↳ News
- ↳ Trades & Offers
- ↳ Sports
- ↳ Relax & Enjoy!
- ↳ Jokes
- ↳ General Knowledge
- ↳ Tips, Tweaks & Quick Tutorials
- ↳ OpenSource/Freeware & Useful Links
- ↳ Everything Linux
- ↳ General Support
- ↳ Technical Support
- ↳ Software Chat & Support
- ↳ Hardware Chat & Support
- ↳ Smartphones and other Portable Devices Chat & Support
- ↳ Programming/Web Building Chat & Support
- ↳ User Uploads list
- ↳ Graphics & Images
- ↳ Graphics Requests & Helpdesk
- ↳ CC Graphics & Images
- ↳ ChattChitto RG
- ↳ ChattChitto RG - Apps
- ↳ ChattChitto RG - Movies
- ↳ ChattChitto RG - Music
- ↳ Apps
- ↳ Portable
- ↳ Beta
- ↳ Games
- ↳ PC
- ↳ PS2
- ↳ PS3
- ↳ Wii
- ↳ Xbox
- ↳ PSP
- ↳ Other Consoles
- ↳ Movies
- ↳ Rips
- ↳ Pretime Releases
- ↳ DVD-Rip
- ↳ BR-Rip/BD-Rip
- ↳ 3D-Rips
- ↳ Full Rips
- ↳ DVD-R
- ↳ BR-R
- ↳ TV Shows
- ↳ HDTV Shows
- ↳ Anime/Cartoons
- ↳ Sport
- ↳ Music
- ↳ Electronic / Dance Music
- ↳ Pop / Rock Music
- ↳ Hip-Hop / Rap Music
- ↳ R&B / Soul Music / Jazz / Reggae
- ↳ Soundtrack / Classical Music
- ↳ Other Genres
- ↳ Music Videos
- ↳ DJ Mix sets & Mash-Ups
- ↳ eBooks
- ↳ Audio
- ↳ Magazine
- ↳ Mac and Other OSes
- ↳ Others
- ↳ Templates, Fonts & Scripts
- ↳ Wallpapers & Images Pack
- ↳ Tutorials - Educational Material
- ↳ Mobiles & Media Players
- ↳ Apps
- ↳ Portable
- ↳ Beta
- ↳ Games
- ↳ PC
- ↳ PS2
- ↳ PS3
- ↳ Wii
- ↳ Xbox
- ↳ PSP
- ↳ Other Consoles
- ↳ Movies
- ↳ Rips
- ↳ Pretime Releases
- ↳ DVD-Rip
- ↳ BR-Rip/BD-Rip
- ↳ 3D-Rips
- ↳ Full Rips
- ↳ DVD-R
- ↳ BR-R
- ↳ TV Shows
- ↳ HDTV Shows
- ↳ Anime/Cartoons
- ↳ Sport
- ↳ Music
- ↳ Electronic / Dance Music
- ↳ Pop / Rock Music
- ↳ Hip-Hop / Rap Music
- ↳ R&B / Soul Music / Jazz / Reggae
- ↳ Soundtrack / Classical Music
- ↳ Other Genres
- ↳ Music Videos
- ↳ DJ Mix sets & Mash-Ups
- ↳ eBooks
- ↳ Audio
- ↳ Magazine
- ↳ Mac and Other OSes
- ↳ Others
- ↳ Templates, Fonts & Scripts
- ↳ Wallpapers & Images Pack
- ↳ Tutorials - Educational Material
- ↳ Mobiles & Media Players
- ↳ Short Videos
- ↳ Regular Movies
- ↳ Hentai Movies
- ↳ Ebooks, Pics & Wallpapers
- ↳ Jokes
- ↳ Adult Sites Passwords
- ↳ Requests
- ↳ Apps requests
- ↳ Completed Requests
- ↳ Games requests
- ↳ Completed Requests
- ↳ Movies & TV Shows requests
- ↳ Completed Requests
- ↳ Music requests
- ↳ Mix Tape
- ↳ Completed Requests
- ↳ Other requests
- ↳ Mac requests
- ↳ Completed Requests
- Social Life
- ↳ Animals and Pets
- ↳ Photography
- ↳ Handy Hints for Everyday Living
- ↳ Traveling
- ↳ Motor Racing
- ↳ Cars and Bikes
- ↳ Aircrafts
- ↳ Marine/Submarine Vessels
- ↳ Cooking
- ↳ Sports
- ↳ Gadgets
- ↳ Gifts
- ↳ Forex