music
OSdata.com: programming text book 

OSdata.com

quick tour of shell commands

summary

    This subchapter gives you a quick tour of shell commands.

    You should do each of the exercises and observe what happens.

    Do not worry about trying to learn how each of the commands works.

    The goal here is to give you a basic idea of how a shell works and the kinds of things that the most common shell commands and operations do.

    This quick tour will give you a background to understand the upcoming subchapters and their lessons. If you have the need to use anything you observe in this quick tour, you can always jump ahead to the appropriate subchapter and learn the details.

free book on UNIX/Linux System Administration

Teach Yourself UNIX/Linux System Administration and Shell Programming

free computer programming text book project

table of contents
If you like the idea of this project,
then please donate some money.
more information on donating

Google

quick tour of shell commands

    This subchapter gives you a quick tour of shell commands.

    You should do each of the exercises and observe what happens.

    Do not worry about trying to learn how each of the commands works.

    The goal here is to give you a basic idea of how a shell works and the kinds of things that the most common shell commands and operations do.

    This quick tour will give you a background to understand the upcoming subchapters and their lessons. If you have the need to use anything you observe in this quick tour, you can always jump ahead to the appropriate subchapter and learn the details.

failure

    Type asdf (a non-existent command) into the terminal. Remember to press the ENTER or RETURN key after this command.

    $ asdf
    -bash: asdf: command not found
    $

    This shows you what it look like when the shell reports mistakes. Note that you will not always see any reports of a particular error. Commands that have no output will just return silently to the prompt.

echo text

    Use the echo command to send text to the terminal. Remember to press the ENTER or RETURN key after each command. Note that this will be particularly useful in your future UNIX/Linux scripts to report information back from your scripts.

    $ echo hello world
    hello world
    $

echo text with variable information

    Use the echo command with an environment variable. it should use your account name.

    $ echo hello $USER
    hello admin
    $

list directory contents

    Use the ls command to list the contents of the current directory.

    $ ls
    Desktop          Movies        Send registration
    Documents        Music         Sites
    Downloads        Pictures
    Library          Public
    $

create a text file

    Use the cat command to create a small text file.

    Type the command line, followed by RETURN or ENTER, then type each of the six suggested lines, each followed by the RETURN KEY. After having enetered each line, make sure you are at the beginning of a new (blank or empty) line and type Ctrl-D (hold downt he CONTROL key and the D key at the same time).

    $ cat > names
    James
    Mary
    John
    Patricia
    Robert
    Linda
    CONTROL-D
    $

    The choice of names is based on the most popular names in the United States in the year before this subchapter was written. Bribe me if you want your name put into the example.

check the file was created

    Use ls to make sure the file was created properly. It should be added to your directory listing.

    $ ls
    Desktop          Movies        Send registration
    Documents        Music         Sites
    Downloads        Pictures      names
    Library          Public
    $

display file contents

    Use the cat command to show the contents of your new file.

    $ cat names
    James
    Mary
    John
    Patricia
    Robert
    Linda
    $

count the number of words

    Use the wc command to count the number of words in your new file.

    $ wc names
           6       6      38 names
    $

    The format is the number of lines (6), followed by the number of words (6), followed by the number of characters (38), followed by the name of the file (names).

copy a file

    Use the cp command to make a copy of a file.

    $ cp names saved_names
    $

    Notice that there is no confirmation of the file copy being made.

    This silent behavior is typical of any UNIX shell. The shell will typically report errors, but remain silent on success. While disconcerting to those new to UNIX or Linux, you become accustomed to it. The original purpose was to save paper. When UNIX was first created, the terminals were mostly teletype machines and all output was printed to a roll of paper. It made sense to conserve on paper use to keep costs down.

    You can use the ls command to confirm that the copy really was made. You won’t be using up any paper.

    $ ls
    Desktop          Movies        Send registration
    Documents        Music         Sites
    Downloads        Pictures      names
    Library          Public        saved_names
    $

rename a file

    Use the mv command to rename a file.

    $ mv saved_names old_names
    $

    Notice that the shell is once again silent with success. You can use the ls command to confirm that the rename really was made.

    $ ls
    Desktop          Movies        Send registration
    Documents        Music         Sites
    Downloads        Pictures      names
    Library          Public        old_names
    $

delete a file

    Use the rm (remove) command to delete a file.

    $ rm old_names
    $

    You can use the ls command to confirm that the file was really deleted.

    $ ls
    Desktop          Movies        Send registration
    Documents        Music         Sites
    Downloads        Pictures      names
    Library
    $

current directory

    Use the pwd command to determine the current directory. Your version should give the name of your home directory, which normally matches the name of your user account. The example include the directory as part of the prompt (your system may not include this) and the tilde ( ~ ) character indicates the home directory.

    $ pwd
    /Users/admin
    admins-power-mac-g5:~ admin$

make a directory

    Use the mkdir command to make a new directory (folder).

    $ mkdir testdir
    admins-power-mac-g5:~ admin$

change directory

    Use the cd command to change to your new directory (folder). if your prompt includes the current directory, then you will see your prompt change to show the new location.

    $ cd testdir
    admins-power-mac-g5:testdir admin$

confirm directory change

    Use the pwd command to confirm that you are now in your new directory.

    $ pwd
    /Users/admin/testdir
    admins-power-mac-g5:testdir admin$

return to home directory

    Use the cd command without any additional arguments to return to your home directory from anywhere.

    $ cd
    admins-power-mac-g5:~ admin$

confirm directory change

    Use the pwd command to confirm that you are now back in your home directory.

    $ pwd
    /Users/admin
    admins-power-mac-g5:~ admin$

    Now you are ready to dive in and start becoming proficient at using the UNIX or Linux shell.

COMMENTS

    “When I was transitioning from OS/2 to Linux, one of the things I found deeply annoying about “tour of shell commands” documents is that they list the command and then tell what it does.
    “That is completely backwards. Nobody sits down at a console and thinks, “I have the urge to type ‘rm’ and the name of an irreplaceable file. I wonder what will happen.”
    “Your reference gets it right. You first answer the question “What do you want to accomplish?” and then you explain how to go about it.”—Michael DeBusk


comments, suggestions, corrections, criticisms

please contact us

your name:
email address:
phone number:
message:

free music player coding example

    Coding example: I am making heavily documented and explained open source code for a method to play music for free — almost any song, no subscription fees, no download costs, no advertisements, all completely legal. This is done by building a front-end to YouTube (which checks the copyright permissions for you).

    View music player in action: www.musicinpublic.com/.

    Create your own copy from the original source code/ (presented for learning programming).


return to table of contents
free downloadable college text book
free downloadable system administrator and shell programming book

view text book
HTML file

Because I no longer have the computer and software to make PDFs, the book is available as an HTML file, which you can convert into a PDF.

previous page next page
previous page next page

free book on UNIX/Linux System Administration

Teach Yourself UNIX/Linux System Administration and Shell Programming

free computer programming text book project

Building a free downloadable text book on computer programming for university, college, community college, and high school classes in computer programming.

If you like the idea of this project,
then please donate some money.

send donations to:
Milo
PO Box 1361
Tustin, California 92781

Supporting the entire project:

    If you have a business or organization that can support the entire cost of this project, please contact Pr Ntr Kmt (my church)

more information on donating

Some or all of the material on this web page appears in the
free downloadable college text book on computer programming.


Google


Made with Macintosh

    This web site handcrafted on Macintosh computers using Tom Bender’s Tex-Edit Plus and served using FreeBSD .

Viewable With Any Browser


    †UNIX used as a generic term unless specifically used as a trademark (such as in the phrase “UNIX certified”). UNIX is a registered trademark in the United States and other countries, licensed exclusively through X/Open Company Ltd.

    Names and logos of various OSs are trademarks of their respective owners.

    Copyright © 2012, 2013 Milo

    Created: August 25, 2012

    Last Updated: August 20, 2013


return to table of contents
free downloadable college text book
free downloadable system administrator and shell programming book

previous page next page
previous page next page