Linux [B]


Linux

在这里插入图片描述

Linux 1: Linux Kernel Intro & VMware Intro

  • linux kernel
  • netcraft
  • vmware
  • Centos
  • Others:
  • RedHat
  • Fedora
  • Debian
  • Gentoo
  • Ubuntu
  • Install VMware workstation
  • Setup Windows 8!!!
  • restart: esc> bios> security>system security>virtualization enabled> continue
    在这里插入图片描述

在这里插入图片描述

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

在这里插入图片描述
在这里插入图片描述

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

Linux 2: CentOS

  • install Centos 64
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述

在这里插入图片描述

在这里插入图片描述
在这里插入图片描述

  • choose yes, discard any data

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

在这里插入图片描述
在这里插入图片描述

在这里插入图片描述
在这里插入图片描述

  • choose write changes to disk
    在这里插入图片描述
    在这里插入图片描述

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

  • right click >open terminal

在这里插入图片描述
在这里插入图片描述

Linux 3: Linux Environment

在这里插入图片描述
在这里插入图片描述

  • can create static IP: vmnet8
    在这里插入图片描述

  • vmware> edit>virtual network editor
    在这里插入图片描述

  • IP addres: 1-255 , do not user 1 or 2
    在这里插入图片描述
    在这里插入图片描述

  • enter example: your inet address: 192.168.189.130 / mask:255.255…/DHCP address: 192.168.189.2

  • shell commands

ifconfig
hostname
hostname bigdata01 


vi /etc/sysconfig/network
# vi /etc/sysconfig/network>  i (insert)>  change HOSTNAME=bigdata01>esc> shift+:> wq (write and quit) enter 
reboot

在这里插入图片描述
在这里插入图片描述

vi /etc/hosts
# i>192.168.189.130 bigdata01 > esc> shift+:>wq

在这里插入图片描述

  • add
#hadoop01
192.168.189.130 bigdata01

在这里插入图片描述

vi /etc/sysconfig/network-scripts/ifcfg-eth0
# i> DNS1=192.168.189.2> esc> shift+:>wq
# may not be needed?
service network restart
ping www.baidu.com
  • if unsuccessful do the following
  • 1,cmd输入regedit,进入注册表[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class{4D36E972-E325-11CE-BFC1-08002BE10318}],先导出做备份。
  • 2,逐项查看其下的[项](0000,0001至00xx),看右边哪一项的[值]为:“DriverDesc”=“VMware Virtual Ethernet Adapter for VMnet8”。
  • 3,找到后,添加一个“DWORD”值(32位),名称为“*NdisDeviceType”(*号是必须的),数据值改为“1”。
  • success
    在这里插入图片描述
  • ctrl C to stop process

Linux 4: Linux Basics I

  • SecureCRT
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
ls
ls / #list from root 
ls -l /opt # -options (object)
ls -l # list details
ls -a # list all
ls -al #list all details
ls -d #distinct
cd /
ls /etc/
pwd #show current path
clear #ctl l
ifconfig
loopback
  • filezilla
    在这里插入图片描述
  • notepad has ftp plugin: NppFTP

Linux 5: Linux Commands

  • rm -rf ./*
  • remove all
mkdir test_data/data01
ll
ls test_data/
mkdir test_data/data02  
mkdir -p test_data/data02 #-p parent,can create multiple files
ls test_data/
touch bf.txt #create file
touch pro file #creates pro and file
touch "pro file" #creates "pro file" as one file
rmdir #remove directory
rm bf.txt #remove file
rm -r test_data #remove directory
rm -rf test_data #remove directory
cp file bd_data/ #copy file
cp -r bd_data/ #copy recursively
mv "pro file" bd_data/  #move file
mv file bd.txt #rename file
mv "pro file" bd.list #rename "pro file" bd.list
vi bd.list # > i> "data" > esc> shift ; > wq>
cat bd.list #display
cat /etc/passwd #display
cat /etc/hosts
cat /etc/sysconfig/network
more #display by screen use q to quit
less #can scroll
cat /etc/passwd
head /etc/passwd #list first 10 lines
head -3 /etc/passwd #list first 3 lines
tail /etc/passwd #list last 10 lines
tail -3 /etc/passwd #list last 3 lines
-f #match second or further fragments only

Linux 6: Linux Basics II

在这里插入图片描述

在这里插入图片描述

cd / #root, admin /root
cd ~ #back to user main menu user /home/***

cat /etc/passwd
root:x:0:0:root:/root:/bin/bash  #3rd: UID 4th:GID (group id (teacher:t1,t2...)) usually same
...
tcpdump:x:72:72::/:/sbin/nologin
useradd bduser # adduser
tail -5 /etc/passwd #
postfix:x:89:89::/var/spool/postfix:/sbin/nologin
pulse:x:497:496:PulseAudio System Daemon:/var/run/pulse:/sbin/nologin
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
tcpdump:x:72:72::/:/sbin/nologin
bduser:x:500:500::/home/bduser:/bin/bash #bduser added
ls /home/
bduser
ls /home/bduser
passwd bduser
Changing password for user bduser.
cat /etc/group
bduser:x:500:
  • switching users
[root@bigdata01 home]# su - bduser  # switch user
[bduser@bigdata01 ~]$
[bduser@bigdata01 ~]$ pwd
/home/bduser
[bduser@bigdata01 ~]$ su - root
Password: 
[root@bigdata01 ~]#  
[root@bigdata01 ~]# su bduser
[bduser@bigdata01 root]$ su
Password: 
[root@bigdata01 ~]# exit
exit
[bduser@bigdata01 root]$ 
[bduser@bigdata01 ~]$ exit
logout
[root@bigdata01 home]# exit
logout
  • su (switch user)
  • su - (switche user and environment): recommended
[root@bigdata01 ~]# su - bduser
[bduser@bigdata01 ~]$ su
Password: 
[root@bigdata01 bduser]# pwd
/home/bduser
[root@bigdata01 bduser]# echo $PATH
/usr/lib64/qt-3.3/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/bduser/bin
[root@bigdata01 bduser]# exit
exit
[bduser@bigdata01 ~]$ su -
Password: 
[root@bigdata01 ~]# pwd
/root
[root@bigdata01 ~]# echo $PATH
/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
[root@bigdata01 ~]# 
  • userdel -r dbuser (-r remove user folder)
[root@bigdata01 ~]# adduser bduser3
[root@bigdata01 ~]# tail -3 /etc/passwd 
tcpdump:x:72:72::/:/sbin/nologin
bduser:x:500:500::/home/bduser:/bin/bash
bduser3:x:501:501::/home/bduser3:/bin/bash
[root@bigdata01 ~]# ls /home/
bduser  bduser2  bduser3
[root@bigdata01 ~]# userdel -r bduser3
[root@bigdata01 ~]# ls /home/         
bduser  bduser2
[root@bigdata01 ~]# tail -3 /etc/passwd
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
tcpdump:x:72:72::/:/sbin/nologin
bduser:x:500:500::/home/bduser:/bin/bash
  • r read 4 : cat more tail less head…
  • w write 2: vi mkdir rm touch cp mv…
  • x execute 1: execute, cd
  • u user
  • g group
  • o other
  • u g o
  • rwx r-x r-x = 755
  • rw- r-- -r-- = 644
  • change mode: chmod , chmod u+x file, add +, minus -
  • chmod u+x,g+x,o+x file #edit
  • chmod 644 file #edit by number
  • chmod -R 777 bd_data/ #recursively edit multiple files
cd ~ #~ is the contraction for /home
#dr-xr-xr-x # directory , r- read w- write, x- execute 3 types of permission
[root@bigdata01 /]# touch file
[root@bigdata01 /]# ll
total 98
-rw-r--r--.   1 root root     0 Aug  3 21:05 file #####################

[root@bigdata01 /]# chmod u+x file 
[root@bigdata01 /]# ll
total 98
-rwxr--r--.   1 root root     0 Aug  3 21:05 file#####################

[root@bigdata01 /]# chmod u-x file
[root@bigdata01 /]# ll
total 98
-rw-r--r--.   1 root root     0 Aug  3 21:05 file#####################

[root@bigdata01 ~]# ll
total 104
-rw-r--r--. 1 root root     0 Jul 25 18:39 file#####################

[root@bigdata01 ~]# chmod u+x,g+x,o+x file
[root@bigdata01 ~]# ll
total 104
-rwxr-xr-x. 1 root root     0 Jul 25 18:39 file#####################

[root@bigdata01 ~]# chmod 644  file       
[root@bigdata01 ~]# ll
total 104
-rw-r--r--. 1 root root     0 Jul 25 18:39 file#####################

[root@bigdata01 ~]# chmod 755 file
[root@bigdata01 ~]# ll
total 104
-rwxr-xr-x. 1 root root     0 Jul 25 18:39 file#####################

[root@bigdata01 ~]# chmod 777 file
[root@bigdata01 ~]# ll
total 104
-rwxrwxrwx. 1 root root     0 Jul 25 18:39 file#####################

[root@bigdata01 ~]# ls bd_data
bd.list  bd.txt  data99
[root@bigdata01 ~]# ls -l bd_data
total 8
-rw-r--r--. 1 root root   18 Jul 25 19:42 bd.list
-rw-r--r--. 1 root root    0 Jul 25 18:51 bd.txt
drwxr-xr-x. 2 root root 4096 Jul 25 19:02 data99
[root@bigdata01 ~]# chmod -R 777 bd_data/
[root@bigdata01 ~]# ll
total 104
drwxrwxrwx. 3 root root  4096 Jul 25 19:42 bd_data
[root@bigdata01 ~]# ls -l bd_data        
total 8
-rwxrwxrwx. 1 root root   18 Jul 25 19:42 bd.list
-rwxrwxrwx. 1 root root    0 Jul 25 18:51 bd.txt
drwxrwxrwx. 2 root root 4096 Jul 25 19:02 data99
  • chown: change ownership :admin only
  • chgrp: change group
  • can user -R to recursively change
[root@bigdata01 ~]# su - bduser
[bduser@bigdata01 ~]$ pwd
/home/bduser
[bduser@bigdata01 ~]$ mkdir bd
[bduser@bigdata01 ~]$ ll
total 36
drwxrwxr-x. 2 bduser bduser 4096 Aug  3 21:22 bd
[bduser@bigdata01 ~]$ chown root bd/
#chown: changing ownership of `bd/': Operation not permitted
[bduser@bigdata01 ~]$ exit
logout
[root@bigdata01 ~]# cd /home/
[root@bigdata01 home]# ll
total 8
drwx------. 27 bduser bduser 4096 Aug  3 21:22 bduser
drwx------.  4    501    501 4096 Jul 30 23:14 bduser2
[root@bigdata01 home]# cd bduser
[root@bigdata01 bduser]# ll
total 36
drwxrwxr-x. 2 bduser bduser 4096 Aug  3 21:22 bd
[root@bigdata01 bduser]# chown root bd/
[root@bigdata01 bduser]# ll
total 36
drwxrwxr-x. 2 root   bduser 4096 Aug  3 21:22 bd
[root@bigdata01 bduser]# chgrp root bd
[root@bigdata01 bduser]# ll
total 36
drwxrwxr-x. 2 root   root   4096 Aug  3 21:22 bd 
[root@bigdata01 bduser]# chown bduser:bduser bd/
[root@bigdata01 bduser]# ll
total 36
drwxrwxr-x. 2 bduser bduser 4096 Aug  3 21:22 bd
######################
  • rm : remove : with respect to folder access instead of file access
[root@bigdata01 /]# mkdir temp
[root@bigdata01 /]# ll
drwxr-xr-x.   2 root root  4096 Aug  3 21:34 temp
[root@bigdata01 /]# touch temp/testfile.txt
[root@bigdata01 /]# ls -l temp/testfile.txt
-rw-r--r--. 1 root root 0 Aug  3 21:34 temp/testfile.txt
[root@bigdata01 /]# chmod 777 temp/
[root@bigdata01 /]# ls -ld temp/
drwxrwxrwx. 2 root root 4096 Aug  3 21:34 temp/
[root@bigdata01 /]# ls -l temp/testfile.txt
-rw-r--r--. 1 root root 0 Aug  3 21:34 temp/testfile.txt
[root@bigdata01 /]# rm temp/testfile.txt
#rm: remove regular empty file `temp/testfile.txt'? y
[root@bigdata01 /]# ls temp/
[root@bigdata01 /]# 
  • vi & vim basically same, vim has more functions
  • vi 123.txt >i>add stuff>esc> shift+:> wq>
  • other quit methods: after esc> shift+ZZ
  • other quit: after shift+:>x
  • wq! insist quit
  • command
  • edit mode
  • last line mode
  • set nu :after shift+: show line number
  • after esc: dd: delete (3dd: delete 3 line or cut)
  • after esc: u : undo
  • after esc: p: paste
  • after esc: yy: copy (3yy: copy 3 lines)
  • after esc: G: move to end
  • after esc: gg: move to home
  • after shift+: enter line number
  • after shift+: search root, :/root
  • replace: 1, $s/aaa/666/g (replace(s) from 1st(1) line to ( $)last line from “aaa” to “666” (g) general)
[root@bigdata01 bduser]# touch 123.txt
[root@bigdata01 bduser]# more 123.txt
[root@bigdata01 bduser]# ll
total 36
-rw-r--r--. 1 root   root      0 Aug  3 21:41 123.txt
[root@bigdata01 bduser]# vi 123.txt #esc> shift+:> wq>                                                                                               
[root@bigdata01 bduser]# vi 234.txt
[root@bigdata01 bduser]# ll
total 36
-rw-r--r--. 1 root   root      0 Aug  3 21:43 123.txt
-rw-r--r--. 1 root   root      0 Aug  3 21:43 234.txt
[root@bigdata01 bduser]# vi 123.txt
123
456
789
000                                                                                              
"123.txt" 4L, 16C written
[root@bigdata01 bduser]# cat 123.txt
123
456
789
000

[root@bigdata01 bduser]# vi passwd
      1 root:x:0:0:root:/root:/bin/bash
      2 bin:x:1:1:bin:/bin:/sbin/nologin
      3 daemon:x:2:2:daemon:/sbin:/sbin/nologin
...                                                                                             
:set nu
  • Linux normally differs upper and lower case
  • find < scope> < condition>
  • find / -name init
  • (* ) find anything, repeat ok
  • ? find anything, no repeat (??? 3 files) (?? 2 files),
  • find /etc/ -iname init??? does not differentiate upper lower case
  • find /etc/ -name init* #find all files starting with keyword
  • find /etc/ -name *init * #find all files with keyword
[root@bigdata01 bduser]# find / -name init
/lib/alsa/init
/etc/sysconfig/init
/etc/kdump-adv-conf/kdump_initscripts/init
/etc/init
/selinux/initial_contexts/init
/usr/share/dracut/modules.d/99base/init
/usr/share/alsa/init
[root@bigdata01 bduser]# find /etc/ -name init
/etc/sysconfig/init
/etc/kdump-adv-conf/kdump_initscripts/init
/etc/init
[root@bigdata01 bduser]# find / -name init
/lib/alsa/init
/etc/sysconfig/init
/etc/kdump-adv-conf/kdump_initscripts/init
/etc/init
/selinux/initial_contexts/init
/usr/share/dracut/modules.d/99base/init
/usr/share/alsa/init
/sbin/init
[root@bigdata01 bduser]# find /etc/ -name init
/etc/sysconfig/init
/etc/kdump-adv-conf/kdump_initscripts/init
/etc/init
[root@bigdata01 bduser]# find /etc/ -name *init*
/etc/festival/siteinit.scm
/etc/sysconfig/network-scripts/init.ipv6-global
/etc/sysconfig/init
/etc/rc.sysinit
/etc/security/namespace.init
...
[root@bigdata01 bduser]# find /etc/ -name init* 
/etc/sysconfig/network-scripts/init.ipv6-global
/etc/sysconfig/init
/etc/selinux/targeted/contexts/initrc_context
/etc/kdump-adv-conf/kdump_initscripts/init
/etc/rc.d/init.d
...
[root@bigdata01 bduser]# find /etc/ -name init??
/etc/rc.d/init.d
/etc/init.d
[root@bigdata01 bduser]# find /etc/ -name init???
/etc/inittab
[root@bigdata01 bduser]# touch /etc/INITTAB
[root@bigdata01 bduser]# find /etc/ -iname init???  
/etc/INITTAB
/etc/inittab
  • -size
  • data block smallest: 512 bytes
  • 100mb=102400kb *2 approx 204800 data blocks, 1mb=1024kb
  • find /-size +204800 # + is >, - is <
[root@bigdata01 bduser]# find / -size +240800
/sys/devices/pci0000:00/0000:00:0f.0/resource1
/sys/devices/pci0000:00/0000:00:0f.0/resource1_wc
find: `/proc/9599/task/9599/fd/5': No such file or directory
find: `/proc/9599/task/9599/fdinfo/5': No such file or directory
find: `/proc/9599/fd/5': No such file or directory
find: `/proc/9599/fdinfo/5': No such file or directory
/media/CentOS_6.4_Final/images/install.img
  • -user, -group
  • -type
  • -a or -and
  • find /etc/ -name init* -and -type f
  • f file
  • d data
[root@bigdata01 bduser]# find /root -group root
[root@bigdata01 bduser]# find /root -user root
[root@bigdata01 bduser]# find /etc/ -name init*
/etc/sysconfig/network-scripts/init.ipv6-global
/etc/sysconfig/init
/etc/selinux/targeted/contexts/initrc_context
/etc/kdump-adv-conf/kdump_initscripts/init
/etc/rc.d/init.d
/etc/init.d
/etc/inittab
/etc/init
/etc/init/init-system-dbus.conf
[root@bigdata01 bduser]# find /etc/ -name init* -and -type f
/etc/sysconfig/network-scripts/init.ipv6-global
/etc/sysconfig/init
/etc/selinux/targeted/contexts/initrc_context
/etc/kdump-adv-conf/kdump_initscripts/init
/etc/inittab
/etc/init/init-system-dbus.conf
[root@bigdata01 bduser]# find /etc/ -name init* -a -type d
/etc/rc.d/init.d
/etc/init
  • Linux environment
  • static IP: NAT mode
  • hostname
  • cat /proc/sys/kernel/hostname
  • cat /etc/sysconfig/network
  • #net mapping
  • /etc/hosts #show ip address and host, parse domain name DNS
  • ONBOOT=yes # on boot up connect network driver
  • BOOTPROTO=none #static IP
  • BOOTPROTO=dhcp #automatic IP
  • BOOTPROTO=static # static IP
  • service network restart
[root@bigdata01 bduser]# hostname
bigdata01
[root@bigdata01 bduser]# cat /proc/sys/kernel/hostname
bigdata01
[root@bigdata01 bduser]# cat /etc/hosts            
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
[root@bigdata01 bduser]# cat /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=bigdata01
[root@bigdata01 bduser]# cat /etc/sysconfig/network-scripts/ifcfg-eth0 
...
ONBOOT=yes
...
  • COMMON COMMANDS

  • Create: mkdir -p touch vi

  • Delete: rmdir rm -r -f

  • Edit: cp -r mv

  • Lookup: cat more less head tail -f

  • Search: find -name -iname -size -user -group -type

  • ACCESS

  • rwx : read/ write / execute

  • user, group, other

  • 421

  • chmod :admin and user

  • chown: admin

  • USER & USERGROUP

  • useradd ***

  • passwd ***

  • userdel -r ***

  • su - ***

  • REBOOT

  • reboot, intt 6

  • SHUTDOWN

  • init 0, shutdown -t -r -k -h …

  • Snapshot for VM
    在这里插入图片描述

  • sudo #access

  • visudo #must be admin: root (ip or net) ALL=(ALL) ALL (scope, bin/mkdir sbin/touch)

  • man sudo #manage

  • man visudo

  • man 5 sudoers

  • visudo=/etc/sudoers

  • vi /etc/sudoers

[root@bigdata01 ~]# cd /
[root@bigdata01 /]# ls
bin   dev  file  lib    lost+found  misc  net  proc  sbin     srv  temp  usr
boot  etc  home  lib64  media       mnt   opt  root  selinux  sys  tmp   var
[root@bigdata01 /]# ls bin
alsaunmute            dbus-daemon    fgrep               kill        nano             rpm        tracepath
arch                  dbus-monitor   find                link        netstat          rvi        tracepath6
awk                   dbus-send      findmnt             ln          nice             rview      traceroute
...

[root@bigdata01 /]# visudo
## Sudoers allows particular users to run various commands as
## the root user, without needing the root password.
##
## Examples are provided at the bottom of the file for collections
## of related commands, which can then be delegated out to particular
## users or groups.
##
## This file must be edited with the 'visudo' command.
[root@bigdata01 /]# man sudo
SUDO(8)                   BSD System Manager’s Manual                  SUDO(8)

NAME
     sudo, sudoedit - execute a command as another user
....

[root@bigdata01 /]# man visudo
VISUDO(8)                 BSD System Manager’s Manual                VISUDO(8)

NAME
     visudo - edit the sudoers file
SYNOPSIS
     visudo [-chqsV] [-f sudoers]
...

[root@bigdata01 /]# man 5 sudoers
SUDOERS(5)                  BSD File Formats Manual                 SUDOERS(5)

NAME
     sudoers - default sudo security policy module

DESCRIPTION
     The sudoers policy module determines a user’s sudo privileges.  It is the default sudo policy plugin.
     The policy is driven by the /etc/sudoers file or, optionally in LDAP.  The policy format is described
     in detail in the SUDOERS FILE FORMAT section.  For information on storing sudoers policy information in
     LDAP, please see sudoers.ldap(5).
     ...

[root@bigdata01 /]# more /etc/sudoers
## Sudoers allows particular users to run various commands as
## the root user, without needing the root password.
...
## Drivers
# Cmnd_Alias DRIVERS = /sbin/modprobe

# Defaults specification
...
  • which

  • where is shutdown

  • root ALL=(ALL) ALL

  • bduser ALL=/sbin/shutdown -r now

  • sudo shutdown -r now

[root@bigdata01 ~]# visudo
...
## Allow root to run any commands anywhere
root    ALL=(ALL)       ALL
bduser ALL=/sbin/shutdown -r now
...
[root@bigdata01 /]# cd /home
[root@bigdata01 home]# ll
total 8
drwx------. 27 bduser bduser 4096 Aug  4 19:06 bduser
drwx------.  4    501    501 4096 Jul 30 23:14 bduser2
[root@bigdata01 home]# cd ..
[root@bigdata01 /]# su - bduser
[bduser@bigdata01 ~]$ shutdown
shutdown: time expected
#Try `shutdown --help' for more information.
[bduser@bigdata01 ~]$ shutdown -r now
shutdown: Need to be root
[bduser@bigdata01 ~]$ which shutdown
/sbin/shutdown
[bduser@bigdata01 ~]$ whereis shutdown
shutdown: /sbin/shutdown /usr/share/man/man8/shutdown.8.gz /usr/share/man/man2/shutdown.2.gz /usr/share/man/man3p/shutdown.3p.gz
[bduser@bigdata01 ~]$ ls /sbin
accton           ethtool                ip6tables-restore-1.4.7  lvrename             plipconfig           shutdown
...
[bduser@bigdata01 ~]$ sudo -l
[sudo] password for bduser: 
Matching Defaults entries for bduser on this host:
    requiretty, !visiblepw, always_set_home, env_reset, env_keep="COLORS DISPLAY HOSTNAME HISTSIZE INPUTRC KDEDIR
    LS_COLORS", env_keep+="MAIL PS1 PS2 QTDIR USERNAME LANG LC_ADDRESS LC_CTYPE", env_keep+="LC_COLLATE
    LC_IDENTIFICATION LC_MEASUREMENT LC_MESSAGES", env_keep+="LC_MONETARY LC_NAME LC_NUMERIC LC_PAPER LC_TELEPHONE",
    env_keep+="LC_TIME LC_ALL LANGUAGE LINGUAS _XKB_CHARSET XAUTHORITY", secure_path=/sbin\:/bin\:/usr/sbin\:/usr/bin
User bduser may run the following commands on this host:
    (root) /sbin/shutdown -r now
[bduser@bigdata01 ~]$ sudo shutdown -r now
[sudo] password for bduser: 
Broadcast message from root@bigdata01
        (/dev/pts/1) at 0:53 ...
The system is going down for reboot NOW!

在这里插入图片描述

  • grep (condition) (Object, file)
[root@bigdata01 home]# grep 'root' /etc/passwd
root:x:0:0:root:/root:/bin/bash
operator:x:11:0:operator:/root:/sbin/nologin
  • |
  • pass first section to second section
[root@bigdata01 home]#   cat /etc/passwd |  more
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
...
[root@bigdata01 home]#   cat /etc/passwd | grep 'root'
root:x:0:0:root:/root:/bin/bash
operator:x:11:0:operator:/root:/sbin/nologin
[root@bigdata01 home]#   cat /etc/passwd | head -3
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
[root@bigdata01 home]# ifconfig | grep 'inet6 addr'
          inet6 addr: fe80::20c:29ff:fe37:b1c2/64 Scope:Link
          inet6 addr: ::1/128 Scope:Host`在这里插入代码片`
  • put first section data into second section (files)
  • can enter additional data into the same file
[root@bigdata01 home]# ifconfig | grep 'inet6 addr' >> temp.log
[root@bigdata01 home]# ll
total 12
drwx------. 27 bduser bduser 4096 Aug  6 11:03 bduser
drwx------.  4    501    501 4096 Jul 30 23:14 bduser2
-rw-r--r--.  1 root   root    102 Aug  6 21:47 temp.log
[root@bigdata01 home]# cat temp.log
          inet6 addr: fe80::20c:29ff:fe37:b1c2/64 Scope:Link
          inet6 addr: ::1/128 Scope:Host
[root@bigdata01 home]# ifconfig | grep 'inet6 addr' >> temp.log
[root@bigdata01 home]# cat temp.log
          inet6 addr: fe80::20c:29ff:fe37:b1c2/64 Scope:Link
          inet6 addr: ::1/128 Scope:Host
          inet6 addr: fe80::20c:29ff:fe37:b1c2/64 Scope:Link
          inet6 addr: ::1/128 Scope:Host
  • write over existing content from left side to right side file
[root@bigdata01 home]# ifconfig | grep 'inet6 addr' > temp.log 
[root@bigdata01 home]# cat temp.log
          inet6 addr: fe80::20c:29ff:fe37:b1c2/64 Scope:Link
          inet6 addr: ::1/128 Scope:Host
[root@bigdata01 home]# 
  • wc
  • show stat: example lines
[root@bigdata01 home]# wc -l /etc/passwd
34 /etc/passwd
[root@bigdata01 home]# head -3 /etc/passwd | wc -l  
3
  • ps
  • process
  • ps -ef
  • list all process
[root@bigdata01 home]# ps
  PID TTY          TIME CMD
 2595 pts/0    00:00:00 bash
 4697 pts/0    00:00:00 ps
[root@bigdata01 home]# ps -ef
UID        PID  PPID  C STIME TTY          TIME CMD
root         1     0  0 11:02 ?        00:00:01 /sbin/init
root         2     0  0 11:02 ?        00:00:00 [kthreadd]
root         3     2  0 11:02 ?        00:00:00 [migration/0]
root         4     2  0 11:02 ?        00:00:00 [ksoftirqd/0]
...
[root@bigdata01 home]# ps -ef | wc -l
139
  • man
  • manage (help info)
[root@bigdata01 home]# man ls
LS(1)                            User Commands                           LS(1)
...
[root@bigdata01 ~]# man mkdir
MKDIR(1)                         User Commands                        MKDIR(1)

NAME
       mkdir - make directories
...

[root@bigdata01 ~]# man touch
TOUCH(1)                         User Commands                        TOUCH(1)

NAME
       touch - change file timestamps
...
[root@bigdata01 ~]# man rmdir
RMDIR(1)                         User Commands                        RMDIR(1)

NAME
       rmdir - remove empty directories
...
[root@bigdata01 ~]# man /etc/services
...
[root@bigdata01 ~]# man services
SERVICES(5)                Linux Programmer’s Manual               SERVICES(5)
...
  • more
  • space
[root@bigdata01 ~]# more /etc/services
# /etc/services:
# $Id: services,v 1.48 2009/11/11 14:32:31 ovasik Exp $
#
...

在这里插入图片描述

  • gzip
  • does not save original file
  • cannot compress directory
  • bzip2
  • for larger files
  • tar
  • tar -cvf bd100.tar bd100/ #compress
  • tar -xvf bd100.tar -C /opt/ #uncompress
  • -f must be at the end
  • tar -cvzf bd100.tar.gz bd100/ # compress into tar.gz format
  • tar -zxvf bd100.tar.gz -C/opt/rh/ #uncompress tar.gz format
[root@bigdata01 ~]# touch file_bd
[root@bigdata01 ~]# cp /etc/services file_bd
#cp: overwrite `file_bd'? y
[root@bigdata01 ~]# more file_bd
..
[root@bigdata01 ~]# ll
total 732
...
-rw-r--r--. 1 root root 641020 Aug 10 14:55 file_bd
...
[root@bigdata01 ~]# gzip file_bd
[root@bigdata01 ~]# ll
total 232
...
-rw-r--r--. 1 root root 127222 Aug 10 14:55 file_bd.gz
...
[root@bigdata01 ~]# mkdir file_bd
[root@bigdata01 ~]# ll
total 236
...
drwxr-xr-x. 2 root root   4096 Aug 10 14:58 file_bd
[root@bigdata01 ~]# gzip file_bd
gzip: file_bd is a directory -- ignored

[root@bigdata01 ~]# gunzip file_bd.gz
gzip: file_bd already exists; do you wish to overwrite (y or n)? y
gzip: file_bd: Is a directory
[root@bigdata01 ~]# ll
total 236
...
drwxr-xr-x. 2 root root   4096 Aug 10 14:58 file_bd
-rw-r--r--. 1 root root 127222 Aug 10 14:55 file_bd.gz
...
[root@bigdata01 ~]# rm -rf file_bd
[root@bigdata01 ~]# gunzip file_bd.gz
[root@bigdata01 ~]# ll
total 732
...
-rw-r--r--. 1 root root 641020 Aug 10 14:55 file_bd
...
[root@bigdata01 ~]# mkdir bd100
[root@bigdata01 ~]# ll
total 736
...
drwxr-xr-x. 2 root root   4096 Aug 10 15:03 bd100
...
[root@bigdata01 ~]# tar -cvf bd100.tar bd100/     
bd100/
[root@bigdata01 ~]# ll
total 760
...
drwxr-xr-x. 2 root root   4096 Aug 10 15:03 bd100
...
[root@bigdata01 ~]# tar -xvf bd100.tar -C /opt/
bd100/
[root@bigdata01 ~]# ls /opt/
bd100  rh

[root@bigdata01 ~]# cd /opt/
[root@bigdata01 opt]# ll
total 8
drwxr-xr-x. 2 root root 4096 Aug 10 15:03 bd100
drwxr-xr-x. 3 root root 4096 Jul 30 17:34 rh
[root@bigdata01 opt]# tar -cvzf bd100.tar.gz bd100/
bd100/
[root@bigdata01 opt]# ll
total 12
drwxr-xr-x. 2 root root 4096 Aug 10 15:03 bd100
-rw-r--r--. 1 root root  108 Aug 10 15:20 bd100.tar.gz
drwxr-xr-x. 3 root root 4096 Jul 30 17:34 rh
[root@bigdata01 opt]# rm -rf bd100.tar.gz
[root@bigdata01 opt]# ll
total 8
drwxr-xr-x. 2 root root 4096 Aug 10 15:03 bd100
drwxr-xr-x. 3 root root 4096 Jul 30 17:34 rh
[root@bigdata01 opt]# tar -cvf bd100.tar bd100/   
bd100/
[root@bigdata01 opt]# ll
total 20
drwxr-xr-x. 2 root root  4096 Aug 10 15:03 bd100
-rw-r--r--. 1 root root 10240 Aug 10 15:22 bd100.tar
drwxr-xr-x. 3 root root  4096 Jul 30 17:34 rh
[root@bigdata01 opt]# gzip bd100.tar
[root@bigdata01 opt]# ll
total 12
drwxr-xr-x. 2 root root 4096 Aug 10 15:03 bd100
-rw-r--r--. 1 root root  118 Aug 10 15:22 bd100.tar.gz
drwxr-xr-x. 3 root root 4096 Jul 30 17:34 rh
[root@bigdata01 opt]# 
[root@bigdata01 opt]# tar -zxvf bd100.tar.gz -C/opt/rh/
bd100/
[root@bigdata01 opt]# ls rh/
bd100  data  exception.txt

Linux 7: Linux Disk Management

在这里插入图片描述
在这里插入图片描述

在这里插入图片描述

  • df #check for disk space info
  • df -h #check for disk space
  • fdisk -l #check disk info
  • control+r+“Diskmgmt.msc”
  • brw-rw---- #b: block
  • sda #first drive, primary master : sd is for (originally) scsi disk devices, now refer to removable devices in general and SATA devices
  • sda 1/2…partitioned drive : s:socket ; d: disk
  • drive port: sata sas : Server
  • drive port: scsi ide: personal computer
  • SSD : solid state drive
  • cylinders : block info

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          64      512000   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2              64        6528    51915776   8e  Linux LVM
[root@bigdata01 opt]# df
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/mapper/VolGroup-lv_root
                      47098232   3260924  41444836   8% /
tmpfs                  1959072       224   1958848   1% /dev/shm
/dev/sda1               495844     38016    432228   9% /boot
/dev/sr0               4251346   4251346         0 100% /media/CentOS_6.4_Final
[root@bigdata01 opt]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
                       45G  3.2G   40G   8% /
tmpfs                 1.9G  224K  1.9G   1% /dev/shm
/dev/sda1             485M   38M  423M   9% /boot
/dev/sr0              4.1G  4.1G     0 100% /media/CentOS_6.4_Final
[root@bigdata01 opt]# fdisk -l

Disk /dev/sda: 53.7 GB, 53687091200 bytes
255 heads, 63 sectors/track, 6527 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
...
[root@bigdata01 ~]# ls -l /dev
total 0
crw-rw----. 1 root video    10, 175 Aug  6 11:02 agpgart
crw-rw----. 1 root root     10,  57 Aug  6 11:03 autofs
drwxr-xr-x. 2 root root         640 Aug  6 11:02 block
brw-rw----. 1 root disk    253,   0 Aug  6 11:02 dm-0
...
  • Stop workstation before adding disk: init 0
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述

  • fdisk -l

  • fdisk /dev/sdb

  • partition /dev/sdb disk info

  • p primary partition (1-4) # 2+1 or 3+1 primary + extended <=4

  • after primary partition, extend partition, then logical partition. then write to disk

  • w write

  • reboot

[root@bigdata01 ~]# fdisk -l

Disk /dev/sda: 53.7 GB, 53687091200 bytes
255 heads, 63 sectors/track, 6527 cylinders
...

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          64      512000   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2              64        6528    51915776   8e  Linux LVM

Disk /dev/sdb: 107.4 GB, 107374182400 bytes # newly added disk space
255 heads, 63 sectors/track, 13054 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000


[root@bigdata01 ~]# fdisk /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0xc6cf596d.
Changes will remain in memory only, until you decide to write them.
#After that, of course, the previous content won't be recoverable.

#Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

#WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
#         switch off the mode (command 'c') and change display units to
#         sectors (command 'u').

Command (m for help): m
Command action
   a   toggle a bootable flag
   b   edit bsd disklabel
   c   toggle the dos compatibility flag
   d   delete a partition
   l   list known partition types
   m   print this menu
   n   add a new partition
   o   create a new empty DOS partition table
   p   print the partition table
   q   quit without saving changes
   s   create a new empty Sun disklabel
   t   change a partition's system id
   u   change display/entry units
   v   verify the partition table
   w   write table to disk and exit
   x   extra functionality (experts only)
Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-13054, default 1): 
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-13054, default 13054): +15G

Command (m for help): p

Disk /dev/sdb: 107.4 GB, 107374182400 bytes
255 heads, 63 sectors/track, 13054 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xc6cf596d

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1        1959    15735636   83  Linux

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 2
First cylinder (1960-13054, default 1960): 
Using default value 1960
Last cylinder, +cylinders or +size{K,M,G} (1960-13054, default 13054): +15G

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
e
Partition number (1-4): 3
First cylinder (3919-13054, default 3919): 
Using default value 3919
Last cylinder, +cylinders or +size{K,M,G} (3919-13054, default 13054): 
Using default value 13054

Command (m for help): p

Disk /dev/sdb: 107.4 GB, 107374182400 bytes
255 heads, 63 sectors/track, 13054 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xc6cf596d

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1        1959    15735636   83  Linux
/dev/sdb2            1960        3918    15735667+  83  Linux
/dev/sdb3            3919       13054    73384920    5  Extended

Command (m for help): n
Command action
   l   logical (5 or over)
   p   primary partition (1-4)
l
First cylinder (3919-13054, default 3919): 
Using default value 3919
Last cylinder, +cylinders or +size{K,M,G} (3919-13054, default 13054): +20G

Command (m for help): p

Disk /dev/sdb: 107.4 GB, 107374182400 bytes
255 heads, 63 sectors/track, 13054 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xc6cf596d

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1        1959    15735636   83  Linux
/dev/sdb2            1960        3918    15735667+  83  Linux
/dev/sdb3            3919       13054    73384920    5  Extended
/dev/sdb5            3919        6530    20980858+  83  Linux
Command (m for help): n
Command action
   l   logical (5 or over)
   p   primary partition (1-4)
l
First cylinder (3919-13054, default 3919): 
Using default value 3919
Last cylinder, +cylinders or +size{K,M,G} (3919-13054, default 13054): +20G

Command (m for help): p

Disk /dev/sdb: 107.4 GB, 107374182400 bytes
255 heads, 63 sectors/track, 13054 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xc6cf596d

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1        1959    15735636   83  Linux
/dev/sdb2            1960        3918    15735667+  83  Linux
/dev/sdb3            3919       13054    73384920    5  Extended
/dev/sdb5            3919        6530    20980858+  83  Linux
Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
  • tab more info
  • mkfs.ext4 /dev/sdb6 : formatting disk: ext2, ext3, ext4, xfs, etc
[root@bigdata01 ~]# fdisk -l

...
   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1        1959    15735636   83  Linux
/dev/sdb2            1960        3918    15735667+  83  Linux
/dev/sdb3            3919       13054    73384920    5  Extended
/dev/sdb5            3919        6530    20980858+  83  Linux
/dev/sdb6            6531        8489    15735636   83  Linux

[root@bigdata01 ~]# mkfs.ext4 /dev/sdb6
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
983488 inodes, 3933909 blocks
196695 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4030726144
121 block groups
32768 blocks per group, 32768 fragments per group
8128 inodes per group
Superblock backups stored on blocks: 
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208

Writing inode tables: done                            
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 30 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
  • mount disk
  • mount /dev/sdb6/ mnt # temporary
  • df -h
  • df #Display free disk space
  • forever mount
  • vi /etc/fstab #write into file
  • /dev/sdb6 /mnt ext4 defaults 0 0 # add

[root@bigdata01 ~]# ls
anaconda-ks.cfg  bd100.tar  Desktop    Downloads  file_bd      install.log.syslog  Pictures  Public     v
bd100            bd_data    Documents  file       install.log  Music               pro       Templates  Videos
[root@bigdata01 ~]# ls /
bin   dev  file  lib    lost+found  misc  net  proc  sbin     srv  temp  usr
boot  etc  home  lib64  media       mnt   opt  root  selinux  sys  tmp   var
[root@bigdata01 ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
                       45G  3.2G   40G   8% /
tmpfs                 1.9G   80K  1.9G   1% /dev/shm
/dev/sda1             485M   38M  423M   9% /boot
/dev/sr0              4.1G  4.1G     0 100% /media/CentOS_6.4_Final
[root@bigdata01 ~]# mount /dev/sdb6 /mnt
[root@bigdata01 ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
                       45G  3.2G   40G   8% /
tmpfs                 1.9G   80K  1.9G   1% /dev/shm
/dev/sda1             485M   38M  423M   9% /boot
/dev/sr0              4.1G  4.1G     0 100% /media/CentOS_6.4_Final
/dev/sdb6              15G  166M   14G   2% /mnt
[root@bigdata01 ~]# 
[root@bigdata01 ~]# vi /etc/fstab
# /etc/fstab
# Created by anaconda on Fri Jul 23 08:59:17 2021
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/VolGroup-lv_root /                       ext4    defaults        1 1
UUID=430ddcbf-5568-40b8-91fb-916796841850 /boot                   ext4    defaults        1 2
/dev/mapper/VolGroup-lv_swap swap                    swap    defaults        0 0
tmpfs                   /dev/shm                tmpfs   defaults        0 0
devpts                  /dev/pts                devpts  gid=5,mode=620  0 0
sysfs                   /sys                    sysfs   defaults        0 0
proc                    /proc                   proc    defaults        0 0
/dev/sdb6               /mnt                    ext4    defaults        0 0 # add
                                                                                               

在这里插入图片描述

Linux 8: Linux Access

在这里插入图片描述

  • software package
  • package type:
    1. source package (code)
    1. binary package (rpm, system default) parsed, cannot see source code, manageable, install, uninstall, upgrade,
      check, dependent, A>B>C>D…
  • rpm : query: rpm -qa #query all
  • rpm: install: rpm -ivh #install
  • rpm -ivh zlib-devel-1.2.3-29.el6.x86_64.rpm
  • rpm: uninstall: rem -e : --nodeps #not check dependents, test environments
  • rpm -e zlib-devel-1.2.3-29.el6.x86_64
[root@bigdata01 ~]# mount /dev/cdrom /media
[root@bigdata01 ~]#  cd /media/
[root@bigdata01 media]# cd Packages/
[root@bigdata01 Packages]# ll
...
zlib-1.2.3-29.el6.i686.rpm
zlib-1.2.3-29.el6.x86_64.rpm
...
[root@bigdata01 Packages]# ls | wc -l
3956
[root@bigdata01 Packages]# ls kernel-*
kernel-2.6.32-358.el6.x86_64.rpm              kernel-doc-2.6.32-358.el6.noarch.rpm
kernel-debug-2.6.32-358.el6.x86_64.rpm        kernel-firmware-2.6.32-358.el6.noarch.rpm
kernel-debug-devel-2.6.32-358.el6.x86_64.rpm  kernel-headers-2.6.32-358.el6.x86_64.rpm
kernel-devel-2.6.32-358.el6.x86_64.rpm
[root@bigdata01 Packages]# rpm -qa httpd
httpd-2.2.15-26.el6.centos.x86_64
[root@bigdata01 Packages]# rpm -qa | grep  httpd
httpd-tools-2.2.15-26.el6.centos.x86_64
httpd-2.2.15-26.el6.centos.x86_64
[root@bigdata01 Packages]# rpm -qa | grep httpd-devel  
[root@bigdata01 Packages]# rpm -qa | grep zlib         
zlib-1.2.3-29.el6.x86_64
[root@bigdata01 Packages]# rpm -qa | grep zlib-devel
[root@bigdata01 Packages]# rpm -ivh zlib-devel-1.2.3-29.el6.x86_64.rpm
warning: zlib-devel-1.2.3-29.el6.x86_64.rpm: Header V3 RSA/SHA1 Signature, key ID c105b9de: NOKEY
Preparing...                ########################################### [100%]
   1:zlib-devel             ########################################### [100%]
[root@bigdata01 Packages]# rpm -qa | grep zlib-devel                  
zlib-devel-1.2.3-29.el6.x86_64
[root@bigdata01 Packages]# rpm -e zlib-devel-1.2.3-29.el6.x86_64
[root@bigdata01 Packages]# rpm -qa | grep zlib-devel            

在这里插入图片描述

  • yum
  • ERROR: Error: Cannot find a valid baseurl for repo: base
[root@bigdata01 ~]# yum list
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
YumRepo Error: All mirror URLs are not using ftp, http[s] or file.
 Eg. Invalid release/repo/arch combination/
removing mirrorlist with no valid mirrors: /var/cache/yum/x86_64/6/base/mirrorlist.txt
Error: Cannot find a valid baseurl for repo: base
  • install yum
  • check Centos release
[root@bigdata01 yum.repos.d]# lsb_release -a                      
LSB Version:    :base-4.0-amd64:base-4.0-noarch:core-4.0-amd64:core-4.0-noarch:graphics-4.0-amd64:graphics-4.0-noarch:printing-4.0-amd64:printing-4.0-noarch
Distributor ID: CentOS
Description:    CentOS release 6.4 (Final)
Release:        6.4
Codename:       Final
  • enter following

mirror


[root@bigdata01 yum.repos.d]# vim /etc/yum.repos.d/CentOS-Base.repo
[base]
name=CentOS-$releasever - Base
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra
baseurl=https://vault.centos.org/6.4/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6

#released updates
[updates]
name=CentOS-$releasever - Updates
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates&infra=$infra
baseurl=https://vault.centos.org/6.4/updates/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6

#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras&infra=$infra
baseurl=https://vault.centos.org/6.4/extras/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6

#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus&infra=$infr
a
baseurl=https://vault.centos.org/6.4/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6

#contrib - packages by Centos Users
[contrib]
name=CentOS-$releasever - Contrib
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=contrib&infra=$infra
baseurl=https://vault.centos.org/6.4/contrib/$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6

  • yum list
  • yum list | grep httpd-devel
  • yum install
  • yum install httpd-devel.x86_64
  • y for all options
  • remove
  • yum -y remove httpd-devel.x86_64
[root@bigdata01 yum.repos.d]# yum list
[root@bigdata01 yum.repos.d]# yum list | grep httpd-tools
...
httpd-tools.x86_64                      2.2.15-26.el6.centos             @anaconda-CentOS-201303020151.x86_64/6.4
httpd-tools.x86_64                      2.2.15-29.el6.centos             updates
[root@bigdata01 yum.repos.d]# 
[root@bigdata01 yum.repos.d]# yum list | grep httpd-devel
...
httpd-devel.i686                        2.2.15-29.el6.centos             updates
httpd-devel.x86_64                      2.2.15-29.el6.centos             updates
[root@bigdata01 yum.repos.d]# yum install httpd-devel.x86_64
...

Dependency Updated:
  db4.x86_64 0:4.7.25-18.el6_4                    db4-utils.x86_64 0:4.7.25-18.el6_4                   
  httpd.x86_64 0:2.2.15-29.el6.centos             httpd-tools.x86_64 0:2.2.15-29.el6.centos            
  openldap.x86_64 0:2.4.23-32.el6_4.1            

Complete!
[root@bigdata01 yum.repos.d]# yum list | grep httpd-devel   
....
httpd-devel.x86_64                      2.2.15-29.el6.centos             @updates
httpd-devel.i686                        2.2.15-29.el6.centos             updates
[root@bigdata01 ~]# yum -y remove httpd-devel.x86_64
...
Removed:
  httpd-devel.x86_64 0:2.2.15-29.el6.centos                                                                            

Complete!
[root@bigdata01 yum.repos.d]# yum check-update
...
yelp.x86_64                                          2.28.1-17.el6_3                             updates

[root@bigdata01 ~]# cd /etc/yum.repos.d/
[root@bigdata01 yum.repos.d]# ll
total 20
-rw-r--r--. 1 root root 1503 Aug 13 02:44 CentOS-Base.repo
-rw-r--r--. 1 root root 1926 Aug 13 02:43 CentOs-Base.repo.back
-rw-r--r--. 1 root root  638 Feb 25  2013 CentOS-Debuginfo.repo
-rw-r--r--. 1 root root  630 Feb 25  2013 CentOS-Media.repo
-rw-r--r--. 1 root root 3664 Feb 25  2013 CentOS-Vault.repo

[root@bigdata01 yum.repos.d]# more CentOS-Base.repo
[base]
name=CentOS-$releasever - Base
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra
baseurl=https://vault.centos.org/6.4/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
...
  • ERROR: Cannot find a valid baseurl for repo: base
  • redo eth0 static connection
  • vmware > edit> virtual network editor
    加粗样式

在这里插入图片描述

  • vim /etc/sysconfig/network

[root@bigdata01 ~]# vim /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=bigdata01
GATEWAY=192.168.112.2
~                                                                                                                                    
  • vim /etc/sysconfig/network-scripts/ifcfg-eth0
[root@bigdata01 network-scripts]# vim ifcfg-eth0

IPV6INIT=no
DEVICE=eth0
TYPE=Ethernet
UUID=b93b0f0b-8f71-4d5e-aca7-e6c600d08973
ONBOOT=yes
NM_CONTROLLED=yes
#BOOTPROTO=dhcp
BOOTPROTO=static
DEFROUTE=yes
IPADDR=192.168.112.128
NETMASK=255.255.255.0
GATEWAY=192.168.112.2
NM_CONTROLLED=yes
IPV4_FAILURE_FATAL=yes
IPV6INIT=no
HWADDR=00:0C:29:37:B1:C2
PEERDNS=yes
PEERROUTES=yes
LAST_CONNECT=1627038906
DNS1=192.168.112.2
~
~              

  • fin uuid
[root@bigdata01 ~]# sudo blkid
[root@bigdata01 ~]# ls -l /dev/disk/by-uuid
[root@bigdata01 ~]# nmcli con | sed -n '1,2p'
  • restart network
  • restart computer if still cannot ping successfully

Linux 9: Linux System Management

在这里插入图片描述

  • top: refresh every 3 seconds
  • swap: swapping block: similar to virtual machine on windows
  • q : exit
  • free : view internal space
  • -m : mb
[root@bigdata01 ~]# top
top - 17:21:20 up  4:50,  3 users,  load average: 0.00, 0.00, 0.00
Tasks: 153 total,   1 running, 141 sleeping,  11 stopped,   0 zombie
Cpu(s):  0.0%us,  0.0%sy,  0.0%ni,100.0%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st
Mem:   3918144k total,   693408k used,  3224736k free,    35880k buffers
Swap:  4063224k total,        0k used,  4063224k free,   341092k cached
  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND                                                   
... 
[root@bigdata01 yum.repos.d]# ps
  PID TTY          TIME CMD
 2629 pts/1    00:00:00 bash
 2651 pts/1    00:00:00 ping   
 ....
  [root@bigdata01 yum.repos.d]# free
             total       used       free     shared    buffers     cached
Mem:       3918144     714436    3203708          0      37412     359072
  • ps : process view
[root@bigdata01 yum.repos.d]# ps
  PID TTY          TIME CMD
 2629 pts/1    00:00:00 bash
....
 3775 pts/1    00:00:00 ps
  • netstat

  • -t > tcp , 3 handshakes safer

  • -u > udp , fast QQ

  • -l > listen

  • -r > router

  • -n > net: ip or port

  • netstat -an

  • -a >all

  • netstat -rn > same > route -n

[root@bigdata01 yum.repos.d]# netstat
Active Internet connections (w/o servers)
Proto Recv-Q Send-Q Local Address               Foreign Address             State      
...
[root@bigdata01 yum.repos.d]#  netstat -tlun
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address               Foreign Address             State      
...
[root@bigdata01 yum.repos.d]#  netstat -an
...
[root@bigdata01 yum.repos.d]# netstat -rn
Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
192.168.112.0   0.0.0.0         255.255.255.0   U         0 0          0 eth0
0.0.0.0         192.168.112.2   0.0.0.0         UG        0 0          0 eth0
[root@bigdata01 yum.repos.d]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.112.0   0.0.0.0         255.255.255.0   U     1      0        0 eth0
0.0.0.0         192.168.112.2   0.0.0.0         UG    0      0        0 eth0
  • kill -9 pid
[root@bigdata01 yum.repos.d]# kill -l
 1) SIGHUP       2) SIGINT       3) SIGQUIT      4) SIGILL       5) SIGTRAP
 6) SIGABRT      7) SIGBUS       8) SIGFPE       9) SIGKILL     10) SIGUSR1
11) SIGSEGV     12) SIGUSR2     13) SIGPIPE     14) SIGALRM     15) SIGTERM
16) SIGSTKFLT   17) SIGCHLD     18) SIGCONT     19) SIGSTOP     20) SIGTSTP
21) SIGTTIN     22) SIGTTOU     23) SIGURG      24) SIGXCPU     25) SIGXFSZ
26) SIGVTALRM   27) SIGPROF     28) SIGWINCH    29) SIGIO       30) SIGPWR
31) SIGSYS      34) SIGRTMIN    35) SIGRTMIN+1  36) SIGRTMIN+2  37) SIGRTMIN+3
38) SIGRTMIN+4  39) SIGRTMIN+5  40) SIGRTMIN+6  41) SIGRTMIN+7  42) SIGRTMIN+8
43) SIGRTMIN+9  44) SIGRTMIN+10 45) SIGRTMIN+11 46) SIGRTMIN+12 47) SIGRTMIN+13
48) SIGRTMIN+14 49) SIGRTMIN+15 50) SIGRTMAX-14 51) SIGRTMAX-13 52) SIGRTMAX-12
53) SIGRTMAX-11 54) SIGRTMAX-10 55) SIGRTMAX-9  56) SIGRTMAX-8  57) SIGRTMAX-7
58) SIGRTMAX-6  59) SIGRTMAX-5  60) SIGRTMAX-4  61) SIGRTMAX-3  62) SIGRTMAX-2
63) SIGRTMAX-1  64) SIGRTMAX

在这里插入图片描述

Linux 10: Linux RegEx

在这里插入图片描述

[root@bigdata01 ~]# touch aa
[root@bigdata01 ~]# touch aabb
[root@bigdata01 ~]# ls aa
aa
[root@bigdata01 ~]# ls aa**
aa  aabb
[root@bigdata01 ~]# ls aa*
aa  aabb
[root@bigdata01 ~]# ls *aa*
aa  aabb

  • grep
[root@bigdata01 ~]#  cat /etc/passwd | grep 'root'
root:x:0:0:root:/root:/bin/bash
operator:x:11:0:operator:/root:/sbin/nologin
[root@bigdata01 ~]# grep 'root' /etc/passwd
root:x:0:0:root:/root:/bin/bash
operator:x:11:0:operator:/root:/sbin/nologin
[root@bigdata01 ~]# grep 'l' /etc/passwd
bin:x:1:1:bin:/bin:/sbin/nologin
[root@bigdata01 ~]# grep '[0-9]' /etc/passwd
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
...
  • grep ‘[0-9]’ /etc/passwd
  • grep ‘[0-9][0-9][0-9]’ /etc/passwd
  • ‘[a-z]’ ‘[0-9]’ ‘[A-Z]’
  • ^ , $ , *
[A-Z][0-9][0-9]=B02
[root@bigdata01 ~]#  grep '[0-9][0-9][0-9]' /etc/passwd
games:x:12:100:games:/usr/games:/sbin/nologin
...
[root@bigdata01 ~]#  grep ':[0-9][0-9][0-9]' /etc/passwd
games:x:12:100:games:/usr/games:/sbin/nologin
...
[root@bigdata01 ~]# grep '^r.*n$' /etc/passwd
rpc:x:32:32:Rpcbind Daemon:/var/cache/rpcbind:/sbin/nologin
rtkit:x:499:497:RealtimeKit:/proc:/sbin/nologin
rpcuser:x:29:29:RPC Service User:/var/lib/nfs:/sbin/nologin
[root@bigdata01 ~]# ifconfig
eth0      Link encap:Ethernet  HWaddr 00:0C:29:37:B1:C2  
          inet addr:192.169.112.129  Bcast:192.168.112.255  Mask:255.255.255.0
....
[root@bigdata01 ~]# ifconfig | grep 'inet addr:'
          inet addr:192.169.112.129  Bcast:192.168.112.255  Mask:255.255.255.0
          inet addr:127.0.0.1  Mask:255.0.0.0
[root@bigdata01 ~]# ifconfig | grep 'inet addr:'| grep -v '127.0.0.1'
          inet addr:192.169.112.129  Bcast:192.168.112.255  Mask:255.255.255.0
[root@bigdata01 ~]# ifconfig | grep 'inet addr:'| grep -v '127.0.0.1'| sed 's/inet addr://g'
          192.169.112.129  Bcast:192.168.112.255  Mask:255.255.255.0
[root@bigdata01 ~]# ifconfig | grep 'inet addr:'| grep -v '127.0.0.1'| sed 's/inet addr://g'| sed 's/Bcast.*//g'
          192.169.112.129  

Linux 11: shell

在这里插入图片描述

  • shell script>
  • outer script program: ls-: ascii code> shell script parser > kernel & hardware: machine language 10100000…
  • Linux sh bash psh zsh…
  • User Path : user specific path: more .bash_profile
  • Environment Path : system path: more /etc/profile
[root@bigdata01 ~]# ls
aa    anaconda-ks.cfg  bd100.tar  Desktop    Downloads  file_bd      install.log.syslog  Pictures  Public     v
aabb  bd100            bd_data    Documents  file       install.log  Music               pro       Templates  Videos
[root@bigdata01 ~]#  cat /etc/shells
/bin/sh
/bin/bash
/sbin/nologin
/bin/dash
/bin/tcsh
/bin/csh
[root@bigdata01 ~]# more /etc/profile
# /etc/profile

# System wide environment and startup programs, for login setup
# Functions and aliases go in /etc/bashrc
....
[root@bigdata01 ~]# cd /home/
[root@bigdata01 home]# ls
bduser  bduser2  
[root@bigdata01 home]# cd bduser/
[root@bigdata01 bduser]# ls
123.txt  234.txt  bd  Desktop  Documents  Downloads  Music  passwd  Pictures  Public  Templates  Videos
[root@bigdata01 bduser]# ls -a
.        .bash_history  .cache     Downloads  .gnote           .ICEauthority    .nautilus  .pulse-cookie  .xsession-errors
..       .bash_logout   .config    .esd_auth  .gnupg           .imsettings.log  passwd     .ssh           .xsession-errors.old
123.txt  .bash_profile  .dbus      .gconf     .gstreamer-0.10  .local           Pictures   Templates
...
[root@bigdata01 bduser]# more .bash_profile
# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi
...
[root@bigdata01 bduser]# ls -a /root
.                .bash_logout   .config    file     .gstreamer-0.10     .lesshst   Public               .thumbnails
..               .bash_profile  .cshrc     file_bd  .gtk-bookmarks      .local     .pulse               v
...
  • shell example
  • #!/bin/bash
  • declare which type of script used
  • sh l.sh
  • run
[root@bigdata01 bduser]# vi l.sh
#!/bin/bash
echo '1234'
echo 'abc'
echo '!!!' 
[root@bigdata01 bduser]# sh l.sh 
1234
abc
!!!     
[root@bigdata01 bduser]# vi l.sh
#!/bin/bash
echo $0 # l.sh 
echo $1 # tom
echo $2    # jack
[root@bigdata01 bduser]# sh l.sh tom
l.sh
tom          
[root@bigdata01 bduser]# sh l.sh tom jack
l.sh
tom
jack    
[root@bigdata01 bduser]# vi l.sh
#!/bin/bash
echo $*
[root@bigdata01 bduser]# sh l.sh tom jack
tom jack
[root@bigdata01 bduser]# vi l.sh
#!/bin/bash
echo $*
echo $@
[root@bigdata01 bduser]# sh l.sh tom jack
tom jack
tom jack
  • echo
[root@bigdata01 bduser]# echo '88'
88
  • name=[value]
  • no space, case sensitive
[root@bigdata01 bduser]# a=2
[root@bigdata01 bduser]# echo $a
2

在这里插入图片描述

  • && || ;
[root@bigdata01 bduser]# cat /etc/passwd && mkdir /home/bduser/hdfs
root:x:0:0:root:/root:/bin/bash
...
bduser:x:500:500::/home/bduser:/bin/bash
[root@bigdata01 hdfs]# cd /home/bduser/
[root@bigdata01 bduser]# ls
123.txt  234.txt  bd  Desktop  Documents  Downloads  hdfs  l.sh  Music  passwd  Pictures  Public  Templates  Videos
[root@bigdata01 bduser]# cat /etc/passwd ||  mkdir /home/bduser/hadoop
root:x:0:0:root:/root:/bin/bash
...
bduser:x:500:500::/home/bduser:/bin/bash
[root@bigdata01 bduser]# ls
123.txt  234.txt  bd  Desktop  Documents  Downloads  hdfs  l.sh  Music  passwd  Pictures  Public  Templates  Videos
[root@bigdata01 bduser]# cat /etc/passwwwwd ||  mkdir /home/bduser/hadoop
cat: /etc/passwwwwd: No such file or directory
[root@bigdata01 bduser]# ls
123.txt  234.txt  bd  Desktop  Documents  Downloads  hadoop  hdfs  l.sh  Music  passwd  Pictures  Public  Templates  Videos
[root@bigdata01 bduser]# cat /etc/passwwwwd ;  mkdir /home/bduser/spark
cat: /etc/passwwwwd: No such file or directory
[root@bigdata01 bduser]# ls
123.txt  bd       Documents  hadoop  l.sh   passwd    Public  Templates
234.txt  Desktop  Downloads  hdfs    Music  Pictures  spark   Videos
  • calculations
[root@bigdata01 ~]# a=2
[root@bigdata01 ~]# b=3
[root@bigdata01 ~]# echo $[a+b]
5
[root@bigdata01 ~]# echo $[$a+$b]
5
[root@bigdata01 ~]# echo [$a+$b] 
[2+3]
[root@bigdata01 ~]# echo $(($a+$b))
5
[root@bigdata01 ~]# expr 5+3
5+3
[root@bigdata01 ~]# expr 5 + 3
8
[root@bigdata01 ~]# expr a + b
expr: non-numeric argument
[root@bigdata01 ~]# expr $a + $b
5
[root@bigdata01 ~]# a='I am'
[root@bigdata01 ~]# echo $a
I am
[root@bigdata01 ~]# echo a 
a
[root@bigdata01 ~]# echo $?
0
[root@bigdata01 ~]# ls /etccc
ls: cannot access /etccc: No such file or directory
[root@bigdata01 ~]# echo $?
2
  • more /etc/init.d/nfs
[root@bigdata01 ~]# more /etc/init.d/nfs
#!/bin/sh
#

在这里插入图片描述

  • for
  • rm -rf ./*
[root@bigdata01 ~]# vi l.sh
#!/bin/bash

for i in tom tony leo
do
        echo $i
done    
                                                                                                                           
"l.sh" [New] 6L, 53C written
[root@bigdata01 ~]# sh l.sh
tom
tony
leo
[root@bigdata01 ~]# vi l.sh

#!/bin/bash

for i in tom tony leo
do
        echo $i
        echo $i"123"
done    
                                                                                                                          
"l.sh" 7L, 67C written
[root@bigdata01 ~]# sh l.sh
tom
tom123
tony
tony123
leo
leo123
[root@bigdata01 data_test]# vi for.sh

#!/bin/bash
for i in {1..50}
do
        mkdir /root/data_test/dir$i
done
                                                                                                                           
"for.sh" 5L, 66C written
[root@bigdata01 data_test]# sh for.sh
[root@bigdata01 data_test]# ls
dir1   dir12  dir15  dir18  dir20  dir23  dir26  dir29  dir31  dir34  dir37  dir4   dir42  dir45  dir48  dir50  dir8
dir10  dir13  dir16  dir19  dir21  dir24  dir27  dir3   dir32  dir35  dir38  dir40  dir43  dir46  dir49  dir6   dir9
dir11  dir14  dir17  dir2   dir22  dir25  dir28  dir30  dir33  dir36  dir39  dir41  dir44  dir47  dir5   dir7   for.sh
[root@bigdata01 data_test]# rm -rf ./*
[root@bigdata01 data_test]# ll
total 0
[root@bigdata01 data_test]# vi for.sh

#!/bin/bash
for i in  {1..10}
do
echo $i
done
                                                                                                                            
"for.sh" [New] 5L, 46C written
[root@bigdata01 data_test]# sh for.sh
1
2
3
4
5
6
7
8
9
10
[root@bigdata01 data_test]# vi for.sh

#!/bin/bash
for ((i=1;i<=10;i++))
do
SUM=$((SUM+i))
done
echo $SUM
                                                                                                                           
"for.sh" 6L, 67C written
[root@bigdata01 data_test]# sh for.sh
55

在这里插入图片描述

  • while
  • while read -r line
[root@bigdata01 ~]# vi while.sh
#!/bin/bash
i=1
while [[ $i -le 10 ]]
do
SUM=$((SUM+i))
echo $i
i=$((i+1))
done
echo $SUM
                                                                                                                        
"while.sh" 9L, 90C written
[root@bigdata01 ~]# sh while.sh
1
2
3
4
5
6
7
8
9
10
55

[root@bigdata01 ~]# vi while2.sh

#!/bin/bash
while read -r line
do 
echo $line
done < /etc/passwd
                                                                                                                         
"while2.sh" [New] 5L, 65C written
[root@bigdata01 ~]# sh while2.sh
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
...
[root@bigdata01 ~]# vi while2.sh

#!/bin/bash
while read -r line
do
echo $line:hello
done < /etc/passwd                                                                                                                          
~                                                                                                                              
"while2.sh" 5L, 71C written
[root@bigdata01 ~]# sh while2.sh
root:x:0:0:root:/root:/bin/bash:hello
...

在这里插入图片描述

  • if
[root@bigdata01 ~]# vi if.sh

if [ 2 -eq 2 ];then
#!/bin/bash
if [ 2 -eq 2 ]
then
echo YES
fi
if [ 2 -eq 2 ];then
echo YES
fi                                                                                                                            
"if.sh" 8L, 76C written
[root@bigdata01 ~]# sh if.sh
YES
YES

[root@bigdata01 ~]# vi if2.sh

#!/bin/bash
if [ -d /root ];then
ls /root
fi
                                                                                                                        
"if2.sh" 5L, 46C written
[root@bigdata01 ~]# sh if2.sh
aa               bd100      data_test  Downloads  if2.sh       install.log.syslog  Pictures  Templates  v.sh
aabb             bd100.tar  Desktop    file       if.sh        l.sh                pro       v          while2.sh
...

在这里插入图片描述

  • case
[root@bigdata01 ~]# vi case.sh

#!/bin/bash
case $1 in
top)
        top
        ;;
free)
        free
        ;;
df)
        df
        ;;
*)
        echo "usage:$0{top|free|df}"
esac
~                                                                                                                              
                                                                                                                            
"case.sh" 14L, 104C written
[root@bigdata01 ~]# sh case.sh
usage:case.sh{top|free|df}
[root@bigdata01 ~]# sh case.sh top

top - 08:01:53 up 7 days,  9:31,  2 users,  load average: 0.00, 0.00, 0.00
Tasks: 149 total,   1 running, 140 sleeping,   8 stopped,   0 zombie
Cpu(s):  0.0%us,  0.0%sy,  0.0%ni,100.0%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st
Mem:   3918144k total,   994340k used,  2923804k free,   145880k buffers
Swap:  4063224k total,        0k used,  4063224k free,   488692k cached
 Unknown command - try 'h' for help 
  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND                                                           
 2480 bduser    20   0  226m 2032 1684 S  0.3  0.1   1:37.81 gvfs-afc-volume                                                   
    1 root      20   0 19356 1544 1224 S  0.0  0.0   0:02.85 init                                                                                                                
...                                                       

[9]+  Stopped                 sh case.sh top
[root@bigdata01 ~]# sh case.sh free
             total       used       free     shared    buffers     cached
Mem:       3918144     994736    2923408          0     145880     488692
...
[root@bigdata01 ~]# sh case.sh df
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/mapper/VolGroup-lv_root
                      47098232   3431548  41274212   8% /
...

Linux 12: Linux Time

在这里插入图片描述

  • date
[root@bigdata01 ~]# date
Sun Aug 22 08:03:42 CST 2021
[root@bigdata01 ~]# date -s "2020-02-02 12:12:12"
Sun Feb  2 12:12:12 CST 2020
[root@bigdata01 ~]# date "+%Y%m%d"
20200202
[root@bigdata01 ~]# date
Sun Feb  2 12:13:08 CST 2020
[root@bigdata01 ~]# date "+%y%m%d"
200202
[root@bigdata01 ~]# date -d '7 day ago' "+%Y%m%d%H%M"
202001261214

在这里插入图片描述

  • at
[root@bigdata01 ~]# date -s "2020-02-02 12:12:12"
Sun Feb  2 12:12:12 CST 2020
[root@bigdata01 ~]# at 12:00
at> cp/etc/passwd/tmp        
at> <EOT><EOT>
job 4 at 2020-02-03 12:00
[root@bigdata01 ~]# ls /tmp
gnome-system-monitor.root.2178013162  orbit-gdm
keyring-7jrRhH                        pulse-1NyexxttT0QQ
...

在这里插入图片描述

  • crontab
  • #service crond status
  • #service crond start
  • #service crond stop
  • #service crond restart
  • admin logged in
  • chkconfig crond on
  • chkconfig crond off
[root@bigdata01 ~]# service crond status
crond (pid  1943) is running...
[root@bigdata01 ~]# chkconfig
NetworkManager  0:off   1:off   2:on    3:on    4:on    5:on    6:off
...
crond           0:off   1:off   2:on    3:on    4:on    5:on    6:off
...

在这里插入图片描述

  • min - hour - date - month -weekday -command
  • 0 - 2 - - -1 - cp/etc/passwd/tmp
  • executed every monday at 2 am
  • 5 - 1 -10,25
  • executed every 10th, 25tth at 5 am 1min
  • */10
  • executed every 10 min
  • 0 -1-6
  • executed every morning from 1-6
  • 5
  • 5 min every hour
[root@bigdata01 ~]# service crond status
crond (pid  1943) is running...
[root@bigdata01 ~]# crontab -e

*/1 * * * * date >> /root/time.log
                                                                                           
"/tmp/crontab.jN9bzT" 1L, 35C written
crontab: installing new crontab
[root@bigdata01 ~]# service crond restart
Stopping crond:                                            [  OK  ]
Starting crond:                                            [  OK  ]
[root@bigdata01 ~]# crontab -l
*/1 * * * * date >> /root/time.log
[root@bigdata01 ~]# ls
aa               bd100.tar  Desktop    file_bd      install.log.syslog  pro        v          while.sh
aabb             bd_data    Documents  if2.sh       l.sh                Public     Videos
anaconda-ks.cfg  case.sh    Downloads  if.sh        Music               Templates  v.sh
bd100            data_test  file       install.log  Pictures            time.log   while2.sh
[root@bigdata01 ~]# tail -f time.log
Mon Aug 23 16:16:01 CST 2021

Reference

  • shell commands
######
 	& 	#Start a new process in the background
  	alias 	#Create an alias •
  	apropos 	#Search Help manual pages (man -k)
  	apt 	#Search for and install software packages (Debian/Ubuntu)
  	apt-get 	#Search for and install software packages (Debian/Ubuntu)
  	aptitude 	#Search for and install software packages (Debian/Ubuntu)
  	aspell 	#Spell Checker
  	at 	#Schedule a command to run once at a particular time
  	awk 	#Find and Replace text, database sort/validate/index
######
  	basename 	#Strip directory and suffix from filenames
  	base32 	#Base32 encode/decode data and print to standard output
  	base64 	#Base64 encode/decode data and print to standard output
  	bash 	#GNU Bourne-Again SHell
  	bc 	#Arbitrary precision calculator language
  	bg 	#Send to background
  	bind 	#Set or display readline key and function bindings •
  	break 	#Exit from a loop •
  	builtin 	#Run a shell builtin
  	bzip2 	#Compress or decompress named file(s)
######
  	cal 	#Display a calendar
  	caller 	#Return the context of any active subroutine call •
  	case 	#Conditionally perform a command
  	cat 	#Concatenate and print (display) the content of files
  	cd 	#Change Directory
  	cfdisk 	#Partition table manipulator for Linux
  	chattr 	#Change file attributes on a Linux file system
  	chgrp 	#Change group ownership
  	chmod 	#Change access permissions
  	chown 	#Change file owner and group
  	chpasswd 	#Update passwords in batch mode
  	chroot 	#Run a command with a different root directory
  	chkconfig 	#System services (runlevel)
  	cksum 	#Print CRC checksum and byte counts
  	clear 	#Clear terminal screen
  	cmp 	#Compare two files
  	comm 	#Compare two sorted files line by line
  	command 	#Run a command - ignoring shell functions •
  	continue 	#Resume the next iteration of a loop •
  	cp 	#Copy one or more files to another location
  	cpio 	#Copy files to and from archives
  	cron 	#Daemon to execute scheduled commands
  	crontab 	#Schedule a command to run at a later time
  	csplit 	#Split a file into context-determined pieces
  	curl 	#Transfer data from or to a server
  	cut 	#Divide a file into several parts
######
  	date 	#Display or change the date & time
  	dc 	#Desk Calculator
  	dd 	#Data Duplicator - convert and copy a file, write disk headers, boot records
  	ddrescue 	#Data recovery tool
  	declare 	#Declare variables and give them attributes •
  	df 	#Display free disk space
  	diff 	#Display the differences between two files
  	diff3 	#Show differences among three files
  	dig 	#DNS lookup
  	dir 	#Briefly list directory contents
  	dircolors 	#Colour setup for 'ls'
  	dirname 	#Convert a full pathname to just a path
  	dirs 	#Display list of remembered directories
  	dos2unix 	#Windows/MAC to UNIX text file format converter
  	dmesg 	#Print kernel & driver messages
  	dpkg 	#Package manager (Debian/Ubuntu).
  	du 	#Estimate file space usage
######
  	echo 	#Display message on screen •
  	egrep 	#Search file(s) for lines that match an extended expression
  	eject 	#Eject removable media
  	enable 	#Enable and disable builtin shell commands •
  	env 	#Environment variables
  	ethtool 	#Ethernet card settings
  	eval 	#Evaluate several commands/arguments
  	exec 	#Execute a command
  	exit 	#Exit the shell
  	expect 	#Automate arbitrary applications accessed over a terminal
  	expand 	#Convert tabs to spaces
  	export 	#Set an environment variable
  	expr 	#Evaluate expressions
######
  	false 	#Do nothing, unsuccessfully
  	fdformat 	#Low-level format a floppy disk
  	fdisk 	#Partition table manipulator for Linux
  	fg 	#Send job to foreground
  	fgrep 	#Search file(s) for lines that match a fixed string
  	file 	#Determine file type
  	find 	#Search for files that meet a desired criteria
  	fmt 	#Reformat paragraph text
  	fold 	#Wrap text to fit a specified width
  	for 	#Expand words, and execute commands
  	format 	#Format disks or tapes
  	free 	#Display memory usage
  	fsck 	#File system consistency check and repair
  	ftp 	#File Transfer Protocol
  	function 	#Define Function Macros
  	fuser 	#Identify/kill the process that is accessing a file
######
  	gawk 	#Find and Replace text within file(s)
  	getopts 	#Parse positional parameters
  	grep 	#Search file(s) for lines that match a given pattern
  	groupadd 	#Add a user security group
  	groupdel 	#Delete a group
  	groupmod 	#Modify a group
  	groups 	#Print group names a user is in
  	gzip 	#Compress or decompress named file(s)
######
  	hash 	#Remember the full pathname of a name argument
  	head 	#Output the first part of file(s)
  	help 	#Display help for a built-in command •
  	history 	#Command History
  	hostname 	#Print or set system name
  	htop 	#Interactive process viewer
######
  	iconv 	#Convert the character set of a file
  	id 	#Print user and group id's
  	if 	#Conditionally perform a command
  	ifconfig 	#Configure a network interface
  	ifdown 	#Stop a network interface
  	ifup 	#Start a network interface up
  	import 	#Capture an X server screen and save the image to file
  	install 	#Copy files and set attributes
  	iostat 	#Report CPU and i/o statistics
  	ip 	#Routing, devices and tunnels
######
  	jobs 	#List active jobs •
  	join 	#Join lines on a common field
######
  	kill 	#Kill a process by specifying its PID
  	killall 	#Kill processes by name
######
  	less 	#Display output one screen at a time
  	let 	#Perform arithmetic on shell variables •
  	link 	#Create a link to a file
  	ln 	#Create a symbolic link to a file
  	local 	#Create a function variable •
  	locate 	#Find files
  	logname 	#Print current login name
  	logout 	#Exit a login shell •
  	look 	#Display lines beginning with a given string
  	lpc 	#Line printer control program
  	lpr 	#Off line print
  	lprint 	#Print a file
  	lprintd 	#Delete a print job
  	lprintq 	#List the print queue
  	lprm 	#Remove jobs from the print queue
  	lsattr 	#List file attributes on a Linux second extended file system
  	lsblk 	#List block devices
  	ls 	#List information about file(s)
  	lsof 	#List open files
  	lspci 	#List all PCI devices
######
  	make 	#Recompile a group of programs
  	man 	#Help manual
  	mapfile 	#Read lines from standard input into an indexed array variable •
  	mkdir 	#Create new folder(s)
  	mkfifo 	#Make FIFOs (named pipes)
  	mkfile 	#Make a file
  	mkisofs 	#Create a hybrid ISO9660/JOLIET/HFS filesystem
  	mknod 	#Make block or character special files
  	mktemp 	#Make a temporary file
  	more 	#Display output one screen at a time
  	most 	#Browse or page through a text file
  	mount 	#Mount a file system
  	mtools 	#Manipulate MS-DOS files
  	mtr 	#Network diagnostics (traceroute/ping)
  	mv 	#Move or rename files or directories
  	mmv 	#Mass Move and rename (files)
######
  	nc 	#Netcat, read and write data across networks
  	netstat 	#Networking connections/stats
  	nft 	#nftables for packet filtering and classification
  	nice 	#Set the priority of a command or job
  	nl 	#Number lines and write files
  	nohup 	#Run a command immune to hangups
  	notify-send 	#Send desktop notifications
  	nslookup 	#Query Internet name servers interactively
######
  	open 	#Open a file in its default application
  	op 	#Operator access
######
  	passwd 	#Modify a user password
  	paste 	#Merge lines of files
  	pathchk 	#Check file name portability
  	Perf 	#Performance analysis tools for Linux
  	ping 	#Test a network connection
  	pgrep 	#List processes by name
  	pkill 	#Kill processes by name
  	popd 	#Restore the previous value of the current directory
  	pr 	#Prepare files for printing
  	printcap 	#Printer capability database
  	printenv 	#Print environment variables
  	printf 	#Format and print data •
  	ps 	#Process status
  	pushd 	#Save and then change the current directory
  	pv 	#Monitor the progress of data through a pipe
  	pwd 	#Print Working Directory
######
  	quota 	#Display disk usage and limits
  	quotacheck 	#Scan a file system for disk usage
######
  	ram 	#ram disk device
  	rar 	#Archive files with compression
  	rcp 	#Copy files between two machines
  	read 	#Read a line from standard input •
  	readarray 	#Read from stdin into an array variable •
  	readonly 	#Mark variables/functions as readonly
  	reboot 	#Reboot the system
  	rename 	#Rename files
  	renice 	#Alter priority of running processes
  	remsync 	#Synchronize remote files via email
  	return 	#Exit a shell function
  	rev 	#Reverse lines of a file
  	rm 	#Remove files
  	rmdir 	#Remove folder(s)
  	rsync 	#Remote file copy (Synchronize file trees)
######
  	screen 	#Multiplex terminal, run remote shells via ssh
  	scp 	#Secure copy (remote file copy)
  	sdiff 	#Merge two files interactively
  	sed 	#Stream Editor
  	select 	#Accept user choices via keyboard input
  	seq 	#Print numeric sequences
  	set 	#Manipulate shell variables and functions
  	sftp 	#Secure File Transfer Program
  	shift 	#Shift positional parameters
  	shopt 	#Shell Options
  	shuf 	#Generate random permutations
  	shutdown 	#Shutdown or restart linux
  	sleep 	#Delay for a specified time
  	slocate 	#Find files
  	sort 	#Sort text files
  	source 	#Run commands from a file '.'  •
  	split 	#Split a file into fixed-size pieces
  	ss 	#Socket Statistics
  	ssh 	#Secure Shell client (remote login program)
  	stat 	#Display file or file system status
  	strace 	#Trace system calls and signals
  	su 	#Substitute user identity
  	sudo 	#Execute a command as another user
  	sum 	#Print a checksum for a file
  	suspend 	#Suspend execution of this shell •
  	sync 	#Synchronize data on disk with memory
######
  	tail 	#Output the last part of a file
  	tar 	#Store, list or extract files in an archive
  	tee 	#Redirect output to multiple files
  	test 	#Evaluate a conditional expression
  	time 	#Measure Program running time
  	timeout 	#Run a command with a time limit
  	times 	#User and system times
  	tmux 	#Terminal multiplexer
  	touch 	#Change file timestamps
  	top 	#List processes running on the system
  	tput 	#Set terminal-dependent capabilities, color, position
  	traceroute 	#Trace Route to Host
  	trap 	#Execute a command when the shell receives a signal •
  	tr 	#Translate, squeeze, and/or delete characters
  	true 	#Do nothing, successfully
  	tsort 	#Topological sort
  	tty 	#Print filename of terminal on stdin
  	type 	#Describe a command •
######
  	ulimit 	#Limit user resources •
  	umask 	#Users file creation mask
  	umount 	#Unmount a device
  	unalias 	#Remove an alias •
  	uname 	#Print system information
  	unexpand 	#Convert spaces to tabs
  	uniq 	#Uniquify files
  	units 	#Convert units from one scale to another
  	unix2dos 	#UNIX to Windows or MAC text file format converter
  	unrar 	#Extract files from a rar archive
  	unset 	#Remove variable or function names
  	unshar 	#Unpack shell archive scripts
  	until 	#Execute commands (until error)
  	uptime 	#Show uptime
  	useradd 	#Create new user account
  	userdel 	#Delete a user account
  	usermod 	#Modify user account
  	users 	#List users currently logged in
  	uuencode 	#Encode a binary file
  	uudecode 	#Decode a file created by uuencode
######
  	v 	#Verbosely list directory contents ('ls -l -b')
  	vdir 	#Verbosely list directory contents ('ls -l -b')
  	vi 	#Text Editor
  	vmstat 	#Report virtual memory statistics
######
  	w 	#Show who is logged on and what they are doing
  	wait 	#Wait for a process to complete •
  	watch 	#Execute/display a program periodically
  	wc 	#Print byte, word, and line counts
  	whereis 	#Search the user's $path, man pages and source files for a program
  	which 	#Search the user's $path for a program file
  	while 	#Execute commands
  	who 	#Print all usernames currently logged in
  	whoami 	#Print the current user id and name ('id -un')
  	wget 	#Retrieve web pages or files via HTTP, HTTPS or FTP
  	write 	#Send a message to another user
######
  	xargs 	#Execute utility, passing constructed argument list(s)
  	xdg-open 	#Open a file or URL in the user's preferred application.
  	xz 	#Compress or decompress .xz and .lzma files
  	yes 	#Print a string until interrupted
  	zip 	#Package and compress (archive) files
  	. 	#Run a command script in the current shell
  	!! 	#Run the last command again
  	### 	Comment / Remark
  • CTRL-c : Stop current command

  • CTRL-z : Sleep program

  • CTRL-a : Go to start of line

  • CTRL-e : Go to end of line

  • CTRL-u : Cut from start of line

  • CTRL-k : Cut to end of line

  • CTRL-r : Search history

  • !! : Repeat last command

  • !abc : Run last command starting with abc

  • !abc:p : Print last command starting with abc

  • !$ : Last argument of previous command

  • ALT-. : Last argument of previous command

  • !* : All arguments of previous command

  • ^ abc^ 123 : Run previous command, replacing abcwith 123

  • Vim Cheat Sheet

  • Global

    :h[elp] keyword - open help for keyword
    :sav[eas] file - save file as
    :clo[se] - close current pane
    :ter[minal] - open a terminal window
    K - open man page for word under the cursor

Tip Run vimtutor in a terminal to learn the first Vim commands.
Cursor movement

    h - move cursor left
    j - move cursor down
    k - move cursor up
    l - move cursor right
    H - move to top of screen
    M - move to middle of screen
    L - move to bottom of screen
    w - jump forwards to the start of a word
    W - jump forwards to the start of a word (words can contain punctuation)
    e - jump forwards to the end of a word
    E - jump forwards to the end of a word (words can contain punctuation)
    b - jump backwards to the start of a word
    B - jump backwards to the start of a word (words can contain punctuation)
    ge - jump backwards to the end of a word
    gE - jump backwards to the end of a word (words can contain punctuation)
    % - move to matching character (default supported pairs: '()', '{}', '[]' - use :h matchpairs in vim for more info)
    0 - jump to the start of the line
    ^ - jump to the first non-blank character of the line
    $ - jump to the end of the line
    g_ - jump to the last non-blank character of the line
    gg - go to the first line of the document
    G - go to the last line of the document
    5gg or 5G - go to line 5
    gd - move to local declaration
    gD - move to global declaration
    fx - jump to next occurrence of character x
    tx - jump to before next occurrence of character x
    Fx - jump to previous occurence of character x
    Tx - jump to after previous occurence of character x
    ; - repeat previous f, t, F or T movement
    , - repeat previous f, t, F or T movement, backwards
    } - jump to next paragraph (or function/block, when editing code)
    { - jump to previous paragraph (or function/block, when editing code)
    zz - center cursor on screen
    Ctrl + e - move screen down one line (without moving cursor)
    Ctrl + y - move screen up one line (without moving cursor)
    Ctrl + b - move back one full screen
    Ctrl + f - move forward one full screen
    Ctrl + d - move forward 1/2 a screen
    Ctrl + u - move back 1/2 a screen
  • Tip Prefix a cursor movement command with a number to repeat it. For example, 4j moves down 4 lines.
  • Insert mode - inserting/appending text
    i - insert before the cursor
    I - insert at the beginning of the line
    a - insert (append) after the cursor
    A - insert (append) at the end of the line
    o - append (open) a new line below the current line
    O - append (open) a new line above the current line
    ea - insert (append) at the end of the word
    Ctrl + h - delete the character before the cursor during insert mode
    Ctrl + w - delete word before the cursor during insert mode
    Ctrl + j - begin new line during insert mode
    Ctrl + t - indent (move right) line one shiftwidth during insert mode
    Ctrl + d - de-indent (move left) line one shiftwidth during insert mode
    Ctrl + n - insert (auto-complete) next match before the cursor during insert mode
    Ctrl + p - insert (auto-complete) previous match before the cursor during insert mode
    Ctrl + rx - insert the contents of register x
    Ctrl + ox - Temporarily enter normal mode to issue one normal-mode command x.
    Esc - exit insert mode
  • Editing
    r - replace a single character.
    R - replace more than one character, until ESC is pressed.
    J - join line below to the current one with one space in between
    gJ - join line below to the current one without space in between
    gwip - reflow paragraph
    g~ - switch case up to motion
    gu - change to lowercase up to motion
    gU - change to uppercase up to motion
    cc - change (replace) entire line
    C - change (replace) to the end of the line
    c$ - change (replace) to the end of the line
    ciw - change (replace) entire word
    cw or ce - change (replace) to the end of the word
    s - delete character and substitute text
    S - delete line and substitute text (same as cc)
    xp - transpose two letters (delete and paste)
    u - undo
    U - restore (undo) last changed line
    Ctrl + r - redo
    . - repeat last command
  • Marking text (visual mode)
    v - start visual mode, mark lines, then do a command (like y-yank)
    V - start linewise visual mode
    o - move to other end of marked area
    Ctrl + v - start visual block mode
    O - move to other corner of block
    aw - mark a word
    ab - a block with ()
    aB - a block with {}
    at - a block with <> tags
    ib - inner block with ()
    iB - inner block with {}
    it - inner block with <> tags
    Esc - exit visual mode
  • Tip Instead of b or B one can also use ( or { respectively.
  • Visual commands
    > - shift text right
    < - shift text left
    y - yank (copy) marked text
    d - delete marked text
    ~ - switch case
    u - change marked text to lowercase
    U - change marked text to uppercase
  • Registers
:reg[isters] - show registers content
"xy - yank into register x
"xp - paste contents of register x
"+y - yank into the system clipboard register
"+p - paste from the system clipboard register
  • Tip Registers are being stored in ~/.viminfo, and will be loaded again on next restart of vim.
  • Tip Special registers:

 0 - last yank
 " - unnamed register, last delete or yank
 % - current file name
 # - alternate file name
 * - clipboard contents (X11 primary)
 + - clipboard contents (X11 clipboard)
 / - last search pattern
 : - last command-line
 . - last inserted text
 - - last small (less than a line) delete
 = - expression register
 _ - black hole register
  • Marks and positions
:marks - list of marks
ma - set current position for mark A
`a - jump to position of mark A
y`a - yank text to position of mark A
`0 - go to the position where Vim was previously exited
`" - go to the position when last editing this file
`. - go to the position of the last change in this file
`` - go to the position before the last jump
:ju[mps] - list of jumps
Ctrl + i - go to newer position in jump list
Ctrl + o - go to older position in jump list
:changes - list of changes
g, - go to newer position in change list
g; - go to older position in change list
Ctrl + ] - jump to the tag under cursor
  • Tip To jump to a mark you can either use a backtick (`) or an apostrophe (’). Using an apostrophe jumps to the beginning (first non-blank) of the line holding the mark.
  • Macros
qa - record macro a
q - stop recording macro
@a - run macro a
@@ - rerun last run macro
  • Cut and paste
yy - yank (copy) a line
2yy - yank (copy) 2 lines
yw - yank (copy) the characters of the word from the cursor position to the start of the next word
yiw - yank (copy) word under the cursor
yaw - yank (copy) word under the cursor and the space after or before it
y$ - yank (copy) to end of line
p - put (paste) the clipboard after cursor
P - put (paste) before cursor
dd - delete (cut) a line
2dd - delete (cut) 2 lines
dw - delete (cut) the characters of the word from the cursor position to the start of the next word
diw - delete (cut) word under the cursor
daw - delete (cut) word under the cursor and the space after or before it
D - delete (cut) to the end of the line
d$ - delete (cut) to the end of the line
x - delete (cut) character
  • Indent text
>> - indent (move right) line one shiftwidth
<< - de-indent (move left) line one shiftwidth
>% - indent a block with () or {} (cursor on brace)
>ib - indent inner block with ()
>at - indent a block with <> tags
3== - re-indent 3 lines
=% - re-indent a block with () or {} (cursor on brace)
=iB - re-indent inner block with {}
gg=G - re-indent entire buffer
]p - paste and adjust indent to current line
  • Exiting
:w - write (save) the file, but don't exit
:w !sudo tee % - write out the current file using sudo
:wq or :x or ZZ - write (save) and quit
:q - quit (fails if there are unsaved changes)
:q! or ZQ - quit and throw away unsaved changes
:wqa - write (save) and quit on all tabs
  • Search and replace
/pattern - search for pattern
?pattern - search backward for pattern
\vpattern - 'very magic' pattern: non-alphanumeric characters are interpreted as special regex symbols (no escaping needed)
n - repeat search in same direction
N - repeat search in opposite direction
:%s/old/new/g - replace all old with new throughout file
:%s/old/new/gc - replace all old with new throughout file with confirmations
:noh[lsearch] - remove highlighting of search matches
  • Search in multiple files
:vim[grep] /pattern/ {`{file}`} - search for pattern in multiple files
  • e.g. :vim[grep] /foo/ */
:cn[ext] - jump to the next match
:cp[revious] - jump to the previous match
:cope[n] - open a window containing the list of matches
:ccl[ose] - close the quickfix window
  • Tabs
:tabnew or :tabnew {page.words.file} - open a file in a new tab
Ctrl + wT - move the current split window into its own tab
gt or :tabn[ext] - move to the next tab
gT or :tabp[revious] - move to the previous tab
#gt - move to tab number #
:tabm[ove] # - move current tab to the #th position (indexed from 0)
:tabc[lose] - close the current tab and all its windows
:tabo[nly] - close all tabs except for the current one
:tabdo command - run the command on all tabs (e.g. :tabdo q - closes all opened tabs)
  • Working with multiple files
:e[dit] file - edit a file in a new buffer
:bn[ext] - go to the next buffer
:bp[revious] - go to the previous buffer
:bd[elete] - delete a buffer (close a file)
:b[uffer]# - go to a buffer by index #
:b[uffer] file - go to a buffer by file
:ls or :buffers - list all open buffers
:sp[lit] file - open a file in a new buffer and split window
:vs[plit] file - open a file in a new buffer and vertically split window
:vert[ical] ba[ll] - edit all buffers as vertical windows
:tab ba[ll] - edit all buffers as tabs
Ctrl + ws - split window
Ctrl + wv - split window vertically
Ctrl + ww - switch windows
Ctrl + wq - quit a window
Ctrl + wx - exchange current window with next one
Ctrl + w= - make all windows equal height & width
Ctrl + wh - move cursor to the left window (vertical split)
Ctrl + wl - move cursor to the right window (vertical split)
Ctrl + wj - move cursor to the window below (horizontal split)
Ctrl + wk - move cursor to the window above (horizontal split)
  • Diff
zf - manually define a fold up to motion
zd - delete fold under the cursor
za - toggle fold under the cursor
zo - open fold under the cursor
zc - close fold under the cursor
zr - reduce (open) all folds by one level
zm - fold more (close) all folds by one level
zi - toggle folding functionality
]c - jump to start of next change
[c - jump to start of previous change
do or :diffg[et] - obtain (get) difference (from other buffer)
dp or :diffpu[t] - put difference (to other buffer)
:diffthis - make current window part of diff
:dif[fupdate] - update differences
:diffo[ff] - switch off diff mode for current window
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值