The basic use of linux

linux

installation

  • Installation
    1. Virtual machine resource allocation can not exceed the unit's own resources
    2. LAN: NAT mode, only windows to access the machine, the machine can not access the other network. Bridge: the other machine within the network can also be accessed
    3. Install windows linux vm tools that interact with

table of Contents

  • Features linux directory structure?
    With '/' root directory tree structure. In linux directory everything is a file
  • Common catalog
    1. / Dev hardware device mapping file
    2. / Media U disk loading at
    3. / Root super-user's home directory
    4. / Bin storing most frequently used instructions
    5. / Lib shared dynamic link library
    6. / Opt installation package
    7. / Boot system configuration
    8. / Mnt share files at
    9. / Etc configuration files and subdirectories my.config
    10. / Home folder for each user-specific repository
    11. / Usr software installed at
    12. / Usr / local software installation directory
    13. / Var frequently modified files. Such as logs

Remote Connection

  • How remote connection?
    By XShell like the software to connect, to determine linux sshd service is turned on before connecting. Input through the terminal setupto view
    through xftp used to transfer files

vi 与 I came

  • What is the vi and vim?
    Text editor, vim is an enhanced version

  • Three common mode
    1. Insert
      Press i I o O a AR to any one of the letters to enter edit mode
    2. Command line
      : entry mode quit q q wq save and exit forced to quit!
    3. Normal
      vim into the other mode by entering the ESC mode
  • Common shortcuts
    yy copies the current line normal mode
    5yy normal copy mode line 5
    p paste in the normal mode
    dd delete the current line normal mode
    under the normal mode 5dd delete rows 5
    G document last line in the normal mode
    gg the first line in the document under normal mode
    u revoked in normal mode
    20 shift g jump to the line 20 normal mode
    / hello hello look at the command line mode
    : set nu show line numbers in the command line mode
    : set nonu cancel OK the next number in the command line mode

Boot and reboot and logoff

  • Shutdown restart
    shutdown
    shutdown -h nowshutdown immediately
    shutdown -h 1one minute shutdown
    shutdown -r nowimmediately restart
    haltshutdown
    rebootto restart the
    syncsynchronization instruction memory, the data is written to memory

  • User login logout
    login by ordinary users, do not try to root login
    logoutlogout users

User Management

  • User groups
    each user belongs to at least one user group
  • Add User
    useradd [选项] 用户名
    successfully added automatically creates a corresponding home directory
  • And add the user to specify their home directory corresponding
    useradd -d /home/test/ xiaoming
  • Specify a password
    passwd xiaoming
  • delete users
    userdel 用户名
  • Delete the corresponding retained home
    userdel xiaoming
  • Delete does not retain the corresponding home
    userdel -r xiaoming
  • Query User Information
    id 用户名
  • Switch User
    su 用户名
  • Return by the user
    exit
  • The current user queries
    whoami
  • Add Group
    groupadd 组名
  • Adding user-specified group
    useradd -g 用户组 用户名
  • Modifying User Groups
    usermod -g 用户组 用户名
  • User information stored?
    / etc / passwd
  • User group information stored?
    / etc / group
  • Password information stored?
    / etc / shadow

Run Level

  • linux operating level seven minutes analogy Windows normal mode and security mode, the configuration file etc / inittab
    off 0-
    1-mono user
    2- multiuser no network
    3- multi-user network
    4- unused reserved for system users
    5 - GUI
    6- system reboot
    init[0123456]

Help command

  • View Help Contents
    man ls
    help cd

File Directory class

  • How to display the absolute path to the current directory?
    pwd
  • How to view the current contents of the directory?
    ls -al: Display all, including hidden
    ls -l: the information displayed in a list
  • How to switch directory?
    cd ..On a
    cd ~home directory
  • How to create a table of contents?
    mkdir /home/dogCreate a single-level directory
    mkdir -p /home/animals/tigerto create multi-level directory
  • How do I delete a directory?
    mkdir /home/dogDelete empty directory
    rm -rf /home/tigersto delete non-empty directory
  • How to create a file?
    touch 文件名称
  • How to copy a file?
    cp source destCopy individual files
    cp -r source destrecursively copy folders
    \cp -r source destrecursively copy the folder does not cover tips
  • How to remove a file or directory?
    rm /home/aaa
    rm -r /home/aaaRecursively delete the entire folder
    rm -rf /home/aaarecursively deleted without prompt
  • How to rename or move?
    mv oldName newNameRename
    mv fileName /temp/Move to Folder
  • How to view the files?
    cat /etc/profileRead-only files
    cat -n /etc/profile | moreshow pages and line numbers have
  • How to Redirect and append?
    ls -l>fileNameOverwritten file content list
    ls -al>>=fileNamelisting additional content written to a file in
    cat fileName1>fileName2the file to a file cover 2
    echo "txt">>fileName
  • How to output the content to the console?
    echo [选项] [内容]
    echo $path 输出环境变量
  • View part of the file?
    head /etc/profileThe default view files before 10 rows
    head -n 5 /etc/profile5 rows before viewing the file
    tail /etc/profileafter the default view file 10 line
    tail -n 5 /etc/profileafter line 5 to view the file
    tail -f /etc/profiledynamic tracking monitor file for viewing log
  • How to view instructions have been executed?
    historySee all command
    history 10to view 10 history instruction
    !33execution section 33 history instruction

The date and time

  • How to display the current time?
    date
    date +%YOn display
    date +%mdisplay month
    date +%dand day are displayed
    date "+%Y-%m-%d"format prescribed display time
  • How to set time?
    date -s "2019-10-10 11:22:22"Content specified time by a string
  • How to view the calendar?
    calDisplay month
    cal 2020display a given year

Search Find

  • How do I find?
    find /home -name hello.txtIn the scope of the home directory lookup by file name
    find /opt -user nobodyin the directory opt essay by file name to find a home user
    find / -size +20Mto search by file size in the root directory lookup
    find / -name *.txtto find all the txt file in the root directory
  • Filtration and pipeline applications?
    cat hello.txt | grep yescat View files, pipes | viewing the contents of the cat to grep command Search by yes conditions
    cat hello.txt | grep -n yeswith line numbers
    cat hello.txt | grep -i yesignore case

Extracting archive

  • How to extract compressed files?
    gzip hello.txtHello.txt compressed file and does not retain the original file
    gunzip hello.txt.gzto extract the files
  • How to extract the compressed files and directories?
    zip -r test.zip /home/Recursive compression in test.zip entire home directory in
    unzip -d /opt/tmp test.zipthe extract to test.zip / opt / tmp directory
  • How to pack and unpack?
    tar -zcvf a.tar.gz a1.txt a2.txtThe two files are packaged a1.txt a2.txt a.tar.gz compressed in the
    tar -zcvf home.tar.gz /home/recursive package an entire home directory zcvf
    tar -zxvf home.tar.gzextract the entire packet zxvf
    tar -zxvf home.tar.gz -C /opt/extract to the / opt directory

Group management and rights management

  • Owner of the file, where the group and other groups. Not necessarily the same owner and all groups.
    ls -ahlCheck the file owner
    chown root test.txtto modify the file owner
    chgrp centos test.txtto modify the file's group
    usermod -g root centosto modify the root group centos

  • What file types?
    -Ordinary file
    d:directory
    lsoft link
    ccharacter device, the keyboard
    bblock devices, hard disk

  • Check the file permissions how?
    Check the file permissions to view a file, the previous owner of the first shows, where the group, the other group of three privilege level
    privilege level read and write operations are divided into
    -rw-r--r-- 1 tom police 6 3月 20 19:24 ok.txt
    0-9-bit
    -type file
    rw-read and write permissions to the owner of the
    r--file where the group only read access
    r--other groups only read permission file
    1number of the number of subdirectories or hardwired
    6file size in bytes, folder 4096 is constant
  • Kinds of permissions rwx?
    For file rwx read, modify, execute
    the directory read rwx ls view, modify, delete rename mkdir to create a directory, you can run the cd into the directory
  • How to modify permissions?
    r = 4 w = 2 x = 1 array notation
    . 7 = rwx
    . 6 = RW
    . 5 = RX
    . 3 = WX
    0 = No rights
    u: Owner g: where the group o: others a: all
    chmod u=rwx,g=rx,o=rx abcmodifications abc rights owners rwx, rx others, where the group rx
    chmod u-x,g+w abcowner cancel x permission to increase the rights of all groups w
  • How to modify the file owner?
    chown -R tom kkk/Recursive folder kkk modify the owner of all files to tom
  • How to modify the file owner?
    chgrp -R bandit kkk/

Task scheduling

  • crontab

  • How to set the schedule file?
    Stored in / etc / crontab
  • Understanding of the schedule file?
    crontab -eInto the schedule file editing, deployment scheduling tasks. Tasks can be written directly by calling or writing task command file sh, sh command file to set the x permission.
    */1 * * * * ls -l /etc >> /tmp/to.txtEvery minute representation, etc the list of additional write /tmo/to.txt
  • How practical application?
    vim matask.shSh edit a file, execute written content date >> /tmp/mydate, mytaskx given permission, by corntab -eentering the deployment file, write*/1 * * * * /home/mytask.sh
  • For example application?
    Two daily automatic backup mysql in testdb to a file in mydb.bak

Partition

  • How to view the partition and mount the case of system?
    lsblk -f
  • How to query the disk situation?
    df -lh
  • How to use a directory inquiries?
    du -ach --max-depth=1 /opt
    -s specified directory (or the current directory)
    -h with units of measurement
    -a file containing
    --max-depth = 1 subdirectories depth
    -c listed in detail at the same time
  • ? Practical instruction
    ls -l /home | grep "^-" | wc -lfirst query, use grep filter "-" get all files with wc statistics.
    ls -lR /home | grep "^-" | wc -lFirst query, use grep filter "-" get all files with wc statistics. -R recursive
    treetree showing files

Network Configuration

  • Automatically obtain IP of the shortcomings?
    IP address may be changed, not suitable for server applications.
  • How fixed IP?
    By configuring the / etc / system / network -scripts / ifcfg-eth0
  • How to view the network situation?
    -anA certain order
    -pshows which processes the call
    netstat -anp | moreto see all network
    netstat -anp | sshdview of network conditions sshd

Process Management

  • How to view the process performed by the system?
    ps -aAll the current terminal process information
    ps -uusers format process information
    ps -xbackground process parameter
    ps -aux | grep sshdview sshd related processes
  • How to view the parent process?
    ps -ef | moreView parent ppid
  • How to terminate the process?
    kill -9 3333By 3333 kill process process ID, -9 forced to commit suicide
    killall geditto kill all of the same name process by process name
  • View the process tree
    pstreeprocess tree
    pstree -pprocess tree with a process ID
    pstree -uprocess tree with the process belongs to the user
  • Dynamic monitoring process?
    top3 seconds refresh
    input u and then enter a user name, a user in the top of the monitor
    input k in the top re-enter the process id number, to kill a process
    input N in the top, press the PID sorting
    input M in the top, a sort of memory
    in the top of the input P, sorted by CPU
    top -d 1010 seconds refresh

Service Management

  • In fact, the essence of the service process running in the background, listening on a port, waiting for the requestor.
  • Common commands and parameters?
    service service name [start | stop | restart | reload | status] is used in centos7 systemctl
  • How to detect whether the port is listening?
    telnet 192.168.52.3 22windows instructions, see the 22-port server.
  • See all services?
    setup
    ls -l /etc/init.d/
  • Services run level?
    chkconfig --listView all services whether or not to start at different run levels
    chkconfig --level 5 sshd offsshd service does not start automatically when the 5 level.

rpm package

  • rpm, analog setup.exe
  • How to check rpm?
    rpm -qa | grep firefoxAccess to firefox not installed
    rpm -qi firefoxinquiries installation information
    rpm -ql firefoxquery file path to the installation and installation of
    rpm -qf /etc/passwda query which package a file belongs
  • rpm uninstall?
    rpm -e firefoxUninstall firefox
    rpm -e --nodeps firefoxforced uninstall firefox
  • rpm installation
    rpm -ivh firefox.rpminstall firefox
    -iinstall
    -vprompt
    -hprogress bar

yum follicles

  • Automatically install dependencies based management rpm, advantages
  • yum list | grep firefox Seek
  • yum install firefox run

Guess you like

Origin www.cnblogs.com/KSea/p/12355365.html