Basic Unix Commands#


cd (Change Directory)#

Description: cd is used to navigate from a directory to another directory.

Example:

  • cd /glade/u/home/jiangzhu - Changes the current directory to home directory

  • cd ~ - Brings you to your home directory as well

  • cd /glade/work/jiangzhu/paleocamp/cesm2.1.5 - Changes the current directory to a CESM Source Code directory


ls (List):#

Description: ls` lists the files and directories in the current directory or a specified directory, along with file permissions, sizes, and timestamps.

Example:

  • ls - Lists the files and directories in the current directory.

  • ls -l - Provides more information such as the permissions settings, the file size, the time of creation etc.

  • ls -l /glade/work/jiangzhu/paleocamp/cesm2.1.5 - Lists the specific directory

  • ls -ltr - Lists the files in reverse order of the time they were created. This can be useful when your model run crashes and you want to see which log file was most recently created.


pwd (Print Working Directory):#

Description: pwd displays the name of the current working directory, which is the directory in which you are currently located.

Example:

  • pwd - Displays the location of the current working directory, such as /glade/u/home/jiangzhu.


cp (Copy):#

Description: cp copies files or directories from a source location to a destination location.

Example:

  • cp file1 file2 - Copies the contents of file1 to file2

  • cp -r directory1 directory2 - Copies the contents of directory1 to directory2. The flag -r here means recursively


rm (Remove):#

Description: rm deletes files or directories. Be cautious, as the operation is irreversible.

Example:

  • rm file1 - Deletes a file named file1

  • rm -rf directory1 - Removes a directory named directory1 and all of its contents


mv (Move):#

Description: mv moves or renames files and directories. It can also be used to move files from one directory to another.

Example:

  • mv file1 file2 - Renames file1 to file2

  • mv file1 directory1 - Moves file1 into the directory directory1


grep (Global Regular Expression Print):#

Description: grep searches for lines containing a specified pattern within one or more text files. Useful for text searching and pattern matching.

Example:

  • grep hello file.txt - Searches for the string hello in the file.txt file and displays all lines containing that string

  • grep -r directory1 - Searches for a string recursively within all files that are in the directory directory1


wildcards (*):#

Description: * can be used as a wildcard in Unix, i.e., to represent any combination of characters.

  • grep hello *.txt - Searches for the string hello but only in files that end in .txt


git clone (get code from GitHub respository)#

Description: git clone clones a repository into a newly created directory

Example:

  • git clone https://github.com/jiang-zhu/paleocamp clones the paleocamp respository (including notebooks) into a newly created folder, paleocamp in the working directory.


Unix Tutorial from UCAR’s COMET Program#

From the Tutorial, you can learn

  • the basics of Unix file structures

  • how to navigate in a Unix environment

  • hot to create, store and search for files.

The expected length is 15-30 minutes for users with some Unix experience, and 30-60 minutes for novices.