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:
- TODO screencast
- UNIX tutorial for beginners
- Linux commands cheat sheet
- Ubuntu
- TU/e linux wiki
Essential commands to know are:
-
lslist the directory (folder). -
cd dirchanges 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 dircreate directorydir. -
cp file1 filecopiesfile1tofile2
cp file1 dir1copyfile1into directorydir1.
cp -r dir1 dir2copy directorydir1todir2(ifdir2does not exist) or copydir1intodir2(ifdir2exists). -
mv file1 file2move (rename)file1tofile2
mv file1 dir1movefile1to the directorydir1. -
rm fileremove file.
rm prefix*remove all files starting withprefix.
rm *suffixremove all files ending withsuffix. Note the*is a wild card to match filenames. Thusrm *removes all files in the current directory.rm a*bremoves all files starting withaand ending inb. -
rmdir dirremove directorydir. It must be empty.⚠️ Warning
Removing files or directory is irreversible! There is no undo, trash, or bin.
-
more filedisplay file, one page at a time. -
cat filedisplay file, all at one (does not stop scrolling). -
sudo haltstop the operating system -- use this to stop using the PYNQ board. -
unzip file.zipto extract all the files in the zip file in the current directory. -
zip -r file.zip file1 file2 dir3to create a zip file calledfile.zipthat contains all the files and directories that are listed. -
nano fileedit file with the nano editor. The file is created if it doesn't exist. -
man commandread the manual for command. -
man -k commandsee 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 calleda.outunless we specify otherwise. -
makecompile the program in the current directory. Usually produces an executable calledmain. -
./a.outexecute the program calleda.outin the current directory. -
./mainexecute the program calledmainin 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@computernameto log in asusernameon the computer with namecomputername. 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 fileworks the same ascpbut 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
- copy file-on-your-laptop to /home/student/file-on-your-laptop
- 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
- copy file-on-pynq to file-on-your-laptop:
- from your laptop to PYNQ:
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 typingfg(foreground). It can be killed by typingkill %1.^Zcan usually be used even when when^Cdoes not work.