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.
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.
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_named 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.
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.
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).
Create your own copy from the original source code/ (presented for learning programming).
Work on this project is very slow because I am homeless. I am available for work if someone can provide an indoor place to work in Costa Mesa, California, electricity, internet connections, a flat raised working surface (such as a table or desk), a sitting device (such as a chair or stool), and a fully functional reasonably modern used computer. Im already homeless, so you dont need to pay me (and I understand how much business people hate the minimum wage law). Just give me a chance to work.
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
At the time I am homeless. This greatly interferes with my ability to create this project, which can help nearly 20 million U.S. college students and more than 150 million students world-wide. I am looking for 30 rich people or corporations willing to donate $10 a month to my church so that the church can provide a place indoors for me to continue work. If you want to donate, please see help project. Thanks much.
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)
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.