New Linux literacy and linux literacy

Source: Internet
Author: User
Tags ftp site zip folder custom name scp command

New Linux literacy and linux literacy
I. Linux features

1. free/open-source;

2. multithreading/multiple users are supported;

3. Good security;

4. superior memory and file management.

 

Linux requires at least 4 M --> embedded development

Ii. File directory

All hardware and software of Linux system exist in the form of files and can be freely set, mounted, and detached. Understanding the Linux File directory is the key to learning Linux.

Main directory

/: The upper root directory of the Linux File System, home directory.

/Root: The main directory of the Super administrator, which stores files related to the root user.

/Home: common user directory or FTP site directory, which stores common user files.

/Etc: stores system configuration files.

/Boot: stores the boot files required for Linux.

/Dev: system device files, such as hard disks and printers.

/Mnt: mount point of the device file system. Such as the Mount directory of the optical drive or floppy disk.

/Proc: information about the current system core and program execution. (Process, information about the currently running process of the system .)

/Usr: stores system applications and related Files, similar to win's Program Files.

/Var: stores files frequently changed by the system, such as log files and user emails.

/Tmp: The system zero-time file directory (such as the zero-time file generated during the installation process), each user can perform read and write operations on it, if the file is not used for a period of time, the system will automatically delete the files in this directory.

/Bin: directory for storing executable commands. Any user in the system can execute commands in this directory.

/Sbin: directory of the commands to be executed when the system starts. the commands in this directory can be used only by users with advanced permissions.

Swap: equivalent to windows virtual memory.

Current Directory: pwd

Relative Path: access a file (folder) from the current directory)

Absolute path: access a file (folder) from the root directory)

Green ----> indicates executable files

Red ----> indicates the compressed file

Dark blue ----> represents the Directory

Light blue ----> indicates the linked file

Gray ----> other files

Iii. Linux system partition

The Linux system partition is the same as that of windows. The partition size varies from person to person. The basic partition is as follows:

/Root directory partition (generally the total number of remaining hard disks After Dividing other partitions)

/Boot system boot, boot partition, free size (preferably 200 + M ).

Swap is equivalent to win's virtual memory, which is twice the memory size. It is better to exceed MB.

After partitioning, you need to install software and hardware that can be mounted directly through/mnt. You can uninstall the software and hardware when you do not need it.

(File Mounting first converts it to ISO format)

Iv. Linux Network Environment Configuration

Three methods for modifying IP addresses

First (in the guiView mode configuration ):

Command:/etc/rc. d/init. d/network restart

 

Second (quick modification ):

Use the default broadcast address and dns.

Note: The network configuration of this operation will take effect immediately, but it will only take effect temporarily, and the system will be restored to the previous one after restart.

 

Third (modify the content of the underlying Nic file ):

Command:/etc/rc. d/init. d/network restart

 

Set system date

Data MMDDHHMMCCYY. SS

// Modify the system time, with the following letters representing: Month, month, day, hour, minute, year, year, and second

 

  1. View calendar)

View calendar: cal 5 2016 // view calendar of May 2016

View calendar: cal 2016 // view the calendar for the entire year of 2016

 

USER environment variable:/home/user/. bash_profile

System environment variable:/etc/profile

The configuration. bashrc file specifies that some programs will be automatically started upon user login:

For a user in the system:/home/user/. bashrc

Entire system (all users):/etc/bashrc

 

LinuxStartup Process Analysis

Terminate services starting with K and start services starting with S (for example, init is 5)

  1. /Etc/rc. d/rc/local: execute local configuration;
  2. Other special services.

 

5. User Management

Add User: useradd username (useradd aaa)

Set/Change Password: passwd username (passwd aaa)

Add User Group: groupadd user group name (groupadd root123)

 

Add a user to a user group:

Useradd-g user group (useradd-g root123 aaa)

 

Modify user attributes (root permission required)

Usermod-g User Group

Usermod-d directory username // change the initial directory for User Login

Usermod-s shell User Name

Usermod-c comment User Name

Usermod-u user ID Username

 

Delete user: userdel aaa (delete user, but the user's home directory file information still exists in/home)

Userdel-r aaa (delete user and all user file information completely)

 

View all users in the system:

Cat/etc/passwd

 

View all user groups in the system:

Cat/etc/group

 

By default, a user group named after the user is created.

 

6. Process/Network Status Management

Process:

 

Processes and threads:

Process: The program being executed.

Thread: 1. Lightweight Process;

  1. The process has an independent address space, and the thread does not;
  2. A thread cannot exist independently. It is created by a process;
  3. The cpu and memory consumed by the thread is smaller than that of the process.

View process: 1. ps-aux (currently running process, static)

  1. Top (dynamic monitoring process)

Terminate process:

Kill process ID (PID)

Eg: kill 16251 // terminate a process whose process number is 16251

Kill-9 16251 // some processes cannot be killed. Use the-9 parameter to forcibly terminate the process.

 

Command for displaying network status: netstat

This command is used to display the current network conditions of the entire system. Such as connection, data packet, and route table content.

Netstat-an displays all ports and connection information (including ip addresses remotely linked to the local machine)

Netstat-anp compared with above, multi-display process ID (PID), this command is recommended

 

Command for displaying the packet history: traceroute

This command is used to detect the process of data packets transmitted over the network and shows the complete route path from the local host to the target host.

Traceroute + parameter + target IP address or URL // parameter can be ignored, which is equivalent to tracert in win.

Eg: traceroute www.baidu.com

 

Route-n displays the local gateway and route information.

 

There are five processes in linux:
1. Run (running or waiting in the running Queue)
2. interruption (in sleep, blocked, waiting for the formation or receipt of a signal of a condition)
3. Do not interrupt (do not wake up when receiving the signal or do not run, the process must wait until there is an interruption)
4. Stiff (the process has been terminated, but the process descriptor exists until the parent process calls wait4 () and is released after the system call)
5. Stop (the process stops running after receiving signals from SIGSTOP, SIGSTP, SIGTIN, and SIGTOU)

 

Five status codes used by the PS tool to identify a process:
D. uninterruptible sleep (usually IO) cannot be interrupted)
R run runnable (on run queue)
S interrupt sleeping
T stop traced or stopped
Z dead a defunct ("zombie") process

 

VII. File Management

File owner:

The owner of a file created by a user is the user.

Ls-ahl view the file owner

// A indicates that all files are displayed, including hidden files; h indicates the size of the output files; l indicates that a long list is used to display more details.

 

Modify the file owner: chown username and file name

Modify the folder owner: chown-r user name folder directory // in Linux,-r indicates recursion.

 

File Group:

The user who created the file and Its group is the user's group.

Ls-ahl)

 

Modify file group: chgrp group name file name

 

File and directory permissions:

Rwx = 421 // read/write execution

Chmod 777 aaa // grant file aaa the highest permission

 

Execute the preceding format for file authorization. The following is a detailed explanation.

 

Chmod u = rwx, g = rx, o = rx aaa

// Equivalent to chmod 755 aaa; u stands for user; g stands for group; o stands for other

Chmod u-x, g + w aaa // Remove User execution permissions for aaa and add write permissions for user groups

 

8. Common commands

LinuxRunning levelInit [0123456]

Running level 0: shutdown // shutdown-h now can also be shutdown immediately

1: Single User

2: No network service in multi-user status

4: The system is not used and retained to the user.

5. Graphic Interface

6: system restart // reboot

The common running levels are 3 and 5. Modify the default running level for system startup:

Id: 5: Number in initdefault in the/etc/inittab file.

 

View the user's current running level commands: runlevel or who-r

 

If you accidentally set the default running level to 6, the system will continue to restart.

Solution: Press e on the startup interface, enter the second interface, select the second line, and press e, and enter 1 (start with a single user and enter without a password, can also be used when the password is forgotten and then reset the password), enter the init Level 1, use the command to change back to the default file running level.

 

LinuxCommon commands

 

Use the man command (manual guide, which is equivalent to the help in dos)

Eg: # man grep (followed by the command)

 

Ls: view the file directory, which is equal to dir

Ls-l is displayed in the long list to show more details;

Ls-a: show hidden files;

Ls-h shows the file size.

 

Redirection command:

Ls-l> a.txt writes the display content to a.txt (overwrite the original content)

Ls-al> aa.txt Add the current content to the end of aa.txt (not overwrite the original content)

 

Lsb_release-a // view version information

Uname-a // displays information about the computer and operating system.

Cat/proc/version // specifies the running kernel version.

Cat/etc/issue // displays the release version information

Touch: Create an empty file

Mkdir: Create a folder

Vi: edit the file. If the file does not exist, you can create the file.

Cat: View File Content

Cp: Copy command

Cp-r aaa bbb (recursive replication, copying aaa files and sub-files to bbb)

Mv: Move or rename a file

Rm: delete an object

Rm-rf * Delete all contents of the folder (including directories and subfiles)

R recursion f forced

Ln: establishes a symbolic link, which is equivalent to creating a shortcut link.

Ln-s source file path target file path

Eg: ln-s/root/abc3.java toabc3

// The following figure is displayed after the object is created (multiple l files are created before the object attribute, representing the established ln command)

More: display the file content by page. Press space to view the next page. You cannot view the previous page content.

Less: displays the file content by PAGE, and displays the content of the next page with spaces. You can also view the content of the next page with the up/down key.

Grep: display the content to be searched in the text (grep only displays the searched content, and cat displays the text and so on)

Grep-n: number of lines in the displayed content

|: Pipeline command, hand over the result of the previous command | the subsequent command is processed. (A command can have multiple pipeline commands)

 

Find: file search

Find file path-name file name

Eg: find/-name aaa.txt full directory to find aaa.txt (the more detailed the path, the faster it will be)

★Search for files or directories that have been accessed/changed for a period of time:

Find/hoem-amin-10 // find the file or directory in ten minutes

Find/hoem-atime-10 // find the files or directories in the ten-hour memory

Find/hoem-cmin-10 // find the files or directories that have been changed within 10 minutes

Find/hoem-ctime + 10 // find the files or directories that have been changed 10 hours ago

Find/hoem-size + 10 k // find files larger than 10 k in the/home Directory

A: access c: change changes

This search is mostly used for security. It allows you to view system files that have been moved by hackers for a period of time.

 

Pwd: view the current path

Whereis: Find the path of the target file

Whereis ssh // view the ssh path

 

Compression and decompression

Zip(Compressed) and unzip(Extract)

Zip (Compressed ):

 

To compress the current folder, use either of the following methods:

(1) zip-r 111.zip. //. indicates the current folder

(2) zip-r 111.zip folder path/* (eg: zip-r 111.zip/home /*)

Unzip ):

Decompress the compressed file and scan the unzip *. zip-d/directory (if no file exists in the directory, it will be automatically created)

 

Gzip(Compressed) and gunzip(Decompress ):

3. gunzip a.gz // Extract

 

Tar.gzDecompress:Tar-zxvf aaa.tar.gz

 

Corntab:It is used to set the periodically executed commands and can be used for task scheduling.

Terminate task scheduling:

Conrtab-r: Terminate Task Scheduling

Conrtab-l: lists the current task scheduling tasks.

 

Other common commands:

Http://www.oschina.net/translate/useful-linux-commands-for-newbies

Http://www.tecmint.com/20-advanced-commands-for-middle-level-linux-users/

 

IX. Shell

Shell refers to the software that "provides user interfaces" and parses commands into machine languages. In terms of function, similar to cmd, it accepts user commands and then calls the corresponding application; in terms of function, it is similar to bat batch processing, and the program can be compiled into shell for execution.

 

Shell classification:

Shell Name developer command name

Bourne S. R. Bourne/bin/sh

C Bill Joy/bin/csh

Kom David/bin/ksh

 

Modify Shell: chsh-s enter the new shell // eg: chsh-s/bin/csh

 

Different shell commands are slightly different.

 

The shell script file automatically executed after the user logs in:

. Bashrc is located in the main directory of the user. It previously runs the system script/etc/bashrc, mainly to configure basic data.

. Bash_profile is located in the main directory of the user. It previously executed the system script/etc/profile, mainly used to configure environment variables.

 

Alias (alias), which simplifies the input of Common commands and is frequently used by shell programs.

Command: alias custom name = 'COMMAND to be replaced'

Eg: alias cp = 'cp-I'

Alias ll = 'LS-l-color = tty'

 

10. Software Installation

RPMManagement

Rpm, short for RPM Package Manager, is a packaging and Installation tool used to download packages from the Internet. It is included in some Linux distributions. It generates files with. rpm extensions, similar to dpkg. Although the file format name is marked with RedHat, its original design concept is open, including OpenLinux, S. u. s. e. as well as distribution versions of Linux such as Turbo Linux have been adopted, it can be regarded as an industry standard.

 

How to query which rpm software is installed in linux:

Rpm-q // check whether mysql is installed

Rpm-qa // view all rpm Software

RpmCommon commands:

Install the rpm package:

Rpm-ivh *. rpm // I = install installation; v = verbose prompt; h = hash progress bar

 

Uninstall the rpm package:

Rpm-e *. rpm

// If other software packages depend on the packages to be detached, an error is reported.

Rpm-e-nodeps *. rpm

// This command is used to forcibly uninstall the current rpm package, but the software dependent on this package may not be able to run

 

Upgrade the rpm package:

Rpm-U *. rpm

 

File Sharing:

1. SambaServer installation:In Linux, developers seem to like to install this.

Install Portal

2. FTPServer installation:This is used by most Linux machines.

Install Portal

3. SCP command:

Scp [OPTIONS] file_source file_target
Eg: scp ntp-4.2.8p7-0.10591.1.PTF.959243.x86_64.rpm: boco4a@200.200.0.114:/home/boco4a

OPTIONS:
-V is the same as-v in most linux commands. It is used to display the progress. It can be used to view the connection, authentication, or configuration error.
-C enable compression options
-P: select the port. Note that-p has been used by rcp.

4. Convenient and convenient file transfer software:SshClient

In addition, putty, xshell, and secureCRT can also be used to manage hosts, but file transmission is based on FTP, rz, and sz commands.

 

MysqlDatabase Installation

Mysql databases are free, cross-platform, lightweight, and support for multi-concurrency, and have always been the first choice for small and medium-sized enterprise databases.

 

Installation:

Useradd-g mysql // create a mysql user and put it in the mysql Group

Go to the mysql folder under/home

Sripts/mysql_install_db-user = mysql // initialize the database

Chown root. // modify the file owner (. represents the current file directory)

Chown-R mysql data

// Modify the data folder owner (the R parameter indicates recursion, indicating all files/folders in the current folder)

Chgrp-R mysql. // Change User Group

Start mysql

Bin/mysqld_safe-user = mysql & // & stands for starting later

Check whether port 3306 is Enabled: netstat-anp | more

Go to mysql:

Cd bin

./Mysql-uroot-p123

// Log on to mysql (this method can only start mysql under/home/mysql/bin)

If you want to start mysql in any directory, modify the PATH in the environment variable:

Env // you can see the PATH

Locate. bash_profile in the root user directory ls-al | more

(This file stores user variables in the/etc directory)

Vi. bash_profile Add the mysql PATH to the PATH

Log off/restart the computer, and use mysql-uroot-p123 to access mysql from any path.

(Note: Only any directory of this user can be modified by other users. If you want all users to do this, you need to change the system variable. This file also exists under/etc/profile)

 

Database backup and recovery

The backup operation is in the bin directory of mysql, not in the database.

Create an empty database in the database before restoring the database.

 

You can use the task scheduling crontab to write a shell script to automatically back up the database.

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.