Linux commands

Linux commands 

First very IMPORTANT:

Ctrt+c –> is a stop command (this command you can
use every time you are not sure what you have done)



     ! do not use rm, stopsap, reboot, kill,
ifconfig, setpath,
if you do not know
exactly what you are doing.

First we need to have installed PUTTY and Pageant. To be able to access the system we need a private key and a public key. After our Private key is created we put it here:

Go to Pageant (Putty authentication agent).
Right click on it and choose Add Key.
Here you need to find your private key and enter the password. 
Next go again to Pageant (Putty authentication agent). Right click on it, choose Saved Sessions to choose your session (system).
Here our public key will be generate and will appear on the screen.
(the public key must be in the .ssh file). 
Very important command is “ pwd” that will display the working directory. In our case we are in root root. The “/” means the root, it is the first place where you will enter.

Another important command is “whoami” and will display the current user id and name.
Next command is “cd” that stands for change directory. So with this command we can display a directory. We will go to “/home” directory.
Here we can display what is in it, by typing “ls –altr” (very
important between ls and – is space). In our case it is appearing a long tree.
From here we will go in “training1”.
ls –altr  is a command that list  information about file. The next letters stands for: a-all, l-list, t-time, r-recursive).
go: “training1” we press “cd training1”. 
Also a very practical info is that you can use “tab” key
from keyboard to autocomplete the command that you want to write. So for
example if you write only “tr” for “training1” and press tab will appear the hole word. If
are more words that begins with “tr” will appear all and you can to choose.
Here we can put command ls –altr to display all that we have in it. 
Another command is “man” that means help manual. So for
example if you do not know exactly what is doing the command ls –altr you can
enter command man ls –altr and will appear info. If you want more info you can
press enter and will display a long help manual. You can do this for all commands.
To exit from here you press double points “:” and “q” in the green rectangle.

It is very important to know where you are, so every time you do not know exactly where you are, press pwd and will appear exactly the location. Next
we will make a directory (folder) with command ”mkdir”. To make a director put
command mkdir and the new name for the directory (the name can contain letters
and digits but you can not write with spaces.
If you want you can put sigh like point(.) or line (-). So like this:
Next we press again ls- altr
to see if we have created the folder.  

 To display our new folder we press command cd

So now we are in our new directory but we do not have anything in it but we will still press ls –altr to see. Will appear two directories . and .. .  One point stand for the current shell and two points stands for back shell. ( So one point (.) indicates the current director and two pints (..) indicates parent director).
To make more directories in one time you press command
mkdir  –p linux2 linux3 linux4 linux5
And now we press ll or ls –altr to see if we have done the directories. 
We can make also folders under each other (one in other) with command:
mkdir  –p
So here we have the structure. We press” ll” to se the structure.
 To rename a file, lets take “linuxcourse2” and change the
name in “summer”, we enter command “mv”.
mv linuxcourse2
If we put command “ll” we will see that the “linuxcourse2” changed in ‘summer”.

Next we will make a file here in our directory linux_tutorial. So for this we need the command “touch” and the new name of a file and press enter.

This file we can not open with “cd” command because it is
not a directory (folder). This file we can open with command “cat” that stands
for concatenate and display a content of a file. But we do not have anything in it.
So to put something in it we will enter command “vi”(stands for edit) and the name of our file : vi linux1 and press enter.
Will appear a window where we can enter information.
So first we press on “i” letter from keyboard, to can insert something here. Will appear on the down page this:

Now we can enter some words here.  
To save this info you must first press on “esc” key from keyboard and after that write :wq! (double points, w-save, q-exit, !-force).
To see if our work has been saved we press cat linux1. So our text is here.
In VI editor we can set the line to see how many they are.
So for this we press :set nu. Will appear all lines with a number in front. 
To search for a specific word or letter, we press “/ “ to search from where you are down and “\” to search from where you are up.  With ‘n” letter from the keyboard we go next.
In my example I have searched for “a” letter and with “n” I trough all “a” letters.
To change a word or a letter with something else we use
command :1,$s/c/k/g     (g-global)
So this means that all letters “c” we’ll be changed with “k” letter.
Next I will change word ”kommand” with “weekend”. :1,$s/kommand/weekend
If you want to go to a specific line, you press the number of the line and shift+g
I choose to go to the 10 line, so I press 10(you will not see writable anywhere but it will be there and than shift+g. You will see that was select line 10. Now if you want to delete line 10, press “dd”. Letter ”u” is for undo.
Bellow will appear some vi editor commands that you will need.
General Startup
use vi: vi filename
exit vi and save changes: ZZ   or  :wq
exit vi without saving changes: :q!
enter vi command mode: [esc]

A number preceding any vi command tells vi to repeat
command that many times.
Cursor Movement
               h       move left (backspace)
               j       move down
               k       move up
               l       move right (spacebar)
               [return]   move to the beginning of the next line
               $       last column on the current line
               0       move cursor to the first column on the current line
               ^       move cursor to first non-blank column on the current line
               w       move to the beginning of the next word or punctuation mark
               W       move past the next space
               b       move to the beginning of the previous word or punctuation mark
               B       move to the beginning of the previous word, ignores punctuation

e       end of next word or punctuation mark

E       end of next word, ignoring punctuation

H       move cursor to the top of the screen

M       move cursor to the middle of the screen

L       move cursor to the bottom of the screen
Screen Movement

G        move to the last line in the file

xG       move to line x

z+       move current line to top of screen

z        move current line to the middle of screen

z-       move current line to the bottom of screen

^F       move forward one screen

^B       move backward one line

^D       move forward one half screen

^U       move backward one half screen

^R       redraw screen
 ( does not work with VT100 type terminals )
       ^L redraw screen ( does not work with Televideo terminals )

r        replace character under cursor with next 
character typed

R        keep replacing character until [esc] is hit

i        insert before cursor

a        append after cursor

A        append at end of line

O        open line above cursor and enter append mode
               x       delete character under cursor
               dd      delete line under cursor

dw      delete word under cursor

db      delete word before cursor
Copying Code

yy      (yank)’copies’ line which may then be put by  t
he p(put) command. Precede with a count for  multiple lines.
Put Command brings back previous deletion or yank of lines, words, or characters

P       bring back before cursor

p       bring back after cursor
               ?       finds a word going backwards
               /       finds a word going forwards

f       finds a character on the line under the 
cursor going forward

F       finds a character on the line under the 
cursor going backwards

t       find a character on the current line going 
forward and stop one character before it
               T       find a character on the current line going backward and stop one character before it
               ;              repeat last f, F, t, T
Miscellaneous Commands
               .              repeat last command
               u             undoes last command issued
               U            undoes all commands on one line
               xp           deletes first character and inserts after second (swap)
               J              join current line with the next line
               ^G          display current line number
               %           if at one parenthesis, will jump to its mate
               mx          mark current line with character x
               ‘x            find line marked with character x
Marks are internal and not written to the file.
Line Editor Mode
               Any commands form the line editor ex can be issued upon entering line mode.
               To enter: type ‘:’
               To exit: press[return] or [esc]
ex Commands
               For a complete list consult the UNIX Programmer’s Manual
               copies (reads) filename after cursor in file currently  editing
               :w saves the current file without quitting
               :#           move to line #
               :$            move to last line of file
SHELL ESCAPE executes’cmd’ as a shell command.
Next we will remove our file linux1 with command rm linux1. So we can see that our file is no longer there. (But I will make it again)
Next we can see that the linux1 is no longer there.
We can create a symbolic link.
For this we need to enter command ln –s and the name for
our link. So we enter: ln –s. I made in past one for fructe1->fructe.
(location and name)
In front of a link will appear an “l”. You can now recognize which one is a link and which is a directory or a file.
To copy a director from another director to another director
you press command “cp –pr” and choose the all line in to the all line. So I
copied director “ab” from /home/training1/LuMiNiTa/ab and I put it in
Now a put “ll” to list my director to see if I copy it in my  directory.  So you can see that the directory “ab” is here too.
Next we will talk about Permissions.  So you see that every folder, file and link have does permissions.
Let’s take some examples:
Next we will change the permission for the first one. So
we will put to have 777 that means all permissions for user, group and other.

So we press command chmod 777 and the name for the folder.

Example: chmod 777 LUMI and enter.

To see if it was changed we press ll. So for the all permissions we have rwxrwxrwx.

Next we will change the ownership.

To change the ownership we press command chown and enter the names for owner.

For example we will change the owner oracle: oinstall with root:root.
We press ll or ls –altr to see if it changed it. So, yes for our LUMI director was changed.
If you want to change for all folders that are in director LuMiNiTa, we put command chown  -R root:root LuMiNiTa. This –R will put for all files owner root:root.(-R the same for chmod).
Next we press ll or ls –altr to see if it has changed it. So we have now for all owners root:root.
Another interesting command is “clear”. This command helps you to clean the desktop. So if you press command clear it will clean your screen. But if you go with scroll up you will see all commands that you put it. 
Important is to know that with command “cat” you can
display a file but if it is to long will take time and it will not appear all
on the screen. Command “cat” is good for small files and for big files we use
command “less”and enter the file name . Enter.

My file is a short one but I made this command to see exactly. 
To exit I hope that you remember from the previous steps.(:q)

Next we will search for a word. So we will use  grep –i (key sensitive) and the name of the
file and *.
So example ls –altr(to list for as)  |(pipe) grep –i fructe*.( point is to
search here, where we are, in this location). 
Will appear all files that have *fructe* in it.

 To see all users we put command cat /etc/passwd 

To see the groups we put command cat /etc/group
To see available space we put command df –h 
Command free it shows you how much memory it is on it.

 Command “crontab” schedule a command to run at a later time.

It can be used with –l to list, eith –e to edit. I will put command crontab –l, just to list for me. 
Here we can see how they are programmed. So, if we have in front of it # that means
it is commented (stopped).

If I put with crontab –e, I will be able to edit it. So if I press “i” I will can edit this file. 
So for the first line 30 stands for minute, 1 for hour, *
for day of month, * month, 1-5 day of week.

To substitute user we use command “su”, that makes
possible to change a login session’s owner without the owner having to first
log out of that session.
So I will switch from root to sidadm. Use su – sidadm
(very important space between su and – and between – and sidadm).
To see if we have changed the owner we press command “id”.
Next you can see the shell by pressing command env | grep –I shell:
To see the path also here you can press command env | grep –I path:
To go out from sidadm user, press command “exit” and it will display this:
To find the shell, we press command echo$SHELL. And here we will see the shell.
To compress a file: gzip-gunzip, zip-unzip. I will
compress a file with zip. So I put command zip, after the new name for the zip
file and second the name of the file that I want to zip. (zip cities)
Press”ll” to see if the changes are made.
To archive a file you press command tar. So I will make a archive for cities file. (tar –cjvf orase.tbz cities)

Press”ll” to see if the changes are made.


Leave a comment

2 thoughts on “Linux commands”