This is the 11th day of my participation in the August More Text Challenge
Here are my study notes for learning Linux from the ground up, which will be updated later.
Record their own technology growth, also hope to share with you, welcome to follow ~
This is a study note for Linux for Developers on Coursera
Difference between Ubuntu and CentOS
-
CentOS
CentOS is a community version of RedHat. It is compatible with the RedHat RPM installation package. CentOS is generally used as a server and preinstalled on the server. Aside from the fact that it doesn’t come with RedHat service (which I wouldn’t buy if I wanted to), it works like RedHat. Package management is usually managed by RPM or YUM.
-
Ubuntu
Ubuntu is based on the Debian distribution and the GNOME desktop environment. There is also a KDE version, which is one of the more popular distributions. It has enhanced graphical features and is available in desktop and server versions for the general user. It is popular because the desktop version is pretty, has more multimedia software and ubuntu software Center support, and is reasonably easy to use for the average user. There’s not much to say about the server version, either. Package management is usually apt-get.
-
Usage Scenario Selection
If you want to make a Server, of course choose CentOS, or Ubuntu Server edition. If it’s a desktop system, use Ubuntu Desktop.
Learning goals
- List the major text editors available on almost all Linux-based systems, with emphasis on VI, EMcas, Nano, and Gedit
- Know how to use vi and emacs editors and how to create files using only Cat and Echo without the editor
- Discusses how the operating system uses the command shell program, the options available, and how to initialize bash
- Explains the use of aliases, manipulation and use of environment variables, and custom command line prompts
- Discuss special characters, how to use them and override their special meanings
- Redirection is used for input, output, and error messages, and command substitution is used to provide the output of one program to another
- Use pipes to enable connected programs to run efficiently in parallel to better utilize system resources
- Discusses the main directory structures used in Linux and their purpose
- Describes how to use partitions and how to structure, format, and manipulate them, and how to set up a good partitioning scheme
A text editor
The two most commonly used in Linux and Linux are VI and Emacs. But some alternatives are so easy to use that you can get started right away, like nano and Gedit. We’ll mention them briefly, but they’re very easy to learn.
Whether you are a system administrator or a developer, you will have to edit text files as well as create them. Whether you are a system administrator or a developer, you will have to edit text files as well as create them. One editor you can use from the command line is Nano. It’s very simple to use, it has almost no learning curve, and it’s much easier to get started if you haven’t used VI or Emacs before.
1.echo and cat
If you just want to create a file and don’t even need an editor, there are two standard ways to create a file from the command line and populate it with content.
The first is to just use echo repeatedly:
$ echo line one > myfile
$ echo line two >> myfile
$ echo line three >> myfile
Copy the code
A second way is to use cat combined with redirection:
$ cat << EOF > myfile
> line one
> line two
> line three
> EOF $
Copy the code
either of which produces a file which has in it:
line one
line two
line three
Copy the code
2. The vi editor
The actual name of the program might be vim, with vi as an alias for its alternate name. Everything you do with VI, you can do from the keyboard. One of the confusing parts about VI is that there are two basic modes, command mode and insert mode, and then you can use the exit key to switch between each button. The same letters typed in either mode have very different functions, so learning them can be confusing at first.
3. The vi command
Start, exit, read, and write files in VI
Change the location in VI
Search for text in VI
Change, add, and remove text in VI
3. The emacs editor
Emacs is the other major choice for text editors. Emacs is available on all Linux systems, and sometimes it is not installed by default. In addition to text editing, Emacs has almost a variety of functions, such as E-mail, debugging, constituting a complete integrated development environment, and so on. There is only one mode in Emacs, unlike the two modes in VI. To perform special Control functions and issue editor-specific commands, you use the Control (Ctrl) key or the META key, for which you can easily use ALT or Escape in combination with other keys. Most experienced Emacs users will probably remap the controls to where the useless Caps Lock key is. Therefore, this is only relevant to Emacs.
Shell, Bash, and command line
1.shell
The shell is an interface between you (the user) and Linux (or, more accurately, you and the Linux kernel). Every command you type at the prompt is interpreted by the shell and then passed to the Linux kernel. The shell is a command-language interpreter. ** has its own built-in set of shell commands. ** In addition, the shell can also be called by other effective Linux utilities and application programs on the system. ** Whenever you type a command, it is interpreted by the Linux shell. ** Some commands, such as the print current working directory command (PWD), are included within Linux bash (just like DOS internal commands). Other commands, such as the copy command (cp) and move command (rm), are separate programs that exist in a directory on the file system. For the user, you don’t know (or maybe don’t care) whether a command is built inside the shell or a separate program.
2.bash
Bash, a type of shell. Bash is a command processor that typically runs in a text window and can execute commands typed directly by the user. Bash can also read commands from files, called scripts.
Any command shell can only be invoked by entering a name on the command line. You can change the user’s default Shell using the CHSH utility.
3.Interactive shells
Login shells:
- if /etc/profile exists, source it
- if ~/.bash_profile exists, source it
- else if ~/.bash_login exists, source it
- else if ~/.profile exists, source it
- on exit, if ~/.bash_logout exists, source it
Non-login shells:
- if ~/.bashrc exists, source it
2. Create a new account in root
4. Environment variables
There is no limit to the length or number of environment variables. For example, many applications use them to set default values for configuration options. Examples include HOME, HOST, and PATH, and can be set to PATH: For example, PATH = HOME/bin: HOME/bin: HOME/bin: PATH.
Exercise: Add environment variables. Append path to a directory and set the value for the environment variable
5. Customize the command line prompt
The default command line prompt is **$(for regular users) and # (** for root or superuser).
Here is a table with some of the possible special characters that can be embedded in the PS1 string:
6. Echo command in Shell command
The echo command displays text.
1. Text output: The echo command is followed by the output text
2. Echo wrap; Echo -n indicates that the output is not newline
3. Echo -e indicates that the escaped character ①\b is escaped, which is equivalent to pressing the Backspace key, provided that there are characters after \b. For details, see the following example. (2) the output of \c is not newline. If there is no character after “\c”, the function is equivalent to echo -n. See the following example for details. ③\n Newline, see the example below for specific effect. ④\f line breaks, but the beginning of the new line is connected to the end of the previous line, as shown in the example below. ⑤\v is the same as \f. ⑥\t after the rotation means insert TAB, namely TAB character. ⑦ the cursor of \r moves to the beginning of the line, but does not wrap the line. It is equivalent to using the character after “\r” to cover the character of the same length before “\r”. ⑧\ means to insert “\” itself.
[administrator@localhost ~]$ echo -e "123\b"
123
[administrator@localhost ~]$ echo -e "123\b4567"
124567
[administrator@localhost ~]$ echo -e "123\b\b4567"
14567
[administrator@localhost ~]$ echo -e "123\b\b\b4567"
4567
[administrator@localhst ~]$ echo -e "123\c"
123[administrator@localhost ~]$
[administrator@localhost ~]$ echo -n "123"
123[administrator@localhost ~]$
[administrator@localhost ~]$ echo -e "123\c456"
123[administrator@localhost ~]$
[administrator@localhost ~]$ echo -e "abcefg\n1234"
abcefg
1234
[administrator@localhost ~]$ echo -e "123\f456"
123
456
[administrator@localhost ~]$ echo -e "abcdefg\f1234"
abcdefg
1234
[administrator@localhost ~]$ echo -e "abcdefg\f1234\f@@@@@@@@"
abcdefg
1234
@@@@@@@@
[administrator@localhost ~]$ echo -e "abcdefg\r123"
123defg
[administrator@localhost ~]$ echo -e "abc\r123"
123
[administrator@localhost ~]$ echo -e "a\r123"
123
[administrator@localhost ~]$ echo -e "a\r"
a
[administrator@localhost ~]$ echo -e "abc\\def"
abc\def
Copy the code
File system layout, partitions, paths, and links
1.Linux file management
Linux file Management introduces the way of Linux file management from the user level. Linux has a tree structure to organize files. The top of the tree is the root directory (/), the nodes are directories, and the leaves at the end are files containing data. When given the full path to a file, ** we start from the root directory and travel through various directories along the way to the file. ** We can perform many operations on files, such as opening and reading and writing. In Linux file management related commands, we see many commands that operate on files. They are mostly based on opening and reading files.
There are few differences between Linux distributions, mainly in the system management features and the way packages are managed. The directory structure is basically the same. Windows file structure is a number of parallel tree structure, the top of the different disk (partition), such as: C, D, E, F, etc.
The file structure of Linux is a single tree structure. You can display this using the tree command (it is not installed by default). Partition is used every time you install the system. Under Linux, the relationship between disk partition and directory is as follows:
① Each partition must be mounted to a certain directory.
② Directories are logical distinctions. A partition is a physical partition.
③ Linux partitions on disks can be read and written only after being mounted to a specific directory in the directory tree.
4. The root directory is where all Linux files and directories are stored. You need to mount a disk partition to the root directory.
2.Linux directory structure
Linux does not enforce file extensions, or even have such a concept. However, when creating or saving files, it is usually best to give a file extension, which is very helpful to understand the content of the file and easy to manage
Here is a brief explanation of each directory in the root directory:
Usage suggestions:
-
Users should store files in their home directory and subdirectories
-
Most of the system Settings are in the /etc directory
-
Don’t change anything in/or /usr unless you really know what you’re doing
-
Most tools and application programs are installed in /bin, /sbin, /usr/bin, /usr/sbin, /usr/local/bin
-
A file or directory has a unique absolute path.
One question:
No other file directory can be seen after ls command
Job: Mount the Windows/Linux directory to Linux
Query /proc to obtain the user time, system time, and idle time of the system
3. The partition
Under Linux, ** disks are divided into multiple partitions. Up to four primary partitions can be created, and ** information about them is stored in the MBR (Master boot Record). ** You gain more flexibility by creating up to three primary partitions and one extended partition, which can contain as many logical partitions as you can hold, ** depending on the type of disk involved. For example, SCSI disks can have a maximum of 16 partitions.
The command-line utility for creating and checking disk partitions is fdisk. The FDISK utility can be used to create and delete partitions and change their type. FDISK does not allow you to move or resize partitions.
You can use the MKFS command to format partitions for various file systems or, more commonly, to format partitions with specific commands for each type of file system.
Using the GParted utility (and certain equivalents), you can perform all of these operations in a graphical and user-friendly manner.
In Linux, every hardware device maps to a system’s files, including IDE or SCSI devices such as hard disks and drives. Linux assigns various IDE devices a file with an HD prefix; For various SCSI devices, a file consisting of an SD prefix is assigned.
4. The path
Paths are an important aspect of the environment and are encapsulated in the PATH environment variable.
Adding a directory to a path is easy, as follows:
$ MY_BIN_DIR=$HOME/my_bin_dir
$ export PATH=$MY_BIN_DIR:$PATH
$ export PATH=$PATH:$MY_BIN_DIR
Copy the code
5. Hard connection and soft connection
Our Linux directory uses the ext4 file system.
Ext4 file systems divide partitions into two main parts (not to mention super blocks for now) : a small part that holds inodes (I nodes) of files; Most of the rest is used to store block information.
In Linux, the ** kernel assigns an Inode(index node) to each newly created file, and ** each file has a unique Inode number. File attributes are stored in index nodes, which are copied to memory when accessing files, thus achieving fast access to files. There are two types of Linux links, one called Hard Link and the other called Symbolic Link. By default, the ln command generates a hard link.
A hard link is essentially a pointer to a file index node for which the inode is not reassigned.
Soft links overcome the disadvantages of hard links, there is no limitation of any file system, any user can create symbolic links pointing to directories. It is now more widely used and has greater flexibility, even linking files across different machines and networks.
Summary: Soft links are shortcuts, and hard links are Pointers to file index nodes. Based on the various advantages of soft links, more inclined to use soft links.
Now that you’ve seen this, why not give it a thumbs up