Basic shell commands

Introduction

This page contains quick references for basic shell commands and links to more detailed resources. Users need to know basic shell commands to navigate directories and modify files for use on CHTC systems. Users can reference this page to gain familiarity or refresh their knowledge of shell commands.

Learn about the command line

Why should you learn about the command line?

If you haven’t used the command line before, it might seem like a big challenge to get started. However, we strongly recommend learning more about the command line for multiple reasons:

  • Only a few basic commands are needed to successfully submit jobs on CHTC.
  • With practice, typing on 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.

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 -lh prints human-readable information
ls list files in current directory -a prints 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 to vim, 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 phrase in file

Edit files

Command Use Notes
nano <file> opens or creates file in the nano text editor cheatsheet for nano commands
vim <file> or vi <file> opens or creates file in the vim text editor cheatsheet for vim commands

Copy, move, and remove files

Command Use
cp <file1> <file2> copies file1 to file2
mv <file1> <file2> moves or renames file1 to file2
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 ?.txt removes 1.txt and b.txt but not 24.txt
* matching any characters of any length Example: rm *.txt removes all files with the .txt extension

Read more about wildcards.

Other commands

Commmand Use Notes
echo <$var> prints the value of $var Example: echo $PWD returns the current directory
chmod +x adds executable permissions to a file  

Below are more resources for learning the basic shell commands and the command line.