Basics of Linux Operations

Source: Internet
Author: User
Tags aliases clear screen create directory parent directory readable file permissions

Basic principles of Linux

1, composed of small programs with a single purpose, the combination of small procedures to complete complex tasks;
2, everything is a document;
3, try to avoid capturing the user interface;
4. Save the configuration file in plain text format

Linux system composition

Computer hardware : CPU, hard disk and so on.

kernel: So that the system can run approximately several programs at the same time, is just a platform, the computing power of the hardware is abstracted out in the system call the way of the other upper software;
Window DLL (dynamic link library, DLL)
On Linux Yes .so (Shared object)

Library_api: Because the system call is too low level, the function of the library is to encapsulate one or more system calls into a more advanced interface, unable to execute independently, only execute when called (Shared library).

Development Environment : A unique user interface,
Graphical interface GUI, such as Gnome_c, ked_c++, XFace;
CLI Interface (command line): Commond lines Interface, category with Shell, Bash, csh, zsh, Ksh, tcsh

Bashell

Apps like Bash are usually opened after the user logs in.
process : In each process it appears that only the kernel and the current process exist on the current host, which is actually the concept of partitioning. A process is a copy of a program, an instance of a program execution, which is different for the user's working environment.
Shell can also open shell, multi-layer, multiple start shell command, with exit one by one to exit the current shell, pstree you can view the hierarchy.

Command history
history: View command history;
Empty command history:-c
-d n offset: Offset to delete the history list from the specified location.
ls -aThe hidden file is displayed first, and the command history is saved in the file .bash_history .
-w: Saves the command history to the history file. You can set the size. The environment variable HISTZISE , which is 1000 by default, echo $HISTSIZE can be viewed.
Tips for use :
!n: Displays and executes the nth command;
!-n: Displays and executes the reciprocal nth command;
!!: Displays the previous command, ESC plus . ;
!s: Displays and executes the most recent command starting with S;

Command Aliases :
alias cls=clear: Modify the clear command as CLS;
Aliases defined in the shell are valid only in the current Shell life cycle (process);
alias: Displays all aliases for the current system;
Revoke the specified alias:unalias cls
\原命令: Use the original

command Substitution :
"": Weak application, can realize variable substitution;
‘‘: Strong reference, do not complete variable substitution;
`:命令替换;$ (COMMAND) ,也可以使用反引号``COMMAND``:把命令中某个子命令替换成其执行结果的过程。 echo "Asdsad is $ (pwd)" :将pwd的执行结果显示在字符串中,注意字符串内容必须是双引号; 例如新建以当前时间命名的文件: Touch file-$ (date +%f-%h-%s). txt '

command-line editing :
Cursor Jump: Jump ctrl+a to the beginning, ctrl+e jump to the end of the line, ctrl+u delete the cursor to the beginning, delete the ctrl+k cursor to the beginning, to ctrl+l achieve clear screen;

file name wildcard character globbing
*: Any character of any length, such as ls a*3 finding a file that begins with a 3 ending with A;
?: matches any single character;
[]: matches any single character in the specified range,,, [a-zA-Z] [A-Z] For example, a [0-9] [0-9]*[0-9] file that matches the filename beginning and ending with a number;
[^]: Non, for example, [^0-9] a file that begins with a non-digit;
White space character: [[:space:]] , [:space:] indicates a blank character set;
[:lower:]: lowercase characters;
[:upper:]: uppercase characters;
[:alpha:]: uppercase and lowercase characters;
[:digit:]Digital
[:alnum:]: Numbers and capitalization;
[:punct:]: punctuation characters;
The above can be used to man 7 glob view;

pipeline, support redirection :

Command line expansion :

variables :

Programming :

Complete function :
Command completion and path completion.

Safety-related

User name : Use identity. Strictly case-sensitive, user ID;
authentication mechanism (authentication): password, fingerprint, iris, etc.;
Password Complexity rules : For example, 6-bit passwords:
Numbers: 10^6
Number Plus letter: 36^6
Numbers plus uppercase and lowercase letters: 62^6
Plus special characters: 100^6;

Password usage rules :
1, the use of 4 kinds of characters wrongly written characters at least three species;
2, long enough, more than 7 bits;
3, use random string;
4, regular replacement;
5, the cycle period is large enough;

User Rights Management

Authorization : Authorization
Permissions: Root,student,visitor
User Switching: That su is switch user , su root switch to administrator mode, for example.

Audit : Audition

command Prompt : Prompt,bash (Shell)
#: Root User
$: Ordinary users;

Command

format : COMMAND + OPTION + parameter (argument).

Options : Modify the execution characteristics of the command:
Short options, -char multiple options can be combined using: -b -a = = '-ab ' = = '--ba '; separated by a space;
Long option: --... You cannot use spaces.

parameters : The object of the command, for example, ls /root /bin you can specify more than one directory, displaying the contents of two directories.

Command Type :
Built-in command (shell built-in): type 命令 displaybuilt in
External command: An executable file with the same command name under a path in the file system, for example type ls ;

Environment Variables : Defines the working environment for the current user:
printenv: Displays the current working environment;
path: Displays the work path in which the command is found, first found in path, and then cached.
hash: The command will be stored and the next command will be looked up in the cache first. The internal is the key-value pair format, and O(1) the lookup speed is independent of the quantity!

variable : named Memory space, pointing to memory space;
Stack
Heap

echo: Displays line text correlation, default end with line break;
printf: line break must be specified manually \n ;

Manual command Help

view built-in commands : help Command ;
View external commands : Command --help ;
To view commands using man: man chap_num command :
View the command manual, but there are many chapters where you can specify chapters, usually in chapters with the following rules:
1: User command;
2: System call (/bin,/usr/bin,/usr/local/bin);
3: library call;
4: Special documents (equipment files);
5: File format
6: Game
7: Miscellaneous (miscellanceous)
8: Management Command (/sbin,/usr/sbin,/usr/local/sbin).
For example: man 2 command The number 2 shows the contents of the chapter.

whatis command: View the section related to the Read command.

Man Command features : In the document manual, to [] identify the content can be omitted to | indicate multiple selection one, the <> required content, ... can appear multiple times.

Man structure :
Name: command name and function brief description;
Synopsis: Usage notes, including available options;
DESCRIPTION: Detailed description of the command function;

Flip Screen shortcut key :
Flip the screen backwards:space
Turn back one line:enter
Flip the screen forward:b
To turn one line forward:k

Find command :
/keyword: Search backwards;
? keyword: Search forward;
n: The previous
N: The latter one

Exit :q

Online manual : The info command main supplement to man, mainly historical events and the like.

command Description file address : /usr/share/doc .

Google thinks about its solutions.

File system

rootfs: Root file system.

Root directory Introduction

/boot: The system starts the file first, such as kernel, INITRD, and Grub (bootloader);

/dev: devices, device-related files, providing access to the device, such as /dev/cdrom simply providing the device entry file, not CD access, or directly execute, can only take the back mount, associated media files.
Block devices: Random access, data blocks;
Character device: Linear access, in characters. For example: Display, mouse.
Device number: Has the main device number (major) and the secondary device (minor), different from the general file, no size, displayed as two numbers, separated by commas;

/etc: Configuration file main storage path;
/home: User's home directory, default is /home/USERNAME ;
/root: Administrator's home directory;

/lib: library file:
Static library file: .a ;
Dynamic Library shared library: library files loaded into memory can be mobilized by other applications, only one copy, such as .dll , .so , /lib/modules : kernel module files.

/media: mount point directory, such as placing a CD in the CD-ROM drive, it is necessary to associate it to a file system on a tree node, media is the role of the associated file. Generally used for mobile devices;

/mnt: Mount point, hanging on a temporary file system.
/opt: Optional catalogue;
/pro: Pseudo file system, most of which are kernel mapping files;

relevant to the system :
/sys: Pro, only after the system boot file, and hardware device-related property mapping file;
/temp: Temporary files, will be purged by the system for a certain period of time, all users have permission to access, but can only delete files created by themselves;
/var: variable files, such as the /var/run/ internal storage of some .pid files to save the process ID and other information;
/bin: Executable file, user command;
/sbin: Management commands, and bin are the system startup related programs and commands;
/usr: universal_shared_read-only, read-only files, is the system boot after the function of the folder, there are/usr/bin,/usr/sbin/;
/usr/local/[bin|sbin|lib], third-party related programs and commands, and system startup is irrelevant;

path : From the specified starting point to the location of the destination, hierarchical management files can simplify the search, the tree structure:
Absolute Path : Search starting from the root node;
relative path : The path relative to a location.

FHS: FileSystem level compliance, file system;
MagicNumber: For example, specified at the beginning of the file #!/bin/bash , specifies that the program executes the entry or format.

Directory Management

directory naming rules :
1, the length can not exceed 255 characters;
2, note can not be used / when the file name, it can only be used when the path delimiter;
3, strictly distinguish between the case;
LS cd pwd mkdir rmdir tree
The directory is the path map of the file;

Directory-related commands

1, List of directories , LS, CD, PWD;
ls: list, listing the files under the specified path, with the following options:
-l, display the complete information, from top to bottom content as follows
Result Analysis :
1th Place:
-: Normal file (f)
d: Catalog File
b: Block device files (blocks)
c: note Equipment file (character)
l: Symbolic Link files (symbolic link file)
p: Command pipe file (pipe)
s: Socket file (socket)
After 9 bits:
File permissions: After nine bits, every three bits of a group, rwx respectively for reading, writing, execute permissions;
Number of hard links to files;
The owner of the document;
(group) of documents;
File size (size), default unit bytes;
Time stamp (timestamp);
Access: access;
Change: Change,metadata meta data, file attributes;

Modified: Modify, file content changes;
-h: Human readable, do unit conversion
-a: Show . hidden files at the beginning
.: Current directory
..: Parent Directory
-A: Show . hidden files that do not begin with
-d: Displays the directory's own properties
-i: Index Node,inode, indexing node number of the file
-r: Show files in reverse order
-R: Recursive display

pwd: Printing working derectory, format:/根目录/分级目录/file

cd: Switch to the specified directory;
cdUser home directory, home derectory;
cd ~usernameSwitch to the user home directory;
cd -Switch back and forth between the current directory and the previous directory;

2. Create a directory :
mkdir x: Create x Catalog
mkdir x/yCreate directory y in the X directory
mkdir -p a/b/c: first create C, found that there is no parent directory B, ready to create B, and then find the parent directory of B, found that there is no a directory, then create a directory, will create three directories;
mkdir -pv /mnt/test/{x/y,m}: colleagues create two directories;
mkdir -pv {a,b}-{c,d}: Creation of A_c, A_d, B_c, b_d four folders;

3. Delete directory :
rmdir a: Only empty directory A can be deleted;
rmdir -p a/b/c: Only delete If the A, B and C directories are empty;
rm -rf a: Regardless of whether a is empty, a directory is deleted, which -r is recursive delete, -f not prompt when deleted;
rm -rf /: Delete all files in the current directory, note that it is not a last resort, do not use Administrator privileges!

File Management

Touch Stat file RM cp mv Nano vim

1. Create File:
touch file: Create File
stat: View all the properties of a file, primarily the file name, size, access, modification, and time of change.
touch -a file: Change access time only
-m: Changes modify time only; Change time follows hardware time change;
To modify access time only:touch -a -t 1612121111 a
Only modify Modify Time: touch -m -t 1212121111 a , modify time of file a

2. Edit the file:
nano a: File editor, similar vim editor;
vim a: Create and edit file A;

3, delete files: rm a : Note Here rm is a soft connection, in fact rm -i , equivalent to, that is, when the deletion will prompt.

4. Copy:
cp src dest: Not only can copy a file to a file, can also copy any number of files to the specified directory;
For example: mv a/b/1.txt x/y/ Copy the file 1.txt to the Y directory;
mv -r a/ x/: Copy the A directory to the X directory, specified here -r , using recursive replication;
-a: Archive, archive replication, often used for backup;
-p: Keep the source file permissions, ownership and access time, not specified will be modified to the current user rights, if the file is a linked file, then just copy the link to the file;
-P: If the target file is a link, the link will be copied, if not specified is only the file, will not copy the link;
cp /ect/{a,b,c}/x: Refers to copying three files;

5. Mobile:
mv src dest
Move the file or the entire directory to the target directory;
Modify the file or directory name: when the target directory or file does not exist;

6. Install:
-d: Drectory, you can create one or more directories;
install -t directoy src: Move source files to target directory, only move files, no -r option;

7, file : View the file content type;

Date related

Date, clock, Hwclock, Cal;

date: Check the time of the system, the default is that the current hardware time or a small difference;
Set the system time: The date -s 1211021212 format is: Month day seconds, and then modify the hardware time;

clock/ hwclock : Hardware time (motherboard built-in quartz timer), NTP Network Time Protocol, RTC (real times count);
-w: Set the hardware time to the system time;
-s: Set the system time to hardware time;

cal: Calendar, cal 2018 ;

Text Management text View

1 cat . Connect and display the text file;
-n: Show Line numbers
-E: Shown at the end of each line $ , for Linux, the line terminator is $ ;
Direct cat , Exit press ctrl+c can terminal current command;
If the file is too large, you can ctrl + pageup/down flip the screen up and down, but if the maximum number of cache screen, it will be lost!

2, more : Sub-screen view, only support backward, turn to the end of the exit, similar man command;

3, less : Support before (P) after turn (SAPCE), turn to the end will not exit;

4, head : View only the first n rows, the default is 10.
head -n 3 file: Specify N to view the first 3 rows;

5, tail : View the following n rows, the default is 10.
-f: Look at the end of the file, do not exit, wait to display the new content appended to this file;

Text Processing

The line record is processed.
1. cut :
-d: Specify delimiter, default is space;
-f: Specifies the field displayed, showing the -f 1,3 1th and 32 fields, -f 1-3 showing all fields from 1 to 3;

2, join : splicing;

3. sort : Sort each line of characters according to ASCII, ascending;
-n: Sort by numerical size;
-r: Descending sort;
-t: Specifies the delimiter -k : Index position (starting at 1), for examplesort -t : -k 3
-u: Unique, the same content is only displayed once, only for the adjacent and security of the same row system to think they are the same;

4.uniq
-d: Displays duplicate rows (once), adjacent and identical
-D: As long as the repetition is displayed;
-c: Shows the number of rows repeated;

Text Statistics

wc file: line, number of words, number of bytes;
wc -l: Number of rows
wc -c: Number of bytes;
wc -w: number of words;
wc -L: The length of the longest line (number of bytes)

character Processing

tr: Convert or delete characters, simple screen input and output, display in time;
tr ‘ab‘ ‘AB‘ < file: Use redirection to replace certain characters in the file;
tr ‘a-z‘ ‘A-Z‘: converts lowercase to uppercase;
-d: Delete all occurrences of the character, character by letter processing;

Rights Management

In order to allocate compute resources reasonably, you typically set permissions, that is, identifiers:
User: Set up users, such as admin,student;
User group: The user's container, associated with permissions, in which the user has permission to the container.

Security context: A process is a ownerships (owner and owner group).

The permissions are R, W, x three types:
For files:
r: Indicates readable, can be viewed;
w: Writable, can edit or delete this file;
x: Executable, excutable, can be submitted as a command to the kernel to run;

For files:
r: You can view the directory and use LS to list all the files in the directory;
w: Files can be created in this directory;
x: You can use the CD to switch to this directory, or you can use ls -l the details to view internal files.

rwx octal meaning :
0 ___ : No permissions
1 001 __x : Execution
2 010 _W_ : Write permission
3 011 _wx : Write and Execute
4 r__ : Read permissions
5 101 r_x : Read and Execute
6 rw_ : Reading and writing
7 111 rwx : Read, Write, and Execute permissions
For example, a file permission is 755 , that is rwxr_xr_x ;

The computer identifies the user using the UID (saved in the file /etc/passwd ) and the user group GID (saved in the /etc/group file).
Parse: Name resolution, based on database query for information.
Shadow password :
User: /ect/shadow ;
Group: /ect/gshadow .

User Category

Administrator , id=0, can access any file.

Normal user , id= "1-65535"
System User, id=1-499, dedicated user running background process, do not need to login system;
General user, id=500-60000

User Group Category

Private Group : If you do not specify a group to which you are creating a user, the system automatically creates a group with the same name as the user name;
Basic Group : User Default group;
additional groups and additional groups: groups other than the default group.

passwd file format

man 5 passwd
For example:root:x:0:0:root:/root:/bin/bash
Account: Login name;
Password: point to Shadow File
Uid
Gid
Comment: Notes
Home dir: Home directory
Shell: User's default shell

Shadow file

cat /etc/shadow: To view the file, format: root:$6$3g9wQ8ZnMgSDhVY6$a1OFPBdZMM8P.hDWp4RU5FQg.CcFerDnSCYYQLs/J6j1bOdHGZyML81SyWVchunsJEvc .
man 5 /etc/shadow: View format
Account: User Name
Password: encrypt password

Encryption method

symmetric encryption : Both encryption and decryption use the same password.

Public Key Cryptography : Each password appears in pairs, one is the private key (secret key) and the other is the public key (Publick key). Speed is three orders of magnitude slower relative to symmetric encryption, but more secure.

one-way encryption : Hash encryption, extract data signatures, each number has a unique signature (fingerprint encryption), can achieve the role of data validation.

Run the program device management process to manage network management other

Follow official website: www.kernel.org
GNU (provides various applications and library files) +linux (provides kernel)
Release: Compile the above contents into the CD and provide an installation excuse! For example: Fedora, Readhat (CentOS), SUSE, Debian (release version of Ubuntu two-time development mint)
Compiling: Converting the source code into a program that can be executed on the corresponding platform;
Gentoo system: It is time-consuming to compile software for the current version at installation time;
LSF (Linux from Scrach): Guide to manually creating a Linux system (patchwork software);
Only upward compatibility, not backward compatible;

Basics of Linux Operations

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.