Practice Commands
Try the following set of commands to get practice with linux. Remember,
you need to login first.
- Type: "ls" to list all the files in your home directory. You
can also use "dir". At this point you should see the files "hello.cpp"
and "a.out".
- Type: "pwd" to see what directory you are in. It should
respond with something like, "/home/students/2011/username"
- Type: "cat hello.cpp" to print the file hello.cpp to the screen.
- Type: "cp hello.cpp hello_copy.cpp" to create a copy of the
hello.cpp program.
- Type: "ls" to list all your files again (you should see three files
now).
- Type: "rm hello_c*" to delete the copy. Note that the "*"
character is a wildcard which matches zero or more characters.
- Type: "ls -a" to see alot more files than before. The "-a" is
called a "command line option." In this case, the option "-a" says to
show all files. Usually, the files beginning with a "." are not
shown. Two special files are "." and "..", which represent the current
directory and the parent directory, respectively.
- Type: "cp hello.cpp hello_version2.cpp" to create another copy of
the hello.cpp program.
- Type: "mv hello_version2.cpp hello_there.cpp" to move the file
hello_version2.cpp to a new file named hello_there.cpp. The "mv" command is how you rename files in linux.
- Type: "vi hello_there.cpp". At this point, things are
different than before, you don't get the system prompt back like before.
That's because your running the "vi" program. "Vi" is an editor, like
notepad under Windows, only you don't use it with a mouse. "Vi" is
really powerful, it just sort of looks old-fashioned. If you want to learn more
about vi see the on-line tutorial for vi (here). However, you don't need to use "vi" if you would rather use X-Win32 or Chameleon. Remember, you have a choice in which environment you want to program in
BTW, if you decide to try "vi" and all the information overwhelm's you, just keep in mind that you can "get
by" with the following information.
- Vi has two modes: command mode and insert mode. You switch
between the modes as follows:
- Type "i" to get in insert mode.
- Type <esc> to get in command mode (<esc> is the "escape" key)
- When you are in insert mode:
- Use the arrow keys on your keyboard to move where you want to type.
- Use the <backspace> or <delete> key to erase what you don't want.
- Use the rest of the letter and number keys to insert text.
- When you are in command mode:
- Use the arrow keys to move around.
- Use the command "ZZ" to write and save your changes, or the command
":q!" if you don't want to save your changes.
- Use "J" to put two lines together.
- Using what you now know about vi (or any other editor), try to change the program to write out
"Hello your-name". Then save and exit vi using the command "ZZ".
- Type: "g++ hello_there.cpp" to compile the program.
- Type: "a.out" to run the program.