Linux basics: terminal, file management, ssh etc J. Rabault 11th February 2016

advertisement
Linux basics: terminal, file management,
ssh etc
J. Rabault
11th February 2016
A few words about Linux
Linux is an Operative System, that has several advantages compared with Windows or Mac: it
is free, all its code is available (OpenSource), it has few bugs, is much lighter than windows, is
virus free, and very flexible. There is a number of distributions of Linux (Ubuntu, RedHat,
Debian, etc), which are basically different packaging for the same central piece of software.
There is a learning curve when starting to use Linux, but after some time you will become
much more effective with it than with other systems.
The community of Linux users is large, and therefore you will find a lot of help by googling
any problem or question you have. This document is not a course about Linux and is far from
exhaustive, but it should allow you to get started up to the point where you are able to search
for help on the internet by yourselv.
1 Linux terminal
1.1 Getting started
If you want to use Linux efficiently, you will have to use the terminal. You can do pretty
everything from terminal. Often it will be faster than using the Graphical User Interface
(GUI), but there are even quite a few things you cannot do from the GUI but can do from
terminal.
To open a terminal, click on Applications > Terminal or use the shortcut on you Desktop.
You should then be given a prompt, which in my case looks like:
[ jeanra@belet−i l i ~] $
This indicates that I am logged as jeanra, on the computer belet-ili, and that I am in my
home directory (represented by ~).
1.2 Basic commands
Here are a few of the most basic commands you need to know to use the linux terminal:
1
Linux Basics
• pwd stands for ’print working directory’. It indicates in which directory your terminal is
currently working. To use the is command, you should just type in terminal pwd and
press enter.
• cd stands for ’change directory’. This is used to change the directory in which your
terminal is working. You can see an example here:
[ j e a n r a @ b e l e t − i l i ~ ] $ pwd
/mn/ anatu / a n s a t t e −u5/ j e a n r a
[ j e a n r a @ b e l e t − i l i ~ ] $ cd Desktop /
[ j e a n r a @ b e l e t − i l i Desktop ] $ pwd
/mn/ anatu / a n s a t t e −u5/ j e a n r a / Desktop
There are a few tricks to know: cd .. will make you move to the parent directory, cd ~ will
make you move to your home directory. In addition, you can use the tab key to search
for autocompletion. Pressing it once will complete your folder name if there is only one
possibility. Pressing it twice will show all alternatives.
• ls stands for ’list files’. It displays all the files (and folders) in your current directory. You
can use ls with some options. For example, ls -a will display all files and folders, including
the hidden ones (that start with .), ls -l will display everything as a list, ls -la will display
all files as a list.
[ jeanra@belet− i l i BasicsOfTerminal ] $ l s
Figures
Template_Basic . aux Template_Basic . b l g
Template_Basic . pdf
S c r i p t C o m p i l e Template_Basic . b bl Template_Basic . l o g
Template_Basic . t e x
[ j e a n r a @ b e l e t − i l i B a s i c s O f T e r m i n a l ] $ l s −a l
t o t a l 216
drwxrwxr−x . 3 j e a n r a j e a n r a
4096 Feb 11 1 5 : 3 1 .
drwxrwxr−x . 9 j e a n r a j e a n r a
4096 Feb 11 1 5 : 0 7 . .
drwxrwxr−x . 2 j e a n r a j e a n r a
4096 Dec 17 1 4 : 5 9 F i g u r e s
−rwxrwxr−x . 1 j e a n r a j e a n r a
94 Dec 17 1 5 : 0 0 S c r i p t C o m p i l e
−rw−rw−r −−. 1 j e a n r a j e a n r a
470 Feb 11 1 5 : 2 8 Template_Basic . aux
−rw−rw−r −−. 1 j e a n r a j e a n r a
0 Feb 11 1 5 : 2 8 Template_Basic . b bl
−rw−rw−r −−. 1 j e a n r a j e a n r a
1031 Feb 11 1 5 : 2 8 Template_Basic . b l g
−rw−rw−r −−. 1 j e a n r a j e a n r a 57466 Feb 11 1 5 : 2 8 Template_Basic . l o g
−rw−rw−r −−. 1 j e a n r a j e a n r a 116216 Feb 11 1 5 : 2 8 Template_Basic . pdf
−rw−rw−r −−. 1 j e a n r a j e a n r a
4739 Feb 11 1 5 : 3 1 Template_Basic . t e x
• chmod stands for change mode, and will allow you to change the permissions to files and
folders. This will allow you to make a file executable, write only, etc. For example, if I
want to make the file called script executable, I should just type:
[ j e a n r a @ b e l e t − i l i B a s i c s O f T e r m i n a l ] $ chmod +x S c r i p t
This command is quite rich, google it to get to know more about it.
• cp stands for copy. You can use it to copy files (or folders and all their content with
the option -r , that indicates recursibity). Syntax is: cp <source> <destination>. For
example, if I want to copy all the content of a USB stick on some place of a hard disk, I
should type:
J. Rabault
2
Linux Basics
cp −r / run / media / j e a n r a /CORSAIR/Group2 /∗ .
This will copy all the content of ’/run/media/jeanra/CORSAIR/Group2/’ , including
both files and folders, to ’.’ that represents the present working directory.
• mv stands for move. It works a lot like cp, but instead of copying, moves the file.
• rm stands for remove. Be carefull, this will remove the file without sending it to the Trash,
so there will be no way to undo this command. Again, it can be called with arguments
such as a file or folder path, or the recursion ’-r’ option.
• history will show you the history of the commands you used. Very convenient to do again
something complex you do not remember the command for. history is a command that
is convenient to pipe, i.e. it is convenient to use history output as the input to another
function, for example for filtering by keywords. Piping is done with the | character. You
can for example pipe history in the grep commands to look for commands that contain a
specific string:
[ j e a n r a @ b e l e t − i l i B a s i c s O f T e r m i n a l ] $ history
32 2015−10−24T20 : 5 3 : 2 7 l s
33 2015−10−24T20 : 5 3 : 3 6 o k u l a r Fig_MyScript
[ . . ] ( c o n t i n u e s for 1000 l i n e s )
[ j e a n r a @ b e l e t − i l i B a s i c s O f T e r m i n a l ] $ history | gr ep marduk
822 2016−01−25T10 : 5 5 : 3 9 cd /mn/marduk/ data /WOICE
898 2016−02−09T17 : 1 6 : 0 3 cd /mn/marduk/ data / j e a n r a /
945 2016−02−11T14 : 0 9 : 3 9 cd /mn/marduk/ data /MEK4600_2016/
971 2016−02−11T14 : 0 6 : 2 5 cd /mn/marduk/ data /
If you want to execute precisely one of the command shown by the history command,
you can do it using the number of the command, for example !971 to execute again cd
/mn/marduk/data/.
2 Launching Matlab
One way to open Matlab is to first open a terminal, move to the directory where you want to
work, and once there call Matlab:
[ j e a n r a @ b e l e t − i l i FormulaWaves ] $ matlab &
[ 1 ] 2517
This way, you will start Matlab directly in the right folder.
3 ssh
If you want, you can work on the computers of the laboratory (or any other UiO computer
running linux) remotely from home or from another department. For this, you need to remote
log in ssh. This is done by using the ssh command, together with your username and the name
of the computer you want to log on. Ssh will then ask you for your password. You should fill it
in, nothing will appear in the terminal but that is normal (this is for avoiding somebody looking
over your shoulder to see how many characters there are in your passworkd) For example,
J. Rabault
3
Linux Basics
if I am ’jeanra’ and want to log on the computer ’cleopatra’ from another computer of the
department I can type (followed by my password and then enter):
[ j e a n r a @ b e l e t − i l i B a s i c s O f T e r m i n a l ] $ s s h −X j e a n r a @ c l e o p a t r a
Last l o g i n : F r i Nov 20 1 6 : 0 5 : 0 0 2015
[ jeanra@cleopatra ~] $
Note that before I was working on belet-ili, and now I am working on cleopatra. If you
are outside of UiO, you should first connect to a computer that is accessible from outside the
network:
[ j e a n r a @ b e l e t − i l i B a s i c s O f T e r m i n a l ] $ s s h −X j e a n r a @ l o g i n . u i o . no
Velkommen t i l u l r i k . u i o . no !
[ jeanra@ulrik ~] $
And once logged on this computer, you should connect to the computer you want to work
on. For closing a ssh connection, just use the exit command:
[ j e a n r a @ u l r i k ~ ] $ exit
logout
Connection t o l o g i n . u i o . no c l o s e d .
[ jeanra@belet− i l i BasicsOfTerminal ] $
J. Rabault
4
Download