This subchapter looks at simple UNIX/Linux commands to get you started with using the shell.
You will learn the basic format or structure of a shell command.
You can run a UNIX (or Linux or Mac OS X) command (also called a tool) by typing its name and then the ENTER or RETURN key.
commands and utilities
A quick note on the difference between commands and utilities.
A utility is a program. who, date, and ls are examples of utility programs.
A command is all of the text typed at the command line, the utility name and all of the flags, switches, file names, and other text.
This subtle distinction between utilities and commands is generally ignored and the two terms are often used interchangeably. As I type this, I am pretty sure that I have ignored this distinction elsewhere in this book and dread double-checking every use. You can probably use the terms interchangeably except in cases like tests, papers, or books.
The kernel is loaded from hard drive (or other storage) when the computer is started and remains running until the computer is turned-off or crashes.
Utilities are also stored on hard drives, but are only loaded into main memory when used.
single command
The most simple form of a UNIX command is just a single command by itself. Many UNIX/Linux commands will do useful work with just the command by itself. The next examples show two commands (who and date) by themselves.
The output generated by a single command by itself is called the default behavior of that command.
who
The who command will tell you all of the users who are currently logged into a computer. This is not particularly informative on a personal computer where you are the only person using the computer, but it can be useful on a server or a large computing system.
Type who followed by the ENTER or RETURN key.
$ who admin console Aug 24 18:47 admin ttys000 Aug 24 20:09 $
The format is the login name of the user, followed by the users terminal port, followed by the month, day, and time of login.
failed command
The shell will let you know when you have typed something it doesnt understand.
Type asdf and then the ENTER or RETURN key. You should see a message similar to the following:
$ asdf -bash: asdf: command not found $
date
The following example uses the date command or tool.
$ date Wed Nov 10 18:08:33 PST 2010 $
The format is: day of the week, month, day of the month, 24 hour time, time zone, year.
options, switches, or flags
A command may optionally be followed by one or more options. The options are also commonly called flags or switches.
Options are usually a single character. Usually the option is preceded by a minus sign or hyphen character.
See the following example.
universal time
Adding the -u flag to the command date will cause it to report the time and date in UTC (Coordinated Universal) time (also known as Zulu Time and formerly known as Greenwich Mean Time or GMT). The seconds are slightly higher in the second example because of the passage of time.
$ date Sat Aug 25 19:09:19 PDT 2012 $ $ date -u Sun Aug 26 02:09:27 UTC 2012 $
arguments
Commands may also optionally have arguments. The most common arguments are the names of files.
Technically, the options just mentioned are also arguments, but in common practice options are separated from other arguments in discussions. Also, technically, the operators mentiond below are also arguments, but again it is useful to separate operators from other arguments in discussions.
The following shows the difference between the default behavior (no arguments) of who and a version with arguments who am i.
The default behavior of who lists all users on the computer.
$ who admin console Aug 24 18:47 admin ttys000 Aug 24 20:09 $
The use of the arguments with who am i causes the command to only lists the one user who typed the command.
The command is who and the arguments are am i.
$ who am i admin ttys000 Aug 25 17:30 $
one argument
In an upcoming subchapter on the cat you will use the command cat with the file name file01.txt to confirm that you correctly entered your sample file.
just observe this example do not type this into your shell
$ cat file01.txt This is a line of text in my first file. This is another line.
In the upcoming subchapter on the cat you will use the command cat with two file names (file01.txt and numberfile.txt) to confirm that you correctly entered two of your sample files.
just observe this example do not type this into your shell
$ cat file01.txt numberfile.txt This is a line of text in my first file. This is another line.
You can combine options and arguments on the same command line.
The following example uses the command cat with the -b option and the file name file01.txt.
just observe this example do not type this into your shell
$ cat -b file01.txt 1 This is a line of text in my first file. 2 This is another line.
3 To be, or not to be: that is the question:
4 1234567890 5 ABC 6 XYZ 7 abc 8 xyz $
operators and special characters
Command lines may include optional operators or other special characters.
In an upcoming subchapter on the cat you will use the command cat with the operator > and the file name file01.txt to enter your sample file.
just observe this example do not type this into your shell
$ cat > file01
If you accidentally typed in the above command, hold down the CONTROL key and the D key at the same time to return to your 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.