Things to know in Linux to handle development and servers.

Things to know in Linux to handle development and servers.
4.67 (93.33%) 3 votes

  6 minutes

Linux is always tough for newbies but trust me if you treat linux more than OS at the initial stages, you will be so intimated by its power that you may not get use to it easily. So my suggestion linux is just an operating System.

Linux is one of the must to know things in computer science as most of the servers are linux based and one or the other day you have to interact with it. SO lets start with things that you should know to be able to handle servers easily.

 

Make directory, change directory , copy, move and remove commands.

Yes this are the basic commands are same as they are in windows command prompt.

For creating a directory use

mkdir directory_name

for changing the directory use

cd path_to_directory

Read more about cd options here .

for copying from one location to another

cp [options] source dest

Read more about cp Options here .

for moving from one location to another

mv [options] source dest

Read more about mv options here .

for removing a file or directory

rm filename
rm -R directory_name

Read more about rm here.

How to install packages in Linux.

You can install the packages in linux using commands with respective modification of OS. like for Ubuntu you use

apt-get install package-name

Similarly for other the commands are there just use the commands you can easily find on internet.

 

Permissions in linux

Here comes the tough part, Permissions, Lets talk about it and make it simple to understand.

Linux permissions are managed by Permissions Groups and Permission Types.

 

There are three Permission Groups.

Owner – The Owner permissions apply only the owner of the file or directory, they will not impact the actions of other users

Group – The Group permissions apply only to the group that has been assigned to the file or directory, they will not effect the actions of other users.

All users – The All Users permissions apply to all other users on the system, this is the permission group that you want to watch the most.

 

And the permission types are

Read – The Read permission refers to a user’s capability to read the contents of the file.

Write – This permission allows User to write to the file or not.

Execute – This allows the user to execute the file.

To see the permission go to directory and type

ls -l -a

ls will list files -l will list permissions and -a will list hidden files also

When you see a permission of any file it will be something like this

rw_rw_rwx

Here the first three characters are for owner, next three for group and last three for all users. r is for read, w for write and x for execute.

So for above case.

Owner as permission to read and write, group has permission to read and write, but all users have permission to read, write and execute.

 

Now how to set permissions, It is done using chmod command like

chmod 640 file_name

Wait wait now you must be thinking what is 640 here. 640 is the representation of permissions in numbers.

It is calculated like below.

r - 4

w - 2

x - 1

Now why 4 2 and 1 why not anything else its because of binary representation see here, when we write the permissions for group or owner or all users it was like rwx or rw_ or something similar.

Here there are three positions first for r second for w and  third for x. Now if we see the places in binary and put 1 in these positions it will be like 111 for rwx 110 for rw_. Now if we convert the binary to number 100 is for read this 4 is for read 010 is for write thus 2 is for write and 001 is for execute thus 1 is for execute.

From above 640 means 6 for owner, 6 = 110 thus read and write permission for owner. 4 is for group thus 4 = 100 thus only read for group and 0 thus no permission for all users.

Now you understand the permission for linux and how to change them using chmod.

If you wanna dig deeper into permission try reading this article on linux permissions.

 

Command to start stop and restart various server.

There is nothing to tell about this. Generally in linux server are added as a service so say you want to start an nginx server you just have to type

sudo service nginx start/restart/stop
sudo service mysql start/restart/stop for mysql.

All the commands are like this only and if there is any diversion you can easily get the commands from their documentation.

 

Now that you learned basics, permissions and few more commands lets get into GREP.

grep Command

When you are working with servers you have to keep a close watch on logs, search them and analyze them. Now comes the grep which make it very easy to search in directory of file.

grep [options] pattern [files]

Simplest example is lets say we have to find word hello in file test.html

then command will be like

grep hello test.html

Now you want it to be highlighted use

grep --color hello test.html

Say you want to see line number also then type

grep -n --color hello test.html

Grep search is case sensitive, to perform case insensitive search use -i flag

grep -n --color -i hello test.html

Searching in more than one file with extension .html

grep -n --color -i hello *.html

It will search in all the files with extension .html

Now searching in subdirectories, use the -r flag.

grep -n --color -i -r hello *.html

These are few of the basic examples you can read about more here.

 

Getting Process Id and killing it.

This is important in handling servers as sometimes it may happen you run a script and it started consuming all your resources in that case you have to kill that process.

For getting the process id for firefox

ps ax | grep firefox

This will give process id for all process of firefox.

Now kill the process

kill -9 pid or kill -KILL pid

here pid is Process ID

 

VIM text editor.

Why Vim is important is that generally on servers you don’t have GUI thus if you need to edit any file you will come across one such CLI editors. VIM is one of those. Here Ill tell some basic things in Vim

For opening a file in VIM

vim path_to_file

For starting editing in file

press i and start changing.

for saving the file

press ESC -> : -> w

it will write changes to the file.

for closing the file

press ESC -> : -> q

Deleting a line

press d

Undo changes

press u

Redo Changes

CTRL + u

For searching

press ? then pattern

These are the things that you must know to handle the servers easily in linux.

Liked the post, Subscribe for more

 


Gaurav Yadav

Gaurav is a Full Stack Web Developer and Blogger. Sportsperson by heart and loves football. He has experience with various frameworks in php, python and javascript. Loves to explore new frameworks and evolve with the trending technology.

Leave a Reply

Your email address will not be published. Required fields are marked *