music |
| | 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.
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 wont 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
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).
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.
Names and logos of various OSs are trademarks of their respective owners.