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:
-
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 directorydir
. -
cp file1 file
copiesfile1
tofile2
cp file1 dir1
copyfile1
into directorydir1
.
cp -r dir1 dir2
copy directorydir1
todir2
(ifdir2
does not exist) or copydir1
intodir2
(ifdir2
exists). -
mv file1 file2
move (rename)file1
tofile2
mv file1 dir1
movefile1
to the directorydir1
. -
rm file
remove file.
rm prefix*
remove all files starting withprefix
.
rm *suffix
remove all files ending withsuffix
. Note the*
is a wild card to match filenames. Thusrm *
removes all files in the current directory.rm a*b
removes all files starting witha
and ending inb
. -
rmdir dir
remove directorydir
. 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 calledfile.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 calleda.out
unless we specify otherwise. -
make
compile the program in the current directory. Usually produces an executable calledmain
. -
./a.out
execute the program calleda.out
in the current directory. -
./main
execute the program calledmain
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 asusername
on 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 file
works the same ascp
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
- 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
.^Z
can usually be used even when when^C
does not work.