Getting Started with Linux foundation under

Eight, Linux pipes, redirection, and text processing

8.1, Linux and more collaborative command: pipes and redirection

8.1.1 Open Source Culture

  • One of the core concept of open source culture is not to reinvent the wheel, a lot of open source software is re-combining existing software, code, function as if by assembling machine parts, like open and shared source code to make this possible, but also greatly improve the efficiency and productivity.

8.1.2 pipes and redirection

  • Among Linux system, most commands are simple, complex functions rarely command, each command or often only achieve one or a few very simple function, we can pass the different functions of the command used in combination, to the purpose of completing a complex function.
  • Linux, almost all returned data commands are plain text (because the command is run in CLI), and plain text data is input format most commands, which allow multiple command called may collaborate
  • Linux commands provided us with pipes and redirection mechanisms, multi-command coordination is done through pipes and redirection.
  • Command-line shell data stream has the following definitions:
name Explanation Numbering default
STDIN Standard Input 0 keyboard
STDOUT Standard output 1 terminal
STDERR Standard error 2 terminal
  • STDIN received command data or parameter, or by STDOUT output by output error STDERR
  • Redirection through the conduit and we can control the flow of data CLI
classification Keyword definition example
Redirect > STDOUT will be redirected to a file (cover) echo "linuxcast.net" > outfile ls -l > outfile
Redirect >> STDOUT will be redirected to a file (Append) echo "linuxcast.net" >> outfile data >> outfile
Redirect 2> The STDERR redirected to a file (cover) ls nothere 2> errorout
Redirect 2>&1 STDERR will combine with STEOUT ls nothere 2>&1 alloutput
Redirect < Redirect STDIN grep linuxcast < /etc/passwd
pipeline | STDIN to STDOUT as a command to another command ls -l | grep linuxcast find / -user linuxcast | grep video find / -user linuxcast 2> /dev/null | grep video
  • Pipes commonly used to command different combinations to implement a complex function
  • Output redirection is typically used to hold information about a command or error information can be used to record the results of the error message or saved to a specified folder

8.2, Linux command-line text-processing tools

8.2.1 File Browser

  • cat view the file contents
  • more view file contents page form (only page down)
  • less view the file contents page form (can flip up and down)
  • 10 head start line to view the file (or specify the number of rows)
  • 10 tail end of the line to view the file (or specify the number of rows)

8.2.2 based on keyword search

  • Grep command for searching text-based keyword, such as:
    • grep 'linuxcast' / etc / passwd single keyword may not be used ''
    • find / -user linuxcast | grep Video
    • find / -user linuxcast 2> /dev/null | grep Video
  • grep common parameters:
    • -i ignore case when searching
    • -n displays the number of the row results
    • -v output without specifying keywords
    • -Ax contain specified number of rows after the row results in the output of
    • -Bx containing specified number of lines before the row results in the output of

8.2.3 Column-based text processing

  • Command to cut the column processing text-based content
    • cut -d: -f1 /etc/passwd
    • grep linuxcast /etc/passwd | cut -d: -f3
  • Common parameters:
    • -d Specifies the separator character (default is Tab)
    • -F designated column number output
    • -c character-based cutting: cut -c2-6 / etc / passwd

8.2.4 Text Statistics

  • Wc command for statistical information text (word count)
    • wc linuxcast
  • Common parameters:
    • -l only count the number of rows
    • -w only count the word
    • -c only count the number of bytes
    • -m only count the number of characters

8.2.5 Text Sort

  • Sort command to sort text content
    • sort linuxcast
  • Common parameters:
    • -r conduct reverse order
    • sort -n-based digital
    • -f Ignore case
    • -u delete duplicate rows
    • c -tc used as delimiters to sort columns
    • -kx when carried out which columns are sorted based on the specified character as a separate sort column is specified based on

8.2.6 delete duplicate rows

  • Sort -u command can be used to delete duplicates
  • Uniq command to remove duplicate adjacent lines

Text Compare 8.2.7

  • Diff command to compare the difference between two files
    • diff linuxcast linuxcast.net
  • Common parameters:
    • -i ignore case
    • -b Ignore changes in amount of white space
    • -u unified display comparative information (usually to generate a patch (patch) file)
      • diff -u linuxcast linuxcast-new > final.patch

8.2.8 Spell Checker

  • Aspell command to display checks the spelling of English
    • aspell check linuxcast
    • aspell list < linuxcast

8.2.9 Working with text content

  • Tr for processing text commands (Translator)
    • Delete keywords: tr -d 'TMD' <linuxcast
    • Change case: tr 'az' 'AZ' <linuxcast

8.2.10 search and replace

  • Sed command users to search and replace text
    • sed 's/linux/unix/g' linuxcast
    • sed '1,50s/linux/unix/g' linuxcast
    • sed -e 's / linux / unix / g' -e 's / nash / nash_su / g' linuxcast
    • sed -f sededit linuxcast (by saving 's / linux / unix / g' file search and replace sededit file and the parameters used to call up the file -f)

Nine, Linux system startup Detailed

9.1、BIOS

  • BIOS (Basic Input Output System) which we call BIOS typically stored on the motherboard BIOS chip
  • When the computer starts to run is the first BIOS, BIOS is responsible for checking the hardware and find bootable devices
  • It can be defined boot device in the BIOS setup, such as USB, CDROM, HD

9.2、MBR

  • After the BIOS boot device may find its boot code execution
  • The first 446 bytes of the boot code of the MBR

9.3、GRUB

  • Grub bootloader is now mainstream use of Linux
  • It can be used to direct almost all operating systems now
  • Grub-related files are stored in / boot / grub directory
  • Grub configuration file /boot/grub/grub.conf
  • Configuration format:
title CentOS 
        root (hd0,1)
        kernel /boot/vmlinuz-2.6.32-279.e16.i686 ro root=UUID=77272833-B6BB-4D53-B043-9541D1102EBD 
        initrd /boot/initramfs-2.6.32-279.e16.1688.img

9.4、KERNEL

  • MBR boot code will be responsible for finding and loading the Linux kernel
  • The Linux kernel keeps in /boot/vmlinuz-2.6.32-279.e16.i686
  • General will load the kernel module package file: /boot/initrammfs-2.6.32-279.e16.i686.img
  • Why stay thin Linux kernel will drive some of the less frequently used functions compiled into modules dynamically loaded when needed, and these modules are packaged saved as a file initramfs
  • Early versions of Linux use initrd file, initfamfs is an alternative initrd optimized version, save more space than initrd, more flexible
  • Dmesg command can be viewed at this startup kernel output

9.5、INIT

  • init process is the first Linux operating system
  • Call /etc/rc.d/rc.sysinit responsible for initializing the system, mount the file system, and starts the appropriate service depending on the operating level
  • Linux run level:
    • 0 Shutdown
    • 1 single-user mode
    • 2 Multi-user mode without network
    • More than three-user mode
    • 4 Not used
    • Graphics mode 5 X11
    • 6 Restart
  • By / etc / inittab configuration file to modify the default run level
  • Each level corresponds to the start of the service stored in /etc/rc.d/rc[0123456].d
  • Runlevel command displays the current level and on a run
  • Init command can be used to change the current run level
    • init 3
    • init 5

9.6, single user to modify the ROOT password

  • Single-user mode to kernel passing the parameter "1" or "single" may System
  • Do not start any service in single-user mode
  • Single-user mode directly as root user login, and does not require a password
  • You can use passwd to modify the root password
    • Press the Start button down when the guide page pause, the guide can be press e edit page, row select kernel, then key e can edit the default cursor at the end, after entering a carriage return, then b is started, which is the kernel is forced to start up in single-user mode, you can change the root password after startup is complete, change the input after the completion of exit after the transport system will exit single-user mode in the normal mode is started
    • This approach also has a security risk, as long as anyone can physically close to the user computer, he would only need to restart the computer, and then passed to the kernel boot time parameters can change the root password, this is very dangerous, in order to prevent any such As long as people can approach the computer will be able to change the password to happen, grub joined a cryptographic operation.

9.7, GRUB encryption

  • To encrypt by the addition of grub following parameters in grub.conf boot configuration:
    • password encryption password --md5 +
  • The encrypted password can be generated by grub-md5-crypt
    • Enter the root user grub-md5-crypt, after the carriage return will generate an encrypted password, copy all passwords (including the final., But do not copy more space), then vi /boot/grub/grub.conf, most well in the first row is inserted: password --md5 + encryption password, save and exit.
  • After you configure encryption on the grub boot menu and then want to change, then you must enter the password, the normal boot is not needed, but you have to modify the contents, then you need a password.
  • If you have forgotten your password grub, it basically can not break, can only remove the hard drive, mount to the other machine, and then the hard disk root partition boot partition boot file folder where the mount on another Linux machine inside the system, and then delete the configuration, and then you can go. In fact, this is still a security risk, the hard disk was stolen someone else or to get in your system to go inside. If you want to protect your data, only root partition partition-level encryption.

Ten, Linux software management infrastructure: RPM, YUM

10.1, source code form

  • The vast majority of open source software is distributed in source code form directly
  • The source code will generally be packaged into a compressed archive file tar.gz
  • After the source code is compiled into a binary form of program needs to be able to run with
  • Basic source code compilation process:
    • 1- ./configure checking build environment, the relevant libraries, and configuration parameters and generate makefile
    • 2- make the source code is compiled, executable file
    • 3- make install the generated executable computer installed into the current
  • Software source code is cumbersome to use, but preferably the compatibility and controllability
  • Open source software is usually a large number of other functions using open source software, open source software, so there will be a large number of dependencies (using a software you need to install additional software)

10.2、RPM

10.2.1 RPM design goals

  • A disadvantage of the source code: complex operation, a longer compilation time, very prone to errors
  • The advantage of source code: applicable to all systems, can be customized
  • For ease of use, Erik Troan and Marc Ewing developed the RPM (Redhat Package Manager)
  • RPM by specific compiler source code platform-based system as an executable file, and save the dependencies to simplify installation management of open source software
  • RPM design goals are as follows:
    • Simple to use
    • Use a single software package file format release (.rpm files)
    • Scalable
    • Tracking software dependencies
    • Basic information inquiry
    • Software Verification
    • Multi-platform support

10.2.2 RPM packages commonly used naming convention:

  • linuxcast-1.2.0-30.e16.i686.rpm
    • linuxcast: Software name
    • 1.2.0-30: The version number, there are major version number, there are a small version number
    • e16: corresponding system, e16 representative of Red Hat enterprise 16
    • i686: is representative of the 32-bit platform, if it is generally 64 x86_64

10.2.3 RPM basic commands:

  • Installing the software: rpm -i software.rpm
  • Uninstall the software: rpm -e software (not behind the .rpm)
  • Upgrade in the form of installation: rpm -U software-new.rpm
  • rpm support the installation of software through http, ftp protocol: rpm -ivh http://www.linuxcast.net/software.rpm

  • You can add the following parameters:
    • -v Show Details
    • -h display a progress bar

10.2.4 RPM Queries

  • RPM will save a lot of information related to the software, available through the following command:
    • rpm -qa List all installed software rpm
    • rpm -qf filename query object files belong to which rpm package
    • rpm -qi packagename query specifies information rpm installed software
    • rpm -ql packagename rpm query specifies the file that contains the software has been installed
    • Information rpm -qip software.rpm query the rpm file
    • File rpm -qlp software.rpm query file contains rpm

10.2.5 RPM verification

  • Malicious software may be modified in the dissemination process, so for safety reasons, the system now have joined the validation of the software
  • Authentication is normally an asymmetric encryption algorithm, it requires a secret key
  • Importing keys:
    • rpm --Import RPM-GPG-KEY-CentOS-6
  • Verify rpm file:
    • rpm -K software.rpm
  • Verify installed software:
    • rpm -V software

10.3 YUM

  • RPM package management software form is convenient, but the need to manually resolve package dependencies, a lot of time to install a software need to install one or more (sometimes up to hundreds) of other software, very complex when manually resolved. Use YUM can solve this problem.

10.3.1 YUM

  • YUM (Yellowdog Updater, Modified) RPM is a front-end program, the main purpose is designed to automatically resolve dependency problems RPM. Its characteristics are as follows:
    • Automatically resolve dependencies
    • It can be grouped RPM, and mounting operation based on the group
    • The introduction of the concept of a warehouse, supports multiple warehouses
    • Simple configuration

10.3.2 YUM warehouse

  • YUM introduces the concept of a warehouse (repo), the warehouse used to store all existing rpm package, when using yum install a rpm software, if there is a dependency, reliance will automatically find and install software in the warehouse
  • Warehouse can be local, or through HTTP, FTP or NFS used in the form of centralized, unified network warehouse
  • Warehouse management using yum save rpm package, warehouse configuration file stored in the directory /etc/yum.repos.d/ the following format:
[LinuxCast]
name = This is LinuxCast.net rpm soft repo
baseurl = http://www.linuxcast.net/yum/centos/6/i386/rpms/
enabled = 1
gpgcheck = 1
  • Warehouse can use file, http, ftp, nfs way
  • yum configuration file must end with .repo
  • You can save the configuration information across multiple warehouses in a configuration file
  • There may be multiple configuration files in the directory /etc/yum.repos.d/
  • The default view when integrated yum warehouse system installation: Practice
    • cd /etc/yum.repos.d/
    • cat CentOS-Base.repo

10.3.3 YUM basic commands

  • yum management software commonly used commands:
    • yum install software-name specified software installation
    • yum remove software-name Uninstall the specified software
    • yum update software-name specified software upgrade
  • Action: Using yum command to install tigervnc.x86_64
    • yum install tigervnc.x86_64

10.3.4 YUM query

  • Yum query operations using the following command:
    • yum search keyword search
    • yum list (all | installed | recent | updates) lists all installed, the most recent software updates
    • yum info packagename displays information about the software
    • yum whatprovides filename which contains the target file rpm query software
  • Practice: All inquiries rpm package contains 'vnc' of
    • yum search vnc

10.3.5 Creating YUM warehouse

  • Yum repository can be created manually by following ways:
    • 1 Copy all the rpm files to a folder (ls -l | wc -l can see the number of rows, that is, the number of packages)
    • 2 command manually install the software rpm createrepo
    • 3 Run command createrepo -v / rpm-directory
    • 4 If there are packets of information, specify the -g file grouping parameters when running the command
createrepo -g /tmp/*comps.xml /rpm-directory
CentOS/RHEL 的分组信息保存在光盘 repodata/ 目录下,文件名以 comps.xml 结尾的 xml 文件
  • Once you've created the machine can be used directly by way of file, if required as external YUM repository server, you can share it through HTTP, FTP, or NFS protocols

10.3.6 YUM CACHE

  • YUM To speed cache is usually a lot of information, but sometimes the cache will cause some fault, you can clear the cache with the following command:
    • yum clean all
  • Every time you install or run a query class will rebuild command yum cache

Guess you like

Origin www.cnblogs.com/duncan1863/p/11588679.html