Sie sind auf Seite 1von 3

MR308-Computational modeling of materials

Course TA: Rafia Ahmad and Avanish Mishra


Hands-on session 1
This hands-on will familiarize you with the linux environment. We shall not get into the details of linux, but you can
find some enlightening information online. Earlier versions of linux involved only the command line interface (CLI).
For some time now, graphical user interface (GUI) has been made available. However, linux, through CLI gives you
the freedom to perform file manipulations much faster than GUI. Hence, it is useful to learn a few commands. To
begin with open your Terminal where you will see a blinking cursor immediately after the $ sign. The default
directory that is launched in the terminal is the home (symbolized by (tilde) symbol) directory. This is the
place where all the action happens. You will need to type in the required command and then press the Enter key
for the execution of that command. Some of the commonly used commands are given below (while giving these
commands as input, do not include the < and > brackets):
ls
mkdir <folder-name>
ls <folder-name>
cd <folder-name>
cd ../
cd
rmdir <folder-name>
rm <file-name>
rm -rf <folder-name>
cp <file1> <file2>
cp -r <folder1> <folder2>
mv <file1>/<folder1> <file2>/<folder2>
pwd
Warning:

list the contents in the current directory


make directory <folder-name>
list the contents in the directory given by <folder-name>
change directory to <folder-name>
change to a previous directory
(The space between cd and ../ is important!!)
change directory to home (i.e. /)
remove empty directory <folder-name>
remove file <file-name>
remove recursively the contents of a f older <folder-name>
copy the contents of <file1> to <file2>
copy the contents recursively of <folder1> to <folder2>
move (rename) the contents of either <file1> or <folder1>
to <file2> or <folder2> and delete <file1> or <folder1>
gives the path of the present working directory

Use these commands with extreme caution!!

Tip: In many of these commands, the <folder-name> or <file> may be in some other directory. In such a
case, you will have to put the full path of that corresponding <folder-name> or <file>. You want to know the
real secret to this? You do not need to know the full path (Thats right!). If you know the starting letter of the
<folder-name> or <file>, just type that and press the Tab key. For example, if you want to check the contents
of the folder Aadipotter in the Desktop folder and you are at home (/), then just type:
ls Des(press the Tab key. The word Desktop gets completed appended with the / symbol)Aa(press the Tab key.
The word Aadipotter gets completed appended with the / symbol)
Disclaimer: Note that this table of commands is not exhaustive (What??). More commands will crop up during
this hands-on series (oh my God!!). But fret not! These commands will be explained on a need-to-know basis
(Phew!).

Quick exercise 1:
1. Suppose you just type ls in the home (/) directory, what do you see?
2. Type the command pwd. What do you see?
3. Now if you were to type ls Desktop/, what do you see?
4. Now go to the Desktop directory and create a folder of your name there.
5. If you were to type ls command, do you see the newly created folder?
6. Now rename your folder. Do you see the new name given to the folder?
7. Remove the empty folder that you just created. Do you now see your folder there?
8. Come back to the home directory and repeat questions 1-7.
We have still not used all the commands listed in the table. You now would want to create some file in a folder,
dont you? In order to create a file, just type the command vi <file-name> on the terminal and press the Enter
key. vi stands for view. This is the file editor in the terminal similar to that of Notepad in Windows. However,
that is where the similarity ends. Unlike in Notepad, you cannot move the cursor to a particular line.
There are 2 modes in vi: edit mode and read mode. When vi is launched, the read mode is the default mode.
Now, let us look at some common operations in vi.
Quitting
:q
:q!
:w
:w!
:wq
ZZ

<new-file>

quit as long as there are no changes


quit even if there are changes
write (i.e. save) the file but do not quit
write the changes to a new file <new-file> without changing the contents of the old one
write and quit the file
quit the file and save if any changes have been made

Navigation
:1
:x
G
xG
gg

go to the beginning of the file


go to line no. x (should be an integer). Eg. :20 goes to line 20
go to the end of the file (*capital G means shift + g)
Similar to :x
go to top of the file

All rights reserved to Aaditya Manjanath

Text manipulation
i/Insert key
Esc key
I
:r <file-name>
a
A
xyy
xY
xdd
xD
D
Xx
xp
xP
u
Ctrl-r

insert mode
go to read mode
insert text at the beginning of the line
read and insert the contents of file <file-name> after the line containing the cursor
append text after the cursor
append text at the end of the line
yank (copy) x (should be an integer) no. of lines. Eg: 5yy yanks 5 lines
Similar to xyy
delete x (should be an integer) no. of lines. Eg: 5dd deletes 5 lines
Similar to xdd
delete the characters under the cursor until the end of the line
remove X (X should be an integer) characters under the cursor.
Note that x here is not a number but X is.
paste x (should be an integer) times after the line containing the cursor.
Eg. 3p pastes 3 lines in the next line
paste x (should be an integer) times before the line containing the cursor.
Eg. 3P pastes 3 lines in the previous line
undo a previous change
redo a new change. You can achieve by pressing the Ctrl and r keys simultaneously

Disclaimer: This list is not exhaustive. More such vi tricks will be taught at a later time. This would be sufficient
for now.
Quick exercise 2:
1. Create a new folder as mentioned in question 4 in Quick exercise 1. Go to that folder and create a file with your
name. Type anything you want and save it. Do you see this file in the folder?
2. Now open this file and copy one line and paste it 3 times after the line containing the cursor.
3. Without exiting this file, bring it back to its original state.
4. Do the same as question 2, but paste before the line containing the cursor.
5. Do the same as question 3.
6. Without saving/exiting this file, save this to another file, say file1 (you can give any name).
7. Now open file1 and delete a line. Save and exit.
8. Open the previous file. Include the contents of file1 into this file.
9. Open a new file, say num-file, and make it a 10 10 matrix by keying in some numbers. You can type a row of
numbers and repeat them multiple times similar to questions 2 and 4, if you are lazy to type numbers. But ensure
that not all the rows are same.
10. In this file, go to a row (which is different from the previous rows) and change any element in that row.
11. Now, copy this line and put it at the end of the file (without using the mouse, of course!!).
12. Include the contents of file1 into this file. Delete any of the rows, and put them at the end of the file.
13. Without exiting this file, save it as another file, say file2
14. Exit num-file without saving the recent changes. Now, copy file2 into another file file3 (without using vi).
15. Delete file2. Now rename file3 to another file file4.
16. Come back to Desktop and make a copy of this folder.
17. Rename this folder and move to the home directory.
18. Go back to the home directory and delete this folder (all the effort only to delete a folder??).

Das könnte Ihnen auch gefallen