A Short Linux Tutorial For This Course Getting Access To Linux
A Short Linux Tutorial For This Course Getting Access To Linux
http://www.tfd.chalmers.se/~hani/kurser/OS_CFD_2011/Lin...
Working in linux
In Linux you have the option to work graphically or text based. In this course we will work text
based, since that way we have better control of what we are doing (and I am used to working that
way).
To start with, you need to open a terminal window. You do that either by right-clicking on the
desktop and clicking on 'Terminal' or 'Console', or you should be able to find a button looking like
a computer monitor to click on somewhere. Once you have a terminal window open you need to
know some useful Linux commands.
1 of 7
24/09/2013 21:20
Linux commands
cd
(or: cd ~)
2 of 7
http://www.tfd.chalmers.se/~hani/kurser/OS_CFD_2011/Lin...
ls
ls -l
ls -a
mkdir linuxTutorial
cd linuxTutorial
cp myFile.txt copyOfMyFime.txt
rm myFile.txt
mv copyOfMyFime.txt myFile.txt
mkdir aSecondDirectory
cd aSecondDirectory
cd ..
rmdir aSecondDirectory
mkdir -p aSecondDirectory/aThirdDirectory
/aFourthDirectory
24/09/2013 21:20
Linux commands
http://www.tfd.chalmers.se/~hani/kurser/OS_CFD_2011/Lin...
cp myFile.txt
aSecondDirectory/aThirdDirectory
/aFourthDirectory
ls aSecondDirectory/aThirdDirectory
/aFourthDirectory
cd aSecondDirectory/aThirdDirectory
/aFourthDirectory
pwd
cd ../../..
tree -L 3
tree -L 2
tree -d
more myFile.txt
head myFile.txt
tail myFile.txt
tail -f myFile.txt
tailf myFile.txt
Find all files that have the string 'yfi' in their file
name. The string is not case sensitive because
we use the flag -iname. The '*' means 'any
string'. The command is recursive.
sed -i s/"second text line"/"modified text line"/g Substitute the string "second text line" in
myFile.txt
myFile.txt with "modified text". Use your
Linux skills to check that it was done! The
sed-commands can also be used in the 'vi'
editor which will be discussed later.
3 of 7
24/09/2013 21:20
Linux commands
http://www.tfd.chalmers.se/~hani/kurser/OS_CFD_2011/Lin...
mkdir newDirectory
ln -s myFile.txt softLinkToMyFile.txt
touch touchedFile.txt
cd ; rm -r linuxTutorial
exit
Managing processes
Here are some useful Linux commands. If you do all the commands in the same order as they are
presented below you will go through a small tutorial on how to use these commands:
4 of 7
24/09/2013 21:20
Linux commands
http://www.tfd.chalmers.se/~hani/kurser/OS_CFD_2011/Lin...
xlogo &
jobs
fg
CTRL-c
xlogo
CTRL-z
bg
top
kill <PID>
Kill -9 <PID>
which xlogo
Other commands
Find other useful Linux commands by doing the following:
info coreutils
info coreutils ls
info coreutils nohup
5 of 7
24/09/2013 21:20
Linux commands
http://www.tfd.chalmers.se/~hani/kurser/OS_CFD_2011/Lin...
Editing files
For editing files interactively you use a text editor. I commonly use 'vi', which is a VERY simple
text editor. The benefits of vi is that it is quick to open files, and it does not open any new window.
You do the editing directly in the terminal window. Several of the vi commands can also be used
in the man pages and in sed commands. On the downside, there is no graphical user interface.
Search the internet for short introductions to vi, for example: http://www.cs.colostate.edu/helpdocs
/vi.html
Other alternaties are:
emacs
gedit
nedit
6 of 7
24/09/2013 21:20
Linux commands
http://www.tfd.chalmers.se/~hani/kurser/OS_CFD_2011/Lin...
7 of 7
24/09/2013 21:20