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 type | Basic description | Key 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 developer | Same as App dev from any other OS, but on Linux. | -Understanding Linux environment, Linux API , IO handling , Python & Shell, IO handling, C/C++ |
Kernel Programming | Dealing 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
- What is Linux?
- Linux distros, and the difference between them
- 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:
Command | Meaning | Example |
---|---|---|
cd | Change directory -this command allows you to go from one directory to another. | cd /home/exampleDir |
ls | List – this command list all the file & directory in the current directory. | ls /home/exampleDir |
pwd | Print 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:
Command | Meaning | Example |
---|---|---|
touch | create an empty file of any type | touch example.txt |
rm | remove a file of any type | rm example.txt |
rm -r | remove 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:
Command | Meaning | Example |
---|---|---|
cp | copy a file to a directory | cp example.txt /home/exampleDir |
mv | move a file to different directory, or rename a file | mv 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:
Command | Meanings | Examples |
---|---|---|
cat | cat displays the content of the file | cat example.txt output: Example contnet |
echo | echo pushes data, usually text, into a file | echo Example content >> example.txt |
vi | vi 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 |
nano | nano 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 file | nano 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:
Command | Meaning | Example |
---|---|---|
tar -cvf | create a tar archive | tar -cvf example.txt /home/eampleDir/ |
tar -xvf | decompress a tar archive | tar -xvf /home/exampleDir/example.tar |
tar -tvf | list the content of the archive | tar -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:
Command | Meaning | Example |
---|---|---|
zip | to compress a file into zip archive | zip example.txt |
unzip | tp decompress a zip archive | unzip example.zip |
There’s also some command that retrives information such as os version, network connection, etc.
Command | Meaning | Example |
---|---|---|
uname | retrieve information about the Linux distro system. | uname -a Output: |
hostname | retrieve your host name & ip adress | hostname |
ping | ping 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 branch | examples |
---|---|
Redhat | Redhat, CentOS, fedora |
Debian | Debian, Ubuntu |
and each have their own type of installing package.
Distros branch | Type of installing package |
---|---|
Redhat | rpm(redhat package manager) |
Debian | deb(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 |
---|---|
rwx | the 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
Meanings | Numerical value(Decimal) | read digit(binary) | write digit(binary) | execute digit(binary) |
---|---|---|---|---|
No permission | 0 | 0 | 0 | 0 |
Execute permissions | 1 | 0 | 0 | 1 |
Write permissions | 2 | 0 | 1 | 0 |
Write and Execute | 3 | 0 | 1 | 1 |
Read permission | 4 | 1 | 0 | 0 |
Read and exectue | 5 | 1 | 0 | 1 |
Read and write | 6 | 1 | 1 | 0 |
Read, write, exectue | 7 | 1 | 1 | 1 |
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.
- Linux introduction https://www.zhihu.com/question/397371213
- What is kernel programming https://www.quora.com/What-is-Kernel-programming-What-does-a-Kernel-programmer-actually-do#:~:text=Kernel%20programming%20is%20nothing%20but%20providing%20functionality%20in,kernel%20programmer%20would%20be%20doing%20the%20following%20things%3A
- What is Linux https://maker.pro/linux/tutorial/basic-linux-commands-for-beginners
- Basic vi command https://www.cs.colostate.edu/helpdocs/vi.html
- The Beginner’s Guide to Nano, the Linux Command-Line Text Editor https://www.howtogeek.com/howto/42980/the-beginners-guide-to-nano-the-linux-command-line-text-editor/
- 18 Tar Command Examples in Linux https://www.tecmint.com/18-tar-command-examples-in-linux/
- What is the difference between yum, apt-get, rpm, ./configure && make install? https://superuser.com/questions/125933/what-is-the-difference-between-yum-apt-get-rpm-configure-make-install
- yum和apt-get的区别 https://www.cnblogs.com/siyuli2019/p/11252419.html
- How to Use the chmod Command on Linux https://www.howtogeek.com/437958/how-to-use-the-chmod-command-on-linux/
- Linux chmod command https://www.computerhope.com/unix/uchmod.htm
- Linux基础入门 | 目录结构 https://mp.weixin.qq.com/s?__biz=MzU3NTgyODQ1Nw==&mid=2247485351&idx=1&sn=c1a56193a2fa9fa40eaace1c220d8279&source=41#wechat_redirect
- The Linux Directory Structure, Explained https://www.howtogeek.com/117435/htg-explains-the-linux-directory-structure-explained/