Basic
Unix commands (including Cygwin)
Back to DEX-Install/Tutorial
Here are some basic Unix
commands for navigating and exploring data. Since Unix is often run in a
command-line environment, you will have to type commands to see, edit and
change the files and move between them. Here are the very basic commands you
will need to know to run DEX with confidence.
Listing
files and folders, type:
- ls
- Lists the files and folders in the current directory
- ls -lt
- Lists more information about all the files/folders in the current
directory, one file/folder per line
Pattern
matching
- *
-
Example: “ls time*” will list
every file that starts with the word “time” while the command
“ls
time*.dat” will match everything in the folder that begins with “time”
and ends with “.dat”. This is a very powerful feature of Unix and should
be used to reduce the number of commands are need to execute a program.
- Tab
- The
“Tab” button will complete the name of a file or folder if it is
unique. For example, if there is only one file that begins with
“time-2” then simply typing “ls time-2
(Tab)“ will complete the file without having to type the rest of
the letters. This saves a lot of time when most of the files are
unique.
- Ctrl d - This
is typed if you have finished typing part of a filename and you need to
find out which files have that same beginning part in their names.
For example, typing “ls time-2 (Ctrl d)”
will display all the files that have that beginning of the filename
“time-2”. After typing this, you can see what the exact name of the
file you wish is named and type in the rest of the name. When you
combine “Ctrl d” with the Tab button, you typically only need to type a
few letter per name, even if it is long. This saves a considerable
amount of time.
- Up
arrow - Typing the up
arrow on the command line will show you the last command that was
executed. You can just modify this one or run it again to see the
results of the same or new file.
Changing
folders/manipulation of folders
- cd folder-name
- folder-name is the name of the folder you want to move to
- pwd
- Displays what folder you are currently in
- mkdir
- Creates a folder (directory)
- rmdir
- Removes a folder (directory) but it must be empty
Changing/moving
file/filenames
- cp old-filename new-filename
- Copies the old file to the new filename without
erasing the old file
- mv old-filename new-filename
- Changes the old file to the new filename and erases
the old file
- rm filename
- Removes the filename you type
Printing
a file
- lpr –Pprinter-name
- printer-name is the name of the Unix networked printer. If you do
not have a printer setup with the Unix commands, you will have to find the
file in the window system and print how you would normally print it.
Cygwin users: You can open regular text files in MS Word and
save and print them normally.
Viewing
contents of a file
- vi filename
- vi is a visual program to view the text in a file such as the results
from a program.
- head filename
- Shows the first 10 lines of a file
- tail filename
- Shows the last 10 lines of a file.
Executing/Stopping
programs
- To execute a program, you
only need to type its name. You may need to type “./” before the
name, if your system does not check for executables in that file.
- Ctrl c
- This command will cancel a program that is running or won’t automatically
quite. It will return you to the command line so you can run
something else.
vi
program
Once you type the command
above, the window will display the text. Unlike a regular document
program, vi does not let you just type using the keyboard. Instead, each
key has a function, such as move the cursor left or down. Here are the
basic commands you can use to edit and save the commands. You can use the
arrow keys just like normal, and must be used to move the cursor to the place
you want to start typing/editing. The mouse will not work in the standard
“vi” program, only the keyboard is used. This takes some getting used
to.
- i
- insert is similar to “a” but is to the left of where the cursor is.
- a
- appends to the data, after typing “a” you can use the keyboard to type
in letter/numbers like a normal word processing program. When you
are done typing what you want at that location, you need to hit the “Esc”
button before you can return to the regular mode.
- Esc
- escape ends the current mode you are in (i.e. typing mode) and takes you
back to the original.
- x
- Typing “x” lowercase will erase the character on the cursor, like the
“Backspace” key does in a normal word processing program. The
“Delete” button will do the same thing in the regular mode.
- :w
- saves all the changes you made to a existing file name.
- :w new-filename
- saves all the changes you made to a new filename you specify.
- ZZ
- Capital ZZ. This will save and quit the “vi” program and bring you
back to the command line.
- :q!
- This will quite the “vi” program without saving the last changes you
made.
- u
- This is undo, and will undo the last action you have completed.
- dd
- This will erase the entire line. Tying a number before typing “dd”
will remove the number of lines chosen.
- :se nu -
This is to “set number lines” which will temporarily number the lines of
the document for you.
- Ctrl f -
This will page down the document by one screen length.
- Ctrl b -
This will page up the document by one screen length.
- G
- This will move the cursor to the end (bottom) of the document
- 1G
- This will move the cursor to the top of the document