Linux learning

2020-07-05

This is the post where i’m going to summarize my entry level knowledge on Linux. I’m going to keep updating this post until i have a basic idea of Linux as a whole.

The basic syllabus

There is three main utilization of Linux/purpose for learning Linux:

Utilization typeBasic descriptionKey phrases/Stuff to learn
Operation and Maintenance, O&M.The craft of keeping servers running. This mostly deals with server maintaining, set-up, surveillance, etc.FTP,DNS,APACHE,IPTABLE,ORACLE,MYSQL, etc. Understanding most of the Linux commands. Shell & Python
Application developerSame as App dev from any other OS, but on Linux.-Understanding Linux environment, Linux API , IO handling , Python & Shell, IO handling, C/C++
Kernel ProgrammingDealing with the core of Linux as an OS.Get to know the relationship between hardware and software. , – Read manuals on computer chip sets.

Although it’s would be best to learn everything, I find the first option, O&M, more suited for my case(since I have rented servers). So this post will be focusing more on the server-side knowledge(I will try to learn the other option afterward).

Linux basics

  1. What is Linux?
  2. Linux distros, and the difference between them
  3. Most common Linux command

What is Linux:

Linux is a free and open souse Operating system created by Linux Torvalds. It is Unix based, and are used among most of the servers.

Linux distros:

Since Linux is open sourced, people is allowed to modify and produce their own version of Linux, thus born Linux distros. The most common Linux distros are:

  • Ubuntu Linux
  • Red Hat Enterprise Linux
  • Linux Mint
  • Debian
  • Fedora

Also Linux distros usually comes with a GUI, the majority of Linux user interaction is done by CLI(command line interface)

Linux basic commands:

The absence of GUI in most cases means that operating around Linux requires navigation through working directory, e.g. /home/usr/etc/etc. This means that the most used command are the follow:

CommandMeaningExample
cdChange directory -this command allows you to go from one directory to another.cd /home/exampleDir
lsList – this command list all the file & directory in the current directory.ls /home/exampleDir
pwdPrint working directory – this command print the path of your current directory, it let you know where you are.pwd Output: /home/exampleDir

After going through the directories, we can also manipulate the directories by these commands | Command | Meaning | Example | | ------- | ------------------------------------------------------------------- | ----------------- | | mkdir | Make directory – create a new directory under the current directory | mkdir /exampleDir | | rmdir | Remove directory – remove a directory under the current directory. | rmdir /exampleDir |

Files can be also manipulated in a similar way:

CommandMeaningExample
touchcreate an empty file of any typetouch example.txt
rmremove a file of any typerm example.txt
rm -rremove the directory, but not the files inside.rm -f /exampleDir

In GUI, a file movement is usually done by drag and drop. In Linux, file movement is done by:

CommandMeaningExample
cpcopy a file to a directorycp example.txt /home/exampleDir
mvmove a file to different directory, or rename a filemv example.txt /home/exampleDir mv example.txt example1.txt

There is also a search command:

locate

which act as the search tool for files. For example

locate example.txt
#output: /home/exampleDir/example.txt

Linux also has a build in Manual, which helped users if they forget the meaning of a certain command. To activate the the manual, use

man
#or
-help

Examples could be:

man cd
#or
cd -help

After creating a file/files, it could be examined and edited using these commands:

CommandMeaningsExamples
catcat displays the content of the filecat example.txt output: Example contnet
echoecho pushes data, usually text, into a fileecho Example content >> example.txt
vivi or visual editor is the default text editor for Unix based systems. When using, press i to edit, press esc to exit editing mode, type :wq or “:x” to write and quit, type :q to just quit, add ! if permission denied.vi example.txt
nanonano is a more complex text editor than vi. It is a “what you see is what you got” text editor with more functions such as inserting the content of another filenano example.txt nano /home/exampleDir /example.txt

There is also some system side command that is very useful in day to day usage.

For example

sudo

sudo stands for SuperUser Do. It is a command allowing a non-root user to have administrative privilege when giving out other commands. It is usually used at the very front:

sudo cd
sudo vi example.txt
sudo mkdir
#etc, etc

Managing disks is another important part of the Linux. The following two command gives you the information of disk space: | Command | Meaning | Example | | ------- | ------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------- | | df | df checks the disk space information in each mounted partition of the system. E.g. total disk space, used disk space, available disk space. | df, df -m show in megabytes | | du | du tells the disk usage of a particular file or directory | du /home/exampleDir du /home/exampleDir /example.txt |

There’s a whole other topic on disk mounting, which is something that i will touch on later on.

In terms of file compression, Linux uses the tar archive, which is represented with .tar. The command such as compress and decompress are as the following:

CommandMeaningExample
tar -cvfcreate a tar archivetar -cvf example.txt /home/eampleDir/
tar -xvfdecompress a tar archivetar -xvf /home/exampleDir/example.tar
tar -tvflist the content of the archivetar -tvf /home/exampleDir/example.tar

each letter in the “-cvf” in “tar -cvf” has it’s own meanings:

  • c is for create tar file
  • v is for verbosely show tar file progress
  • f is for file name

The old fashion “zip” file is also avalible in Linux, we can zip and unzip using the following command:

CommandMeaningExample
zipto compress a file into zip archivezip example.txt
unziptp decompress a zip archiveunzip example.zip

There’s also some command that retrives information such as os version, network connection, etc.

CommandMeaningExample
unameretrieve information about the Linux distro system.uname -a Output:
hostnameretrieve your host name & ip adresshostname
pingping check your connection with a certain website. It is also used to check the overall internet connection.ping example.com

Then, to install something, we use

apt-get

or

yum

The difference between these two is their type of installing package. Linux has two branch of distros

Distros branchexamples
RedhatRedhat, CentOS, fedora
DebianDebian, Ubuntu

and each have their own type of installing package.

Distros branchType of installing package
Redhatrpm(redhat package manager)
Debiandeb(dpkg)

yum and apt-get are the wrappers around these installing packages. They help manage all the installing package on a online repository.

So to use them, for example download the “sudo” package, we just neet to type:

apt-get install sudo

or

yum install sudo

depending on your version of Linux distro.

Finally, files in Linux have privilege/permission setting. A user with a root/sudo privilege will be able to change these permissions.

To understand these permission, we first need to go back to the ls command.

There is a variety to ls, which is

ls -l

it can display the information in a “long” format, which gives more information about a file. An example output would be:

-rwxrw-r-- 1 exampleUsr exampleUsr 780 Aug 20 11:11 example.txt
#or
drwxr-xr-x 2 exampleUsr exampleUsr 4096 Aug 21 08:03 exampleDir

The string of text in front of each line displays the the file type, the permission for file owner, the permission for users in the same group as the file owner and the permission for everyone else.

this shows that this is a file
rwxthe first segment is for file owner
rw-the second segment is for users in the same group
r–the third segment is for every else.

The first symbol represent the file type. The most common symbols are – and d, which is file and directory.

Apart from the first symbol, the following letters follows a pattern, each letter represent a permission status

  • r = read
  • w = write
  • x = execute
  • – (if not the first symbol/letter) = denied permission on whatever is suppose to be there

So, rwx means readable, writable, exexutable; rw- means only readable, writable, but not executable, and r– means only readable.

Now, to change the permission of these files, we use the command

chmod

This command can only be used with a root/sudo privilage, and the user must provide the “permission statement”, which includes the information of

  • who: who’s permission is changed
  • what: what changes in permission
  • which: what permission is going to change

This is represented with indicators after “chmod”, which is summarized in the table below | | | | | | | ----- | ----------------------- | ----------------------------------------- | ------------------------------------- | ------ | | who | u: “user”/ “file owner” | g: group, members in the same user group. | o: others | a: all | | what | – : remove permission | + : grants permission | = : set permission and remove others. | | | which | r: see above | w: see above | x: see above | |

This permission statement can also be represented using numerical and binary values. In that case

MeaningsNumerical value(Decimal)read digit(binary)write digit(binary)execute digit(binary)
No permission0000
Execute permissions1001
Write permissions2010
Write and Execute3011
Read permission4100
Read and exectue5101
Read and write6110
Read, write, exectue7111

so, to grant full permission of a file to everybody, we can either use

chmod a=rwx example.txt

or

chomd 777 example.txt

However, usually we just give the full permission to the file owner, and other people the read and execute permissions, so it’s like this:

chmod u=rwx,og=rx example.txt

or

chmod 755 example.txt

and finally, we add

-R

between chmod and the permission statement if we want tot change the permissions of the files in the sub directories.

References

This is all my reference is going to go. This page will move to the end after i finished this post.