» tagged pages
» logout
Unix
Return to BASH Cures Cancer Blog

Shell Programming Beginners Class Lesson 3 - Essential Commands

Make further edits, (or Cancel)

(or Cancel)

(Editing anonymously: to be credited for your changes, login or register a new account)

(or Cancel)

Tags Applied to this Entry

1 person has tagged this page:

Knowing commands is essential to using the command line. It is even more so when programming the command line.
However, you don’t have to know them yet! I can teach you the basics and then you can learn as you go. The most important thing you can possibly get from this article is the next sentence. UNIX/Linux systems have the ENTIRE user manual in neat organized sections relating to the specific command you want to know about. Its called the man pages or manual pages. Just type “man” and then any command. Example “man find”.

This is the third installment of Shell Programming Beginners Class. If your reading this article first and would prefer to start from the beginning you can do so here: motivation or if you would simply like to read the previous article, it is available here: variables.

Commands in UNIX/Linux, Windows, and Mac OS all follow the same format. That is “command options”. Technically options are arguments but who cares. Example “find /home/brock -name ‘ECON1001*’” or “rmdir test_directory”.

Enough already, here is the list in no particular order:

  1. cd: change to a different directory
  2. cp: copy files and directories
  3. more: used for viewing a file one page a time
  4. less: less is more (less is better than more)
  5. mv: mv or rename files and directories
  6. vi: a text editor
  7. rmdir: remove empty directories
  8. rm: remove files and directories

Most of the commands should be self explanatory. cd changes from one directory to another, cp copies things, rm removes
things, and rmdir removes empty directories. Your probably not sure why we have rm and rmdir or possibly what less, more, and vi are.

rmdir exists basically as the “correct” or “safe” way to deal with deleting files and directories. The command line does not have a trash bin. When its gone its gone. Thus typically rm has the -i option enabled by default which asks your to confirm EVERY SINGLE TIME you want to delete a file. Then your supposed to remove all the files in a directory and then and only then delete it with rmdir. So what does everyone do when they want to delete something? “rm -rf”.

rm -rf is joking called the nuclear option in some very dorky circles. It deletes recursive and does not prompt. Running “rm -rf /” will bring your system down and delete everything on your hard disk.

When using the command line you typically have a small window where you type in your commands. As you type in commands
the output scrolls to the top of the window and then eventually disappears after you have scrolled all the way up. Thus
the need for more and less. They allow you to view a file one page a time. Less is more, than more.

vi is the windows notepad of UNIX/Linux although its very hard to learn for new people. If you have the command “nano”
or “pico” available (just type it in) and are getting distressed with vi, give them a try. I’d rather have you never learn
vi than to never learn the command line because of vi.

If you have no idea what I am talking about, here is a few sample commands being executed. When the user types “vi file”
they would see a screen which you will not see below. But after closing vi they would return to seeing what we see below. The user copies a file, edits the new file, and then removes the old one. Looks like some cheating is going on.

# cp econ1101-brad.doc econ1101-jessica.doc
# vi econ1101-jessica.doc
# rm econ1101-brad.doc
Username:
Password:
(or Cancel)