CSCI-1411-Basic-Unix-Commands

Common Unix Commands

This page documents some of the basic Unix commands (specifically those used in class) and how should be used. In the guide below the command name will be shown in bold. If you have to provide additional information like the name of a folder (this name is called an argument) it will be shown in italics. Note: If you are using a Mac with the terminal you can also use these commands (Assuming that you are using the UCDenver VPN and you have connected to the CSE grid using SSH).

    HorizontalLine

  • ls
    (List) – Lists the files and directories in your current location. Use this command every time you would like to see what files and folders are in your current working directory (to check your current working directory use the pwd command.

    Example: I want to print the names of all files in the current directory.

    [username@ucdenvercsenode05 ~]$ ls
    main.cpp test.cpp firstprog.cpp
    [username@ucdenvercsenode05 ~]$

  • HorizontalLine

  • cd directoryname OR ..
    (Change Directory) – Changes your current working directory. The directory you change to must be shown when you use the ls command.

    Example: I want to change to the myHelp directory (go into the myHelp directory) and then I want to come back out of that directory. This shows the process of entering and exiting directories by specifying their name (to go into) and by using two dots .. to come out of a directory.

    [username@ucdenvercsenode05 ~]$ ls
    myFolder myHelp
    [username@ucdenvercsenode05 ~]$ cd myHelp
    [username@ucdenvercsenode05 myHelp]$ cd ..
    [username@ucdenvercsenode05 ~]$ ls
    myFolder myHelp

  • HorizontalLine

  • pwd
    (Print Working Directory) – This command prints the current working directory, that is, your current location in the directory hierarchy.

    Example: After logging in you can enter the pwd command to display your current position in the directory hierarchy on the CSE Unix grid. The output will be similar to the following.

    [username@ucdenvercsenode05 ~]$ pwd
    export/homes/username/
    [username@ucdenvercsenode05 ~]$

  • HorizontalLine

  • mkdir directoryname
    (Make Directory) – This command makes a directory in your current location. To check your current location use the pwd command.

    Example: I want to create a new directory named: myHelp. You can then display the new folder using the ls command.

    [username@ucdenvercsenode05 ~]$ mkdir myHelp
    [username@ucdenvercsenode05 ~]$ ls
    myHelp

  • HorizontalLine

  • rmdir directoryname
    (Remove Directory) – This command removes an existing directory. Note that you must match the name of the directory as it is shown by the ls command.

    Example: I want to remove the myHelp directory. List the contents of the current directory using ls, then remove the directory with rmdir.

    [username@ucdenvercsenode05 ~]$ ls
    myHelp
    [username@ucdenvercsenode05 ~]$ rmdir myHelp
    [username@ucdenvercsenode05 ~]$ ls
    [username@ucdenvercsenode05 ~]$

  • HorizontalLine

  • mv filename directoryname
    (Move) – Move the file given by filename to the specified directory given by directoryname

    Example: I want to move help.cpp into the directory myHelp. List the current directory with ls, then use the mv command.

    [username@ucdenvercsenode05 ~]$ ls
    myHelp help.cpp
    [username@ucdenvercsenode05 ~]$ mv help.cpp myHelp
    [username@ucdenvercsenode05 ~]$ ls
    myHelp
    [username@ucdenvercsenode05 ~]$ cd myHelp
    [username@ucdenvercsenode05 myHelp]$ ls
    help.cpp

  • HorizontalLine

  • nano filename
    (Nano Editor) – This command will open the Nano editor where you can edit the text of a file by using the terminal interface. For example you would not have to use WinSCP to upload a c++ source file, you could simply enter the command nano main.cpp. This would open the nano editor in the terminal and allow you to type in the file main.cpp. However since most labs contain source code from which you can work off of, I would suggest just uploading those files instead of retyping them. There are various tutorials on the internet that describe how to use nano.
  • HorizontalLine

  • vi filename
    (VIM) – Another text editor entirely controlled by keyboard short-cuts. Use this program if you feel that nano isn’t enough of a challenge. There are various tutorials online that explain the intricacies of this editor. If you don’t already know how to use this program and value your free time, I would suggest using nano or another text editor.