Quick reference: Basic shell commands
Introduction
This page contains quick references for basic shell commands and links to more detailed resources. You should learn basic shell commands to navigate directories and modify files on CHTC systems. Reference this page to learn or refresh your knowledge of shell commands.
Table of Contents
Learn about the command line
Why should you learn about the command line?
If you haven’t used the command line before, it may be challenging to get started. However, we strongly recommend learning more about the command line for multiple reasons:
- You only need to know a few basic commands to submit jobs.
- With practice, using the command line is significantly faster and much more powerful than using a point-and-click graphic interface.
- Command line skills are useful for more than just large-scale computing!
For beginning users: Get started with the command line
For a good overview of command line tools, see the Software Carpentry Unix Shell lesson. We recommend that you learn how to:
Quick reference: Basic shell commands
Note: Bracketed items (<>) denote where to place your input. Do not include the brackets in your command.
Navigate directories
| Command | Use | Notes | 
|---|---|---|
| cd <path/to/directory> | changes current directory to path/to/directory | .- the current directory | 
| ..- one level above the current directory | ||
| ~- your home directory (/home/username/) | ||
| pwd | prints path of the working (current) directory | |
| ls <directory> | lists files in directory | -lhprints human-readable information | 
| ls | list files in current directory | -aprints hidden files | 
| mkdir <directory> | creates a directory | |
| rmdir <directory> | removes a directory (must be empty) | 
Inspect files
| Command | Use | 
|---|---|
| cat <file> | prints contents of file | 
| less <file> | views contents of file(similar tovim, but without edit capabilities) | 
| head <file> | prints the first ten lines of file | 
| tail <file> | prints the last ten lines of file | 
| grep <phrase> <file> | grabs and prints every instance of phraseinfile | 
Edit files
| Command | Use | Notes | 
|---|---|---|
| nano <file> | opens or creates filein thenanotext editor | cheatsheet for nano commands | 
| vim <file>orvi <file> | opens or creates filein thevimtext editor | cheatsheet for vim commands | 
Copy, move, and remove files
| Command | Use | 
|---|---|
| cp <file1> <file2> | copies file1tofile2 | 
| mv <file1> <file2> | moves or renames file1tofile2 | 
| rm <file1> | removes file1 | 
| scp <file> <destination> | moves files between machines. See how to transfer files to/from your local computer | 
Wildcards
| Wildcard | Use | Notes | 
|---|---|---|
| ? | matching any character | Example: rm ?.txtremoves1.txtandb.txtbut not24.txt | 
| * | matching any characters of any length | Example: rm *.txtremoves all files with the.txtextension | 
Read more about wildcards.
Other commands
| Commmand | Use | Notes | 
|---|---|---|
| echo <$var> | prints the value of $var | Example: echo $PWDreturns the current directory | 
| chmod +x | adds executable permissions to a file | 
Related pages
Browse these resources for learning basic shell commands and the command line.