Linux knowledge 2

Time:2021-3-24

Open and switch the root user

After the default installation, you don’t know the password of the root user, so how to apply the root permission?

(1) Sudo command

[email protected]:~$  sudo

In this way, you can enter the password of the current administrator to get the permission of the super user. But by default, the root permission is invalid in five minutes.

(2)sudo -i

[email protected]:~$  sudo -i

In this way, you can enter the root user by entering the password of the current administrator user.

(3) If you want to use the root permission all the time, you should switch to the root user through su.
First, we need to set the password of the root user

[email protected]:~$  sudo passwd root

In this way, you can set the password of the root user.

(4) After that, you can switch to the root user freely

[email protected]:~$  su

Enter the password of the root user.

su "due"perhapsexitBack to user rights

Switching between X window and text mode

By default, Linux will provide six terminals for users to log in, and the switching mode is: [Ctrl] + [ALT] + [F1] ~ [F6]
Combination button. The default is to start the graphical interface, so the X window will appear in the tty1 interface. If your Linux uses pure command line by default, then tty1 ~ tty6 will be occupied by the text interface.

  • [Ctrl] + [Alt] + [F2] ~ [F6]: command line login tty2 ~ tty6 terminals;
  • [Ctrl] + [Alt] + [F1]: graphical interface desktop.

Tty2 ~ tty6 didn’t exist at first! But when you want to switch (press [Ctrl] + [ALT] + [F2]), the system will generate additional tty2, tty3

If you start the X window in a plain text environment, the graphical interface will appear on the TTY at that time

#The method of starting window interface under pure command line
[[email protected]~]$ startx

However, startx is not a panacea. To make startx work, you need at least the following things:

  • No other X window is enabled;
  • You must have installed X window system and X server can start smoothly;
  • You’d better have a window administrator, such as Gnome / KDE or TWM of Yangchun;

As for the prompt character, in Linux, the default prompt character of root is#And the prompt character of general identity users
by$

Operation of basic instruction

\enter \spaceuse\Escape special key

  • Command to display date and time:date
[email protected]:~$ date +%Y/%m/%d\ %H:%M:%S\ %s
2018/06/05 14:10:11 1528179011
  • Display calendar command: cal
[email protected]:~$ cal 10 2018
      October 2018
One two three four five six
    1  2  3  4  5  6
 7  8  9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31
  • Simple and easy to use computer: BC
  • Changing language coding
[[email protected] ~]$ LANG="en_US.utf8"
  • Man instruction
Code Representative content
1 Instructions or executable files that users can operate in shell environment
2 The core of the system can call functions and tools
3 Some commonly used functions and libraries, most of which are C’s (libc)
4 The description of the device file, usually in the file under / dev
5 Configuration file or the format of some files
6 Games
7 Conventions and protocols, such as Linux file system, network protocol, ASCII code, etc
8 Management instructions available to system administrators
9 Kernel related files

In man page, you can sort out the commonly used buttons for him

Key Work
Blank key Turn the page down
[PageDown] Turn the page down
[PageUp] Turn one page up
[Home] Go to the first page
[End] Go to the last page
/string Search “down” for string. If you want to search for vbird, enter / vbird
?string Search “up” for string
n, N When using / or? To search for a string, n can be used to continue the next search (whether it is / or?), and N can be used to “reverse” search. For example, if I use / vbird to search for vbird strings, I can continue to query N and use n to query up. If you use? Vbird to query vbird string up, I can use n to continue “up” query and use n to reverse query.
q End this man page

Since there is a man page, it is only because there are some file data that it can be read out as a man page! So where is the man page data? Different distributions may have some differences, but they are usually placed in/usr/share/manIn this directory, however, we can improve the problem of this directory by modifying its man page search path! modify/etc/man_db.conf(some versions are man.conf or manpath.conf or man.config And so on! For more information about man, you can use“man man”Come to inquire!

  • info page
Key Work
Blank key Turn the page down
[Page Down] Turn the page down
[Page Up] Turn one page up
[tab] Move between nodes. Where there are nodes, they are usually displayed as *.
[Enter] When the cursor is above the node, press enter to enter the node.
b Move the cursor to the first node in the info screen
e Move the cursor to the last node in the info screen
n Go to the next node
p Go to the previous node
u Move up one level
s(/) Search in info page
h, ? Show help menu
q End this info page
  • /usr/share/doc

Shutdown command

  • Instructions to write data to the hard disk synchronously:sync
  • Usual shutdown command:shutdown
[ [email protected] ~]#/ SBIN / shutdown [- krhc] [time] [warning message]
Options and parameters:
-k: Don't really shut down, just send a warning message out!
-r: Restart the system after the system service is stopped
-h: Shut down the system immediately after the system service is stopped. (commonly used)
-c: Cancel the contents of the shutdown instruction that is already in progress.
Time: specify the time of system shutdown! An example of time is shown below. If there is no such item, it will be automatically performed in 1 minute by default.
example:
[[email protected]~]# /sbin/shutdown -h 10 'I will shutdown after 10 mins'
Broadcast message from [email protected] (Tue 2015-06-02 10:51:34 CST):
I will shutdown after 10 mins
The system is going down for power-off at Tue 2015-06-02 11:01:34 CST!
  • Power on, power off:reboot, halt, poweroff

Catalog file

Linux knowledge 2

  • chgrp: change the group to which the file belongs:chgrp users initial-setup-ks.cfg
  • chown: change file owner
[[email protected]~]$ chown bin initial-setup-ks.cfg
[[email protected]~]$ chown root:root initial-setup-ks.cfg
[[email protected]~]$ chown user.group file
#Chown can also simply modify its group
[[email protected]~]$ chown .sshd initial-setup-ks.cfg
  • chmod: change file permissions, suid, sgid, sbit, etc
[[email protected]~]$ chmod 755 .bashrc
[[email protected]~]$ chmod u=rwx,go=rx .bashrc
[[email protected]~]$ chmod g+r-w,o-r .bashrc

The importance of permissions to files

  • r(read): it can read the actual content of the file, such as the text content of the text file;
  • w(write): you can edit, add or modify the contents of the file (excluding deleting the file);
  • x(execute): this file has permission to be executed by the system.

The importance of permissions to directories

  • r(read contents in directory): it means that you have the permission to read the directory structure list, so when you have the permission to read (R) a directory, it means that you can query the file name data in the directory. So you can use itlsThis command will display the content list of the directory!
  • w(modify contents of directory): This writable permission is great for the directory! Because it means that you have the permission to change the directory structure list, that is, the following permissions(No,xThe permission still cannot be executed):

    -Create new files and directories;
      -Delete the existing files and directories (regardless of the permissions of the file!)
      -Rename the existing file or directory;
      -Move the file and directory location in the directory.

In a word, the w permission of the directory is related to the change of the file name under the directory! Of subdirectoriesmkdirrmdirmvAnd sub filesmvrmvinanoetc.

  • x(access directory): eh! What’s the use of directory execution permission? It’s just the total directory name, right? you ‘re right! The directory cannot be executed. The X of the directory represents whether the user can enter the directory and become a working directory!

File type extension

  • Document type

We just mentioned using “LS – L” to observe that the first character in the first column is the type of file. In addition to the common general file (-) and directory file (d), what kinds of file types are there?

  • Regular file: is the type of file we are accessing. In terms of the attributes displayed by LS – Al, the first character is [-], for example [- rwxrwxrwx]. In addition, according to the content of the document, it can be roughly divided into:

    • Plain text file (ASCII): This is the most common file type in Linux system. It’s called plain text file because the content is data that we can read directly, such as numbers, letters and so on. Almost all the files we can use as settings belong to this file type. For example, you can issue “cat ~ /. Bashrc” to see the contents of the file. (cat is an instruction to read out the contents of a file)
    • Binary fileRemember that we mentioned in the operation of software program in Chapter 0, introduction to computer that our system only knows and can execute binary file? That’s right. The script file in your Linux is in this format. For example, cat is a binary file.
    • Data format file (data): some programs will read some specific format files in the process of running, and those specific format files can be called data files. For example, when our Linux users log in, they will record the login data in the file var / log / wtmp, which is a data file and can be read by the last command! But when using cat, it will read out the garbled code, because it belongs to a special format file. Is it too late?
  • Directory: is the directory. The first attribute is [D], such as [drwxrwxrwx].
  • Link file: it’s a shortcut similar to Windows system! The first attribute is [l] (lowercase of English l), such as [lrwxrwxrwx];
  • Device and device file: some files related to system peripheral and storage are usually concentrated in the directory / dev! It is usually divided into two types:

    • Block device file: is some storage data, to provide system random access peripheral equipment, for example, hard disk and floppy disk is it! You can read and write randomly in different blocks of the hard disk. This kind of device is a block device! You can check / dev / SDA and find that the first attribute is [b]!
    • Character device file: peripheral devices of serial port, such as keyboard, mouse, etc! The characteristic of these devices is “one-time read”, which can not truncate the output. For example, you can’t make the mouse “jump” to another picture, but “continuously slide” to another place! The first attribute is [C].
  • Data interface files (sockets)Since it is called data interface file, of course, this type of file is usually used for data on the network. We can start a program to listen to the requirements of the client, and the client can communicate data through this socket. The first attribute is [S]. This file type is most often seen in / run / tmp.
  • Data transfer file (FIFO, pipe)FIFO is also a special file type. Its main purpose is to solve the error problem caused by multiple programs accessing a file at the same time. FIFO is the abbreviation of first in first out. The first attribute is [P].

The maximum allowable file name of a single file or directory is 255bytes, which takes one byte for one ASCII English
The length is about 255 characters. If each Chinese character occupies 2 bytes, the maximum file name will be 0
It’s about 128 Chinese characters!

Recommended Today

Swift advanced (XV) extension

The extension in swift is somewhat similar to the category in OC Extension can beenumeration、structural morphology、class、agreementAdd new features□ you can add methods, calculation attributes, subscripts, (convenient) initializers, nested types, protocols, etc What extensions can’t do:□ original functions cannot be overwritten□ you cannot add storage attributes or add attribute observers to existing attributes□ cannot add parent […]