Welcome to Linux Knowledge Base and Tutorial
"The place where you learn linux"
Let The Music Play: Join EFF Today

 Create an AccountHome | Submit News | Your Account  

Tutorial Menu
Linux Tutorial Home
Table of Contents
Up to --> Linux Tutorial

· Working with the System
· Backing-up and Restoring Files
· Interacting with the System
· Logging In
· Logging Out
· When Things Go Wrong
· Accessing Disks

Glossary
MoreInfo
Man Pages
Linux Topics
Test Your Knowledge

Site Menu
Site Map
FAQ
Copyright Info
Terms of Use
Privacy Info
Disclaimer
WorkBoard
Thanks
Donations
Advertising
Masthead / Impressum
Your Account

Communication
Feedback
Forums
Private Messages
Recommend Us
Surveys

Features
HOWTOs
News
News Archive
NukeSentinel
Submit News
Topics
User Articles
Web Links

Google
Google


The Web
linux-tutorial.info

Who's Online
There are currently, 313 guest(s) and 2 member(s) that are online.

You are an Anonymous user. You can register for free by clicking here

  
Linux Tutorial - Working with the System - Interacting with the System
  Backing-up and Restoring Files ---- Logging In  


Interacting with the System

It is common to have people working on UNIX systems that have never worked on a computer before or have only worked in pure windowing environments, like on a Macintosh. When they get to the command line, they are lost. On more than one occasion, I have talked to customers and I have asked them to type in cd /. There is a pause and I hear: click-click-click-click-click-click-click-click-click-click-click-click. "Hmmm," I think to myself, "that's too many characters." So I ask them what they typed, and they respond, "cd-space-slash."

We need to adhere to some conventions throughout this site to make things easier. One is that commands that I talk about will be in your path unless I say otherwise. Therefore, to access them, all you need to do is input the name of the command without the full path.

The second convention is the translation of the phrases "input the command," "enter the command," and "type in the command." These are translated to mean "input/enter/type in the command and press Enter." I don't know how many times I have talked with customers and have said "type in the command" and then asked them for what happens and their response is, "Oh, you want me to press Enter?" Yes! Unless I say otherwise, always press Enter after inputting, entering, or typing in a command.

Simply having shell is probably not enough for most users. Although you could probably come up with an interesting and possibly useful shell script, more than likely you're going to need some commands to run. There are literally hundreds of different commands that come with your system by default and there are many more different variations of these commands, which you can download from the Internet.

Sometimes the commands you issue are not separate files on the hard disk, but rather are built-in to your shell. For example, the cd command, which is used to change directories, is part of the shell, whereas the ls command, which is used to display the contents of directories is a separate program. In some cases one shell has a particular command built-in, but it is not available in another shell.

In general a command is broke down into three parts:

programname option(s) argument(s)

Note that not all commands have options and you do not always need to have arguments to a command. For example, the date does have any arguments and works just fine without any options. Some command are built-in to the shell you are using, but may be an external command with a different shell. For example, the echo is internal to the bash shell, but you will probably also find the /bin/echo command on your system.

If you ever run into trouble and are confused about the behavior of your shell, one important thing to know is what shell you have. If you weren't told what shell you had when your account was created or you are installing Linux for the first time and really don't know, there are a couple of ways of finding out. The first is to simply ask the shell. This is done by accessing the $SHELL environment variable. (We discuss environment variables in detail in the section on shell variables.) This is done using the echo command like this:

echo $SHELL

As you might guess, the echo command simply displays on the screen exactly what you told it, in this case we told it to display the $SHELL variable. (We know it is a variable because of the leading $, which we also will discuss in section on shell variables .) What should probably happen is you get something like this:

/bin/bash

In this case, the shell is /bin/bash. We can also find out what shell we are using by seeing which programs we are currently running. With Linux, as with other Unix dialects, a running program is called a " process", and you check your processes using the ps command (for process status). You can start it with an argument simply by inputting ps and pressing the enter key. This will probably get you something like this:

PID TTY TIME CMD 21797 pts/1 00:00:00 bash 6060 pts/1 00:00:00 ps

In this case we see under the heading CMD (for command) only "bash" and not the full pathname as in the previous example. However, there are options to the ps command which will show us the path.

The shell you are using is just one piece of information the system maintains in regard to your current session. Much of this information is stored in the form of variables, like your shell. These variables are set for you when you login to the system. You can also set variables yourself using the set command. This might look like this:

set VAR=value

Where VAR is the variable name and "value" is the value which you assigned to that variable. Note that it is not until you want to access the value of the variable that you preceded with the $. To find out the contents of all variables, you would use the set command by itself with no arguments. This gives you a long list of variables.

When you login to the system you start in your "home" directory, which can be stored in the $HOME variable. As we discussed earlier, to change your current directory (also called your working directory) you use the cd command. If you wanted to return to your home directory, you can issue the command cd $HOME and your shell will pass the value of the $HOME variable to the cd, which would then change directories for you. (Note that typically if you use the cd command with no arguments at all, you change to your home directory by default.)

One part of your environment which is extremely useful to know is the directory you are currently in. To do this you might want to tell the system to simply print your current working directory. This is done with the pwd command, which simply displays the full path to your current directory.

It is also useful to see what files and directories reside in your current directory. This is done with the ls command (short for "list"). Without the options the ls command provides you a simple list of what is in your current directory, without any additional information. The output might look like this:

prompt# ls letter.txt memo.txt picture.jpg

you can use the -l option to get a "long" listing of the files and directories. This might show you something like this:

prompt# ls -l -rw-r--r-- 1 jimmo users 2457 Feb 13 22:00 letter.txt -rw-r--r-- 1 jimmo users 7426 Feb 15 21:33 memo.txt -rw-r--r-- 1 jimmo users 34104 Feb 14 21:31 picture.jpg

This information includes the permissions on the file, who owns the file, the size, and so forth. Details of this can be found in the section on file permissions.

For a more detailed discussion on how various shells behave see the section on shells.

There are many ways to do the things you want to do. Some use a hammer approach and force the answer out of the system. In many cases, there are other commands that do the exact same thing without all the gyrations. So, what I am going to try to do here is step through some of the logic (and illogic) that I went through when first learning Linux. That way, we can all laugh together at how silly I was, and maybe you won't make the same mistakes I did.

Every dialect of UNIX that I have seen has the ls command. This gives a directory listing of either the current directory if no argument is given, or a listing of a particular file or directory if arguments are specified. The default behavior under Linux for the ls command is to list the names of the files in a single column. Try it and see.

It is a frequent (maybe not common) misconception for new users to think that they have to be in a particular directory to get a listing of it. They will spend a great deal of time moving up and down the directory tree looking for a particular file. Fortunately, they don't have to do it that way. The issue with this misunderstanding is that every command is capable of working with paths, as is the operating system that does the work. Remember our discussion of Linux basics. Paths can be relative to our current directory, such as ./directory, or absolute, such as /home/jimmo/directory.

For example, assume that you have a subdirectory of your current working directory called letters. In it are several subdirectories for types of letters, such as business, school, family, friends, and taxes. To get a listing of each of these directories, you could write





Because the ls command lets you have multiple commands on the same line, you also could have issued the command like this:

Both will give you a listing of each of the five directories. Even for five directories, typing all of that is a pain. You might think you could save some typing if you simply entered

However, this gives you a listing of all the files and directories in ./letters, not the subdirectories. Instead, if you entered

the shell would expand the wildcard (*) and give you a listing of both the ./letters directory as well as the directories immediately below ./letters, like the second example above. If each of the subdirectories is small, then this might fit onto one screen. If, on the other hand, you have 50 letters in each subdirectory, they are not all going to fit on the screen at once. Remember our discussion on shell basics? You can use the pipe (|) to send the command through something like more so that you could read it a page at a time.

It is common to run command one right after the other. If you simply press the enter key after the first command, the shell executes it before returning to the prompt. Often you want to issue two commands in sequence. This is done by separating the commands with a semi-colon, like this:

command1; command2

Note that these commands are not really connected in any way. The shell simply executes one after the other. To actually "connect" the commands, you would need to use a pipe. Details on pipes can be found in the section on shells

 Previous Page
Backing-up and Restoring Files
  Back to Top
Table of Contents
Next Page 
Logging In


MoreInfo

Test Your Knowledge

User Comments:


Posted by hrosen on November 09, 2005 03:13pm:

This paragraph should have "maybe be" changed to "may be": Note that not all commands have options and you do not always need to have arguments to a command. For example, the date does have any arguments and works just fine without any options. Some command are built-in to the shell you are using, but maybe be an external command with a different shell. For example, the echo is internal to the bash shell, but you will probably also find the /bin/echo command on your system.agraph: to read as: Note that not all commands have options and you do not always need to have arguments to a command. For example, the date does have any arguments and works just fine without any options. Some command are built-in to the shell you are using, but may be an external command with a different shell. For example, the echo is internal to the bash shell, but you will probably also find the /bin/echo command on your system.


You can only add comments if you are logged in.

Copyright 2002-2009 by James Mohr. Licensed under modified GNU Free Documentation License (Portions of this material originally published by Prentice Hall, Pearson Education, Inc). See here for details. All rights reserved.
  




Login
Nickname

Password

Security Code
Security Code
Type Security Code


Don't have an account yet? You can create one. As a registered user you have some advantages like theme manager, comments configuration and post comments with your name.

Help if you can!


Amazon Wish List

Did You Know?
The Linux Tutorial welcomes your suggestions and ideas.


Friends



Tell a Friend About Us

Bookmark and Share



Web site powered by PHP-Nuke

Is this information useful? At the very least you can help by spreading the word to your favorite newsgroups, mailing lists and forums.
All logos and trademarks in this site are property of their respective owner. The comments are property of their posters. Articles are the property of their respective owners. Unless otherwise stated in the body of the article, article content (C) 1994-2013 by James Mohr. All rights reserved. The stylized page/paper, as well as the terms "The Linux Tutorial", "The Linux Server Tutorial", "The Linux Knowledge Base and Tutorial" and "The place where you learn Linux" are service marks of James Mohr. All rights reserved.
The Linux Knowledge Base and Tutorial may contain links to sites on the Internet, which are owned and operated by third parties. The Linux Tutorial is not responsible for the content of any such third-party site. By viewing/utilizing this web site, you have agreed to our disclaimer, terms of use and privacy policy. Use of automated download software ("harvesters") such as wget, httrack, etc. causes the site to quickly exceed its bandwidth limitation and are therefore expressly prohibited. For more details on this, take a look here

PHP-Nuke Copyright © 2004 by Francisco Burzi. This is free software, and you may redistribute it under the GPL. PHP-Nuke comes with absolutely no warranty, for details, see the license.
Page Generation: 0.15 Seconds