Linux Novice Literacy (reprint)

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

1. Free/open source;

2. Support multi-threaded/multiuser;

3. Good security;

4. Superior in memory and file management.

Linux minimum requires 4m--> embedded development

Two. File directory

Linux system all hardware and software are in the form of files, you can freely set up, mount, uninstall. Understanding the Linux file directory is the key to learning Linux.

Main catalogue

/: Upper root directory of Linux file system, home directory.

/root: The Super Administrator's home directory, storing the root user-related files.

/home: General user directory or FTP site directory, storing ordinary user files.

/etc: Store system configuration related files.

/boot: The files needed to boot the Linux system and related boot files.

/dev: System device files, such as: Hard disk, printer.

/MNT: Add (hang) load point for the device file system. such as: CD-ROM, floppy disk, etc. mount directory.

/proc: Information about the current system core and program execution. (process, which processes information currently running on the system.) )

/usr: Store system applications and related files, similar to Win's program files.

/var: store files that are frequently changed by the system, such as log files, user mail.

/tmp: The system-zero file directory (such as the zero-hour file generated during Setup) allows each user to read and write to him, and the files in that directory are automatically deleted for a period of time without using the system.

/bin: The directory where executable commands are stored, and any user of the system can execute commands under that directory.

/sbin: The directory where the commands required to execute the system start are stored, and the commands in that directory require users with advanced permissions.

Swap: Virtual memory equivalent to Windows.

Current directory: PWD

Relative path: Refers to accessing a file from the current directory (folder)

Absolute path: Refers to accessing a file (folder) from the root directory (/)

Green----> representative executable file

Red----> represent compressed files

Dark blue----> representative catalogue

Light blue----> on behalf of linked files

Grey----> on behalf of some other files

Three. Linux System partitioning

Linux system partition and Windows, how to divide, how much different from each other, the base partition is as follows:

/root partition (general size is the total amount of hard disk remaining after dividing other partitions)

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

Swap is equivalent to win virtual memory, twice times the size of memory, preferably more than 1024M.

After a good area, you need to install the hardware and software can be mounted directly through the/MNT, do not need to uninstall.

(File mount first converts it to ISO format)

Four. Configuration of the Linux network environment

Three ways to modify IP

the first type (in GUI configuration in view mode):

    1. Log in as root, run the Setup command into the text Mode Setup utility to configure the network to IP, subnet mask, gateway, DNS settings.
    2. This operation does not take effect on the NIC configuration and requires a restart of the network.

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

The second type (quick change):

    1. Ifconfig eth0 x.x.x.x//Set the NIC
    2. Ifconfig eth0 Network x.x.x.x//Set subnet mask

Broadcast addresses and DNS are used by default.

Note: The network configuration for this operation takes effect immediately, but only temporarily, and the system reboot will revert to the previous.

The third (modify the bottom-level network card file content):

    1. Modify/etc/sysconfig/network-scripts/ifcfg-eth0 This file, can modify IP, subnet mask, Gateway, DNS, broadcast address and so on.
    2. This operation does not take effect on the NIC configuration and requires a restart of the network.

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

Set the system date

    1. Data: Executes directly, showing the current time of the system.

Data mmddhhmmccyy. Ss

Modify the system time, the following letter represents: The day of the month and day is divided into year by year. seconds

    1. View Calendars (Calendar)

View Calendar: Cal 5 2016//view May 2016 calendar

View Almanac: Cal 2016//view the Year 2016 calendar

User's environment variable:/home/user/.bash_profile

System Environment variables:/etc/profile

Configure the. bashrc file to specify that some programs start automatically when the user logs on:

One user on the system:/home/user/.BASHRC

Entire system (all users):/ETC/BASHRC

Linux Start-Up process Analysis

    1. BIOS self-test;
    2. Start Grub/lilo;
    3. Run the Linux kernel and detect the hardware;
    4. Run the system's first process init;
    5. Init reads the information from the system boot configuration file/etc/inittab;
    6. /etc/rc.d/rc,sysinit system initialization script;
    7. /etc/rc.d/rcx.d/[ks]* Configuration Service according to RunLevel X;

Terminating a service starting with K, initiating a service starting with s (for example, init 5)

    1. /etc/rc.d/rc/local performing local configuration;
    2. Other special services.

Five. User Management

Add User: Useradd user name (Useradd AAA)

Set/Change Password: passwd user name (passwd AAA)

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

To add a user to a user group:

Useradd–g User Group User (useradd–g root123 AAA)

Modify user attributes (Root permission required)

Usermod–g User Group User

Usermod–d Directory user name//change the initial directory of user login

Usermod-s Shell Type user name

Usermod-c Comment User Name

Usermod-u User Number User name

Delete User: Userdel aaa (delete user, but home directory file information still exists)

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

To view all users in the system:


To view all user groups on the system:


By default, a new user is created, and a user group named after the user name is generated.

Six. Process/Network state management


    1. In Linux, each executed program becomes a process and each process is assigned an ID number (PID).
    2. Each process corresponds to a parent process, and the parent process can replicate multiple child processes, such as the WWW server.
    3. Each process can exist in one or two ways, foreground and background.
    4. General system services are present in a background process, and reside in the system until the shutdown is over.

Processes and Threads:

Process: The program being executed.

Threads: 1. a lightweight process;

    1. The process has a separate address space, and the thread does not;
    2. A thread cannot exist independently, it is created by a process;
    3. The thread consumes less CPU and memory than the process.

View process: 1. Ps–aux (currently running process, static)

    1. Top (dynamic monitoring process)

To terminate a process:

Kill process Number (PID)

Eg:kill 16251//Terminate process with process number 16251

Kill-9 16251//Some processes cannot be killed, use the-9 parameter to force the termination process

Show Network status command: Netstat

This command is used to display the current network condition of the entire system. such as connections, packets, routing table contents.

Netstat–an display all port and connection information (including IP that is linked remotely to this computer)

Netstat–anp with the above, more display process number (PID), it is recommended to use this command

Show Packet history Command: traceroute

This command is used to detect the process of a packet being transmitted over a network, showing the full path of the route that the local to the destination host is experiencing.

Traceroute + parameter + Destination IP or URL//parameter can be ignored, equivalent to win under the tracert.


Route–n display native gateways, routing conditions.

There are 5 states of processes on Linux:
1. Running (running or waiting in the running queue)
2. Interrupt (dormant, blocked, waiting for a condition to form or receive a signal)
3. Non-interruptible (receive signal does not wake up and not run, process must wait until interrupt occurs)
4. Zombie (The process has been terminated, but the process descriptor exists until the parent process calls WAIT4 () after the system call is released)
5. Stop (process received Sigstop, SIGSTP, Sigtin, Sigtou signal after stop running run)

PS Tool identifies 5 status codes for the process:
D non-interruptible uninterruptible sleep (usually IO)
R run runnable (on run queue)
S Interrupt Sleeping
T stop traced or stopped
Z Zombie a defunct ("zombie") process

Seven. File management

File owner:

Is the user who created the file, and its owner is the user.

Ls–ahl Viewing file owners

A represents all, including hidden files; h represents the output file size; L represents a long list showing more detail.

Modify file Owner: Chown user name File name

Modify folder owner: Chown–r User name folder directory//linux-R is the meaning of recursion.

The group that the file resides in:

Which user created the file, and the group in which the user was located.

Ls–ahl viewing a group of files (as above)

Modify file group: CHGRP Group name File name

File and Directory permissions:

RWX = 421/read/write execution

chmod 777 AAA//Give file AAA maximum privileges

The file is empowered to execute the above format, which is explained in detail below.

chmod U=rwx,g=rx,o=rx AAA

Equivalent to chmod 755 AAA;U representative of USER;G representative Group;o on behalf of other

chmod u-x,g+w AAA//Give AAA Remove user Execute permission, increase user group Write permission

Eight. Common commands

Linux Run level init [0123456]

RunLevel 0: Shutdown//shutdown–h now can also be switched off immediately

1: Single User

2: Multi-user status No NETWORK service

4: System not used reserved to user

5: Graphical interface

6: System Restart//reboot

The common RunLevel is 3 and 5, which modifies the system startup default RunLevel:

The number in the Id:5:initdefault in the/etc/inittab file.

To view the user's current run level command: RunLevel or Who-r

If you accidentally set the default run level to 6, the system will restart continuously.

FIX: Press E in the Start screen, go to the second screen select the second line to press E, then enter 1 (single user boot, and enter no password required, can also be used to forget the password and then reset the password), into the Init 1 level with the command to change back to the default run level of the file.

Linux Common Commands

There is a problem with the Man Command (manual guide, equivalent to Dos under Help)

Eg: #man grep (followed by direct command)

LS: View file directory, equals dir

Ls–l with long list display, show more detailed content;

Ls–a Show hidden files;

LS–H displays the file size.

REDIRECT command:

Ls–l > A.txt writes the displayed content to A.txt (overwrite the original content)

Ls–al > Aa.txt Append the actual content to the end of the file Aa.txt (without overwriting the original content)

LSB_RELEASE-A//View version information

UNAME-A//Can display information about the computer and the operating system.

Cat/proc/version//Describes the version of the kernel that is running.

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

Touch: Create an empty file

mkdir: Creating a Folder

VI: Edit file to create file when file is not present

Cat: View File contents

CP: Copy command

Cp–r AAA BBB (recursive replication, copy AAA files and sub-files to BBB)

MV: Moving files or renaming

RM: Deleting files

RM–RF * Delete all contents of the folder (including directories and sub-files)

R Recursive F Force

LN: Establishes a symbolic link, which is equivalent to creating a shortcut link.

Ln–s source file path destination file path

Eg:ln–s/root/ TOABC3

It is created after it is displayed as follows (the file attributes will be multiple L, represented by the LN command)

MORE: Page shows the contents of the file, press space to view the next page, not to view the previous page content

Less: page displays the contents of the file, space to view the next page of content, the upper and lower keys can also view the upper/next page content

grep: Display the content found in text (grep displays only what is found, Cat displays text so content)

Grep–n displays the number of rows that the content contains

|: Pipe command, give the result of the previous command | The following command is processed. (one command can have multiple pipe commands)

Find: File Lookup

Find file path –name file name

Eg:find/-name aaa.txt full directory lookup Aaa.txt (the more detailed the path, the faster it is found)

★ Search for files or directories that have been accessed/changed over time:

FIND/HOEM–AMIN-10//Find files or directories accessed within 10 minutes

FIND/HOEM–ATIME-10//Find files or directories accessed within 10 hours

FIND/HOEM–CMIN-10//Find files or directories that have changed within 10 minutes

Find/hoem–ctime +10//Find a file or directory that was changed 10 hours ago

Find/hoem–size +10k//Find files larger than 10k in/home directory

A:access Access C:change Change

This lookup is used for security aspects, looking at system files that hackers have moved over time.

PWD: View current path

Whereis: Find the path to the destination file

Whereis ssh//view SSH path

Compression and decompression

Zip (compression) and unzip (uncompressed)

Zip (compression):

    1. Zip aaa//zip directly after the compressed file name, the AAA compressed into
    2. Zip–m AAA//Compress Delete original file, compress AAA into and remove AAA
    3. Zip–r AAA//Compress sub-directories together, folder AAA and its subdirectories are compressed together into (common)
    4. Zip-9 AAA//-9 Compression ratio ( -1--9,-9 compression rate is highest)

To compress the current folder, two methods:

(1) Zip–r . Represents the current folder

(2) Zip–r folder path/* (Eg:zip–r*)

Unzip (uncompressed):

    1. Unzip the file
    2. Unzip–x BBB//To decompress a file, in addition to the BBB others are decompressed
    3. Unzip–z compressed package contents, also available "-L", "-V" view

Unzip the compressed file somewhere: Unzip *.zip–d/directory (if no file is automatically created in this directory)

gzip (compression) and Gunzip (decompression):

    1. Gzip a.gz AAA//compression
    2. Gzip–d a.gz//Decompression

3.gunzip a.gz//Decompression

tar.gz decompression:tar-zxvf aaa.tar.gz

Corntab : used to set the periodic execution of instructions that can be used for task scheduling.

To terminate a task schedule:

Conrtab–r: Terminating task scheduling

Conrtab–l: Lists which tasks are currently scheduled

Other common commands:


Nine. Shell

Shell, Shell, refers to the "user interface" software, the command to parse into machine language. In effect, similar to cmd, the user command is accepted and then invoked, and functionally similar to the bat batch, the program can be written as shell execution.

Shell's classification:

Shell name Developer Command name

Bourne S.R. bourne/bin/sh

Bill joy/bin/csh C.

Kom David/bin/ksh

Shell modification: chsh–s Enter a new shell//eg:chsh–s/bin/csh

Different shell commands have a slight difference.

Shell script files that are executed automatically after the user logs in:

The. BASHRC is located in the user's home directory, before it executes the system's script/ETC/BASHRC, primarily to configure the underlying data

The. Bash_profile is located in the user's home directory, before it executes the system script/etc/profile, mainly configuring environment variables

Alias, which simplifies the input of common commands, and is used frequently by shell programs

Command: Alias custom naming = ' command to replace '

Eg:alias cp= ' Cp-i '

Alias Ll= ' Ls–l–color=tty '

10. Installation of the Software

RPM Management

RPM,RPM Package Manager (RPM Packages Manager), a package and installation tool for Internet downloads, which is included in some Linux distributions. It generates files with the. rpm extension, similar to dpkg. This file format name, although the Redhat logo, but its original design concept is open, now including OpenLinux, S.U.S.E, as well as the distribution of Linux such as Turbo Linux has been adopted, can be regarded as a recognized industry standard.

How to query which RPM software is installed in Linux:

RPM–Q//See if MySQL is installed

RPM–QA//View all RPM software

rpm Common commands:

To install the RPM package:

RPM–IVH *.rpm//I=install installation; V=verbose prompt; H=hash progress bar

To uninstall the RPM package:

Rpm–e *.rpm

If other packages depend on the package that is currently being unloaded, an error alarm is generated

Rpm–e–nodeps *.rpm

This command is used to force the current RPM package to be unloaded, but software that relies on this package may not run

Upgrade RPM Package:

Rpm–u *.rpm

File sharing:

1.Samba Server Installation: Linux developers seem to like to install this.

Installing the Portal

2.FTP Server Installation: This is used by most Linux machines.

Installing the Portal

3.SCP command:

SCP [OPTIONS] File_source File_target
EG:SCP ntp-4.2.8p7-0.10591.1.ptf.959243.x86_64.rpm [Email protected]:/home/boco4a

-V is the same as-V in most Linux commands to show progress. Can be used to view connections, certifications, or configuration errors
-C Enable Compression option
-P Select the port. Note-P has been used by RCP

4. Quick and Easy file transfer software:sshclient

In addition, Putty, Xshell, SECURECRT can also be used to manage hosts, but file transfers are based on FTP or RZ, SZ commands.

Mysql installation of the database

MySQL database is the first choice for small and medium business databases because it is free, cross-platform, light and multi-concurrency supported.


    1. Copy the installation files to/home
    2. Unzip the MySQL file. tar.gz command: TAR–ZXVF
    3. Groupadd MySQL//create user groups

useradd–g MySQL mysql//create MySQL user and put it into MySQL group

Go to the MySQL folder under/home

Sripts/mysql_install_db–user=mysql//Initialize Database

Chown Root. Modify the file owner (. Represents the current file directory)

Chown–r MySQL Data

Modify the Data folder owner (r parameter represents recursion, which represents all files/folders under the current folder)

Chgrp–r MySQL. Change user groups

Start MySQL

Bin/mysqld_safe–user=mysql &//& on behalf of the next stage start

See if Port 3306 is up: NETSTAT–ANP | More

Go to MySQL:

CD bin


Log in to MySQL (this way you can only start MySQL under/home/mysql/bin)

If you want to start MySQL in any directory, modify the path inside the environment variable:

ENV//Can see path paths

Under the root user directory Ls–al | More find. Bash_profile

(This file holds user variables, system variables in/etc directory)

Vi. bash_profile Add a MySQL path behind path path

Log Off/Restart your computer, then use mysql–uroot–p123 to enter MySQL on any path

(Note: This user can only be any directory, other users are still modified.) If you want all users to be able to, then need to change the system variable, the file also exists under/etc/profile)

Database backup and Recovery

The backup operation is in the bin directory under MySQL, not in the database.

When recovering, create a new empty database in the database.

You can use the Task Scheduler crontab to write a shell script to automatically back up the database.

Original address:

Linux Novice Literacy (reprint)

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: 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.