Skip to content

Introduction to Linux

This page introduces the basics of using Linux.

Linux is a widely used operating system. In fact, the C programming language was invented to program the Unix operating system. See Wikipedia.

You will need to use Linux commands in the terminal. Have a look at the screencast for a short demonstration and the following links:

Essential commands to know are:

  • ls list the directory (folder).

  • cd dir changes the working directory (where you are) to dir. Omitting dir takes you to your "home directory". Note that the prompt tells you where you are. . is the current directory and .. is the parent directory. Thus i.e. cd .. takes you one directory up in the tree of directories. student@pynq:~/$ means that your user name is student, you're logged in on the pynq computer, and that your current directory is your home directory (~).

  • mkdir dir create directory dir.

  • cp file1 file copies file1 to file2
    cp file1 dir1 copy file1 into directory dir1.
    cp -r dir1 dir2 copy directory dir1 to dir2 (if dir2 does not exist) or copy dir1 into dir2 (if dir2 exists).

  • mv file1 file2 move (rename) file1 to file2
    mv file1 dir1 move file1 to the directory dir1.

  • rm file remove file.
    rm prefix* remove all files starting with prefix.
    rm *suffix remove all files ending with suffix. Note the * is a wild card to match filenames. Thus rm * removes all files in the current directory. rm a*b removes all files starting with a and ending in b.

  • rmdir dir remove directory dir. It must be empty.

    ⚠️ Warning

    Removing files or directory is irreversible! There is no undo, trash, or bin.

  • more file display file, one page at a time.

  • cat file display file, all at one (does not stop scrolling).

  • sudo halt stop the operating system -- use this to stop using the PYNQ board.

  • unzip file.zip to extract all the files in the zip file in the current directory.

  • zip -r file.zip file1 file2 dir3 to create a zip file called file.zip that contains all the files and directories that are listed.

  • nano file edit file with the nano editor. The file is created if it doesn't exist.

  • man command read the manual for command.

  • man -k command see if there's anything in the manual related to command.

  • gcc file1.c file2.c ... use the C compiler to compile one or more files. The result of the compilation is called a.out unless we specify otherwise.

  • make compile the program in the current directory. Usually produces an executable called main.

  • ./a.out execute the program called a.out in the current directory.

  • ./main execute the program called main in the current directory.

The following are useful if you use ssh to log in to the PYNQ board.

More information on using a terminal interface (ssh and scp).

  • ssh username@computername to log in as username on the computer with name computername. We use this to log in from your laptop to the PYNQ (ssh student@10.43.0.1 ), but you can actually log in to any computer connected to the internet that allows the ssh protocol.

  • scp file1 file works the same as cp but allows you to copy between your laptop and the PYNQ board. You have to type in the PYNQ password before the copying starts.
    All the following commands have to executed on your laptop.

    • from your laptop to PYNQ:
      • copy file-on-your-laptop to /home/student/file-on-your-laptop
        scp file-on-your-laptop student@10.43.0.1:
      • copy file-on-your-laptop to /home/student/directory/new-name:
        scp file-on-your-laptop student@10.43.0.1:directory/new-name
      • copy directory-on-your-laptop to /home/student/directory/new-directory:
        scp -r directory-on-your-laptop student@10.43.0.1:new-directory
    • from PYNQ to your laptop is similar, just swap the source (now student@10.43.0.1:) and destination, e.g:
      • copy file-on-pynq to file-on-your-laptop:
        scp student@10.43.0.1:file-on-pynq file-on-your-laptop

The following key combinations are essential to know:

  • control+c (written ^C): stop/kill the current command or program

  • control+z (written ^Z): suspend the current command or program. It can be resumed by typing fg (foreground). It can be killed by typing kill %1. ^Z can usually be used even when when ^C does not work.