Computer Skills for Research
The Unix/Linux command line
By Mark Ciotola
First published on October 10, 2019. Last updated on February 16, 2020.
This section will refer to the Unix/Linux command line. If you have access to a Unix server, you can access it on an internet-connected Widows machine by using the Prompt, SSH or Putty programs.
The command line is a way to directly enter commands and send them to the operating system. Therefore the command line can be extremely powerful. Yet the jargon to be entered in command lines is tedious and often bewildering to the novice (even if they have worked with computers for many years).
Most computers come with “terminal” programs to access the command line. On OS X (macOS), the program is simply called “Terminal” and is found in the Utilities folder. Use a terminal emulators for Windows instead of the DOS command line. Console is available for free for Windows. Some of the newer Windows systems will run Unix commands without installing additional software, but older ones will not. Most machines running Linux offer ome with a terminal utility under various names.
We will use Unix operating system commands. Linux is an open source version of Unix. Here are some of the most useful commands. You should practice them.
How to Use the Command Line
To use the command line, simply type a command (along with any options and arguments) and hit the enterkey (may be return key on some systems).
Some commands, such as pico or man, will take you into different environments, each of which have their own particular methods of navigation and entry. You should find out how to use such commands before entering them.
Useful Directory Commands
Command | What It Does |
---|---|
date | current date |
cal | calendar |
bc | calculator environment (type 1+1 and hit return) |
ls | to view the sub-directories and files in a directory |
pwd | to determine the path of your current directory |
cd | directory path and name to change to the specified directory |
cd .. | to go up one level to the parent directory (folder) |
history | lists your recent commands |
logout | logs out of terminal application |
exit | logs out of terminal application |
Dangerous Directory Commands
Command | What It Does |
---|---|
rm | removes file whose name follows command |
Command Options
Unix provides options for many of its commands. To use an option, typically type “-” plus one letter for each option desired. Below are some examples of options for the lscommand.
- ls -l to view a more information-rich list of the sub-directories and files in a directory
- ls -a to view both the hidden and non-hidden sub-directories and files in a directory. Typically anything that begins with a “.” is hidden.
Some options are available in a “–” word format. Here are a few examples for comparison.
- -v for version, particularly for programs
- –version for version, particularly for programs
- -h for help
- –help for help
Arguments
Many Unix commands take arguments. If a command is as a verb, then an argument would be an object upon which the verb acts. For people “eat” would be the command and “fruit” would be the object in the sentence “Eat fruit”. A typical argument for a Unix command would be a file or directory name.
For example, cp is a command to copy files. So the command and arguments “cp filename1.txt filename2.txt” would copy the contents of filename1.txt into the file filename2.txt. If filename2.txt does not yet exist, this command will create it. If filename2.txt does exist, the command will replace it! (So such commands should be used with great care!)
More Useful Commands
man command name | produces documentation for some commands |
---|---|
mkdir directory name | makes a directory with the indicated name in the current directory |
rmdir directory name | removes contents of an empty directory |
mv file1file2 | moves or renames files |
cat filename | displays one or more files sequentially |
more filename | views files one page at a time |
Wild Card
- (asterisk) can act as a wildcard character. For example, rm *.* would remove all files.
Getting Out
You can usually type control C or control D to get out of particular environments, in case you get stuck. You may lose your work, though.
Learning More
There are many more Unix commands and options. Also, some installations or Unix or Linux may vary. There are many books t learn more, and a web search will usually produce commands and help for them for just about anything you wish to achieve.