Linux基礎

linux發展史
unix  誕生(貝爾實驗室)

minix 譚寧邦教授(主要用於教學)

stallman 斯托曼,
 
    公司:自由軟件基金會  FSF(Free Software Foundation)
    項目 : GNU(一個項目,自由、開源替代unix)         GUN's NOT UNIX
    守則:GPL            
        1、自由傳播
        2、任意修改,但必須發出來,通用公共許可  
  開源了不少優秀的軟件,可是缺乏linux內核

 託瓦茲 
      91 開發出了linux內核。node

32位與64位的區別:python

當初設計時的定位不一樣
安裝要求配置不一樣
運算速度不一樣
尋址能力不一樣

buffer與cache:linux

寫入數據到內存裏,這個數據的內存空間稱爲緩衝區(buffer),寫入到內存buffer緩衝區,寫緩衝。
從內存讀取數據,這個存數據的內存空間稱爲緩存區(cache),從內存cache讀取緩存區,讀緩存。

 linux系統的啓動過程ios

1、按下電源
2、BIOS自檢    出現logo
3、MBR系統引導            
4、GRUB菜單(選擇不一樣的內核,或者進入救援模式)
5、加載內核
6、啓動int進程
7、從/etc/inittab 初始化系統(設置主機名,設置ip)
8、執行/etc/re.d/re/sysinit腳本 根據運行級別不一樣,運行對應的文件(開機自啓動軟件) /etc/rc0.d/* /etc/rc6.d/* 九、執行/etc/re.d/re腳本 十、啓動mingetty進程 顯示登陸界面

 

開機自檢
從硬盤的MBR中讀取引導程序GRUB
引導程序根據配置文件顯示引導菜單
若是選擇進入linux系統,此時引導程序加載Linux內核文件
當內核所有加載完畢後,GRUB的任務完成,此時所有控制權交給Linux,cpu開始執行Linux內核代碼,初始化任務調度,分配內存、加載驅動等。簡而言之,此步驟將創建一個內核運行環境
內核代碼執行完畢後,開始執行Linux系統的第一個進程-systemd,進程號爲1
systemd進程啓動後將讀取/etc/systemd/system/default.target,這個文件的做用是設置系統的運行級別。systemd會根據此文件設置系統的運行級別並啓動相應的服務
服務啓動完成後,將引導login彈出登陸界面

 

查看系統信息
[root@VM_0_15_centos ~]# cat /etc/redhat-release 
CentOS Linux release 7.2.1511 (Core) 
[root@VM_0_15_centos ~]# uname -a
Linux VM_0_15_centos 3.10.0-514.26.2.el7.x86_64 #1 SMP Tue Jul 4 15:04:05 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
[root@VM_0_15_centos ~]# cat /etc/os-release 
NAME="CentOS Linux"
VERSION="7 (Core)"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="7"
PRETTY_NAME="CentOS Linux 7 (Core)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:7"
HOME_URL="https://www.centos.org/"
BUG_REPORT_URL="https://bugs.centos.org/"

CENTOS_MANTISBT_PROJECT="CentOS-7"
CENTOS_MANTISBT_PROJECT_VERSION="7"
REDHAT_SUPPORT_PRODUCT="centos"
REDHAT_SUPPORT_PRODUCT_VERSION="7"

  

 linux符號
''                    所見即所得,吃啥吐啥
""                    特殊符號會被解析運行
``                    ===$()先運行裏面的命令,把結果留下來
>                    重定向符號,先清空文件的內容,而後追加文件的最後
>>                    重定向符號  追加文件的最後

2>                    錯誤重定向符號,先清空文件的內容,而後追加文件的最後
2>>                    錯誤重定向符號  追加文件的最後
        
~                    當前用戶的老家
!                    強制取反;查找並運行歷史命令
                        例子:!awk:包含awk的命令,最後一條並運行
                        history | grep awk
#                    註釋;root用戶的變量提示符

$                    去除變量的內容;普通用戶的命令提示符

*                    全部任何東西
\                    轉義字符
&&                    前一個命令執行成功而後在執行後一個命令
||                    前一個命令支持失敗後再執行後面的命令
 查詢幫助的方法
  • man  fstab 
  • man hosts
  • man 命令
  • 命令 --help 簡潔
  • help  linux內置命令

 

Linux基本命令

 

 

-n 取消輸出每行結尾的回車
-e 讓echo命令支持 \n \t 轉義字符


   \\     反斜槓 
   \b     backspace
   \c     produce no further output
   \e     escape
   \f     form feed
   \n     new line
   \r     carriage return
   \t     horizontal tab
   \v     vertical tab
   \0NNN  byte with octal value NNN (1 to 3 digits)
   \xHH   byte with hexadecimal value HH (1 to 2 digits)


echo   *********   >> ./123.txt   2 >> ./123.txt
echo   *********   >> ./123.txt   2>&1  
echo 把echo後面的文字顯示出來

 

mkdir        #建立文件夾
touch        #建立文件,要寫後綴
[root@ace ~]# xargs -n2 <./123.txt # 分組
xargs
[root@ace data]# head -n1 123.txt                # 取文件的前幾行,默認10
head
[root@ace data]# tail -2 123.txt                    # 取文件後幾行,默認10
tail -f  與tailf是同樣的
tail
cp  /data  /temp
或者/bin/sh  /data  /temp
爲何會出現提示? 默認有 -i參數
Why?
    1、防止運行危險命令
    2、簡化命令,別名
cp
[root@ace data]# alias                # 查看全部別名
alias cp='cp -i'
alias l.='ls -d .* --color=auto'
alias ll='ls -l --color=auto'
alias ls='ls --color=auto'
alias mv='mv -i'
alias rm='rm -i'
alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'


如何臨時設置別名
 [root@ace data]# alias cp
alias cp='cp -i'
[root@ace data]# alias cp='echo 1 2 3 4 5 6'
[root@ace data]# alias cp
alias cp='echo 1 2 3 4 5 6'
[root@ace data]# cp /root /temp
1 2 3 4 5 6 /root /temp
[root@ace data]# alias cp='cp -i'


如何永久修改
編輯/etc/profile,在最下邊一行
添加 alias cp='echo 1 2 3 4 5 6'
[root@ace data]# source /etc/profile  使它生效
[root@ace data]# vim /root/.bashrc    還要修改這裏
alias
移動光標到文件的最後一行        G
移動光標到文件的  第一行        gg
在當前行之下插入一個空行,並進入編輯模式    o(小寫字母)
刪除當前光標所在行後面的內容                D
vim
[root@ace data]#useradd   oldbody                    # 添加用戶                            
[root@ace data]#id oldbody
uid=500(oldbody) gid=500(oldbody) groups=500(oldbody)
[root@ace data]#passwd oldbody                        # 設置密碼
Changing password for user oldbody.
New password: 
BAD PASSWORD: it is too simplistic/systematic
BAD PASSWORD: is too simple
Retype new password: 
passwd: all authentication tokens updated successfully.
 
useradd
[root@ace data]# tree -Ld 1
tree
[root@ace data]# find /root/ -type f -name "oldboy.txt" 
[root@ace data]# find /root/ -type f -name "*.txt" 
[root@ace data]# tree -Ld 1
[root@ace data]# find  -maxdepth 1 -type d -mtime +7 -size +1M ! -name "."
find
tar  options   打包(壓縮)到哪裏   源文件位置(建議相對位置)

z----壓縮工具----gzip
c----建立-------create
v----顯示壓縮/解壓過程
f----file------指定壓縮包的名字
t----list------查看壓縮包裏的內容
x-----extract-----解壓


###建立壓縮包
tar zcf /tmp/etc.tar.gz /etc/
###查看壓縮包
tar tf /tmp/etc.tar.gz
#解壓
tar xf /tmp/etc.tar.gz

[root@ace /]# tar zcf /tmp/etc-pai.tar.gz  etc/  --exclude=services   ###排除全部文件名叫services的文件
--exclude-from=/tmp/paichu.txt,建立的時候使用


-C /opt    指定解壓到opt目錄下





 
tar
如何查看/etc/services文件的有多少行
[root@ace oldboy]# wc -l /etc/services
10774 /etc/services
wc
[root@ace oldboy]# ps -ef |grep "/sshd"  | wc -l
root       1509      1  0 17:51 ?           00:00:00 /usr/sbin/sshd
root       1669   1509  0 17:51 ?         00:00:00 sshd: root@pts/0
root       1795   1509  0 18:17 ?         00:00:00 sshd: root@pts/1
root       1813   1671  0 18:17 pts/0    00:00:00 grep sshd
ps
ln   -s   oldboy.txt oldboy.txt-soft

ln   oldboy.txt oldboy.txt-hard
ln
 1)    如何建立:
    a)默認不帶參數狀況下,ln命令建立的是硬連接,帶-s參數的ln命令建立的是軟連接。
 2) 含義:
    a)硬連接文件與源文件的inode節點號相同,而軟連接文件至關於windows下面的快捷方式(inode節點號與源文件不一樣)
 3)    特色:
    a)不能對目錄建立硬連接,但能夠建立軟連接,對目錄的軟連接會常常被用到
    b)軟連接能夠跨文件系統,硬連接不能夠跨文件系統。

 4)    怎麼沒的(源文件,軟連接,硬連接與刪除)
   a)除軟連接文件,對源文件及硬連接文件無任何影響;
   b)除文件的硬連接文件,對源文件及軟連接文件無任何影響;
   c)除連接文件的源文件,對硬連接文件無影響,會致使其軟連接失效(紅底白字閃爍狀);
   d)時刪除源文件及其硬連接文件,整個文件纔會被"真正"的刪除。
軟硬區別
[root@oldboyedu43-lnb oldboy]# ls -l |grep "^d"   
[root@oldboyedu43-lnb oldboy]# ls -l |awk '$2>1'
total 32
drwxr-xr-x  3 root root 4096 Dec 15 00:26 ext
drwxr-xr-x. 2 root root 4096 Dec 11 21:22 test
drwxr-xr-x  2 root root 4096 Dec 15 00:26 xiaodong
drwxr-xr-x  2 root root 4096 Dec 15 00:26 xiaofan
drwxr-xr-x  2 root root 4096 Dec 15 00:26 xingfujie
 
[root@oldboyedu43-lnb oldboy]# ls -F|grep "/"          #-F 給目錄加上’/‘尾巴


ls -lrt

-r  逆序顯示內容
-t  按照文件的修改時間

[root@oldboyedu43-lnb etc]# ls -l --time-style=long-iso
total 1636
drwxr-xr-x.  3 root root   4096 2017-12-08 12:38 abrt
drwxr-xr-x.  4 root root   4096 2017-12-08 12:41 acpi
-rw-r--r--.  1 root root     46 2017-12-12 07:18 adjtime
-rw-r--r--.  1 root root   1512 2010-01-12 21:28 aliases
-rw-r--r--.  1 root root  12288 2017-12-08 12:49 aliases.db
 
 
ace@ace-virtual-machine:/$ ls -ld /etc/    
drwxr-xr-x 134 root root 12288 1月   8 09:57 /etc/
ls
ace@ace-virtual-machine:~$ cat --help
用法:cat [選項]... [文件]...
Concatenate FILE(s) to standard output.

若是沒有指定文件,或者文件爲"-",則從標準輸入讀取。

  -A, --show-all           equivalent to -vET
  -b, --number-nonblank    number nonempty output lines, overrides -n
  -e                       equivalent to -vE
  -E, --show-ends          display $ at end of each line
  -n, --number             number all output lines
  -s, --squeeze-blank      suppress repeated empty output lines
  -t                       與-vT 等價
  -T, --show-tabs          將跳格字符顯示爲^I
  -u                       (被忽略)
  -v, --show-nonprinting   使用^ 和M- 引用,除了LFD和 TAB 以外
      --help        顯示此幫助信息並退出
      --version        顯示版本信息並退出
cat
[root@ace data]# awk  '/zhangsan/'  123.txt        # 匹配zhangsan
[root@ace data]# awk    '!/zhangsan/'  123.txt        # 不匹配zhangsan
[root@ace data]# awk  'NR==20'      123.txt          # 顯示第20行
[root@ace data]# awk  'NR==20,NR==30'    123.txt      # 顯示第20到第30行

[root@ace oldboy]# awk -F "[, ]"  '{print $3,"原封不動的輸出"$6}' oldboy.txt
        -F "[, ]" 表示以逗號或者空格做爲菜刀 分隔符

ifconfig eth0|awk 'NR==2{print $2}'


ifconfig eth0|awk -F "[: ]+"  'NR==2{print $4}'
awk
[root@ace data]# sed  '/zhangsan/d'  123.txt        # 匹配到的zhangsan刪除

[root@ace data]# sed  '/^$/d'  123.txt        # 匹配到的空行刪除


[root@ace data]# sed -n '20p' 123.txt                # 顯示第20行,-n關閉默認輸出
[root@ace data]# sed -n '20,30p' 123.txt             # 顯示第20到第30行
[root@ace data]# sed -n '20,$p' 123.txt              # 顯示第20到最後一行
[root@ace data]# sed  's#須要替換的內容#替換成什麼#g'     123.sh            # 默認不會修改源文件
[root@ace data]# sed  -i   's#須要替換的內容#替換成什麼#g'     123.sh             # 修改源文件

echo 123456|sed -r 's#(.*)#<\1#g'    # 後向引用是擴展正則的功能

# 如下兩種寫法一致
[root@ace data]# ifconfig eth0|sed -n '2p'|sed 's#inet#oldboy#g'
[root@ace data]# ifconfig eth0|sed -n '2s#inet#oldboy#gp'

ace@ace-virtual-machine:~$ sed -n '/zhangsan/p' 123.txt 
zhangsan 
sed
[root@ace data]# grep "zhangsan"  123.txt        # 匹配zhangsan
[root@ace data]# grep -v  "zhangsan"  123.txt        # 不匹配zhangsan
[root@ace data]# grep  -A10 「2X0」 123.txt          # 找到內容爲2X0的一行,同時顯示接下來的10行        -B 之上-C上下

egrep === grep -E 支持高級正則

egrep "3306|1521" /etc/services


--color=auto
grep
Usage: date [OPTION]... [+FORMAT]
  or:  date [-u|--utc|--universal] [MMDDhhmm[[CC]YY][.ss]]
Display the current time in the given FORMAT, or set the system date.

  -d, --date=STRING         display time described by STRING, not `now'
        date -d '+1day'        # 一天以前(year,month,day,hour,min,sec)
  -f, --file=DATEFILE       like --date once for each line of DATEFILE
  -r, --reference=FILE      display the last modification time of FILE
  -R, --rfc-2822            output date and time in RFC 2822 format.
                            Example: Mon, 07 Aug 2006 12:34:56 -0600
      --rfc-3339=TIMESPEC   output date and time in RFC 3339 format.
                            TIMESPEC=`date', `seconds', or `ns' for
                            date and time to the indicated precision.
                            Date and time components are separated by
                            a single space: 2006-08-07 12:34:56-06:00
  -s, --set=STRING          set time described by STRING
        date -s '+1hour'    # 將時間調後一小時
  -u, --utc, --universal    print or set Coordinated Universal Time
      --help     display this help and exit
      --version  output version information and exit

FORMAT controls the output.  Interpreted sequences are:

  %%   a literal %
  %a   locale's abbreviated weekday name (e.g., Sun)
  %A   locale's full weekday name (e.g., Sunday)
  %b   locale's abbreviated month name (e.g., Jan)
  %B   locale's full month name (e.g., January)
  %c   locale's date and time (e.g., Thu Mar  3 23:05:25 2005)
  %C   century; like %Y, except omit last two digits (e.g., 20)
  %d   day of month (e.g, 01)
  %D   date; same as %m/%d/%y
  %e   day of month, space padded; same as %_d
  %F   full date; same as %Y-%m-%d
  %g   last two digits of year of ISO week number (see %G)
  %G   year of ISO week number (see %V); normally useful only with %V
  %h   same as %b
  %H   hour (00..23)
  %I   hour (01..12)
  %j   day of year (001..366)
  %k   hour ( 0..23)
  %l   hour ( 1..12)
  %m   month (01..12)
  %M   minute (00..59)
  %n   a newline
  %N   nanoseconds (000000000..999999999)
  %p   locale's equivalent of either AM or PM; blank if not known
  %P   like %p, but lower case
  %r   locale's 12-hour clock time (e.g., 11:11:04 PM)
  %R   24-hour hour and minute; same as %H:%M
  %s   seconds since 1970-01-01 00:00:00 UTC
  %S   second (00..60)
  %t   a tab
  %T   time; same as %H:%M:%S
  %u   day of week (1..7); 1 is Monday
  %U   week number of year, with Sunday as first day of week (00..53)
  %V   ISO week number, with Monday as first day of week (01..53)
  %w   day of week (0..6); 0 is Sunday
  %W   week number of year, with Monday as first day of week (00..53)
  %x   locale's date representation (e.g., 12/31/99)
  %X   locale's time representation (e.g., 23:13:48)
  %y   last two digits of year (00..99)
  %Y   year
  %z   +hhmm numeric timezone (e.g., -0400)
  %:z  +hh:mm numeric timezone (e.g., -04:00)
  %::z  +hh:mm:ss numeric time zone (e.g., -04:00:00)
  %:::z  numeric time zone with : to necessary precision (e.g., -04, +05:30)
  %Z   alphabetic time zone abbreviation (e.g., EDT)
自動修改系統時間
pool.ntp.org
ntpl.aliyun.com
ntpdate
[root@ace /]# ntpdate pool.ntp.org
8 Jan 14:43:37 ntpdate[2198]: step time server 85.199.214.101 offset 1.834547 sec
date
[root@ace ~]# which --help
Usage: /usr/bin/which [options] [--] COMMAND [...]
Write the full path of COMMAND(s) to standard output.

  --version, -[vV] Print version and exit successfully.
  --help,          Print this help and exit successfully.
  --skip-dot       Skip directories in PATH that start with a dot.
  --skip-tilde     Skip directories in PATH that start with a tilde.
  --show-dot       Don't expand a dot to current directory in output.
  --show-tilde     Output a tilde for HOME directory for non-root.
  --tty-only       Stop processing options on the right if not on tty.
  --all, -a        Print all matches in PATH, not just the first
  --read-alias, -i Read list of aliases from stdin.
  --skip-alias     Ignore option --read-alias; don't read stdin.
  --read-functions Read shell functions from stdin.
  --skip-functions Ignore option --read-functions; don't read stdin.

Recommended use is to write the output of (alias; declare -f) to standard
input, so that which can show aliases and shell functions. See which(1) for
examples.

If the options --read-alias and/or --read-functions are specified then the
output can be a full alias or function definition, optionally followed by
the full path of each command used inside of those.
which 查找命令的絕對路徑,在PATH下找
[root@ace ~]# whereis awk
awk: /bin/awk /usr/bin/awk /usr/libexec/awk /usr/share/awk /usr/share/man/man1p/awk.1p.gz /usr/share/man/man1/awk.1.gz



能夠經過參數,只顯示特定內容
whereis 找出與這個命令相關的
根據名字,查找文件的路徑


文件名字與文件路徑對應有一個表格,  模糊查詢。
新建了文件後,使用updatedb 來更新這張表
locate
[root@ace ~]# w
 14:07:24 up 31 min,  2 users,  load average: 0.00, 0.00, 0.00
USER     TTY      FROM              LOGIN@   IDLE   JCPU   PCPU WHAT
root     tty1     -                14:05    1:33   0.00s  0.00s -bash
root     pts/0    10.0.0.1         13:35    0.00s  0.02s  0.00s w
w
[root@ace ~]# last
root     tty1                          Wed Jan  9 14:05   still logged in   
root     pts/0        10.0.0.1         Wed Jan  9 13:35   still logged in   
reboot   system boot  2.6.32-754.el6.x Wed Jan  9 13:35 - 14:07  (00:32)    
root     pts/0        10.0.0.1         Tue Jan  8 08:53 - crash (1+04:42)   
reboot   system boot  2.6.32-754.el6.x Tue Jan  8 08:47 - 14:07 (1+05:20)   
root     pts/0        10.0.0.1         Mon Jan  7 02:56 - 03:46  (00:50)    
root     pts/0        10.0.0.1         Sun Jan  6 22:53 - 01:34  (02:40)    
root     pts/0        10.0.0.1         Sun Jan  6 17:58 - 22:46  (04:48)    
root     pts/0        10.0.0.1         Sun Jan  6 16:56 - 17:56  (01:00)    
reboot   system boot  2.6.32-754.el6.x Sun Jan  6 16:55 - 14:07 (2+21:12)   
root     pts/0        10.0.0.1         Sat Jan  5 21:24 - 22:05  (00:41)    
root     pts/5        10.0.0.1         Sat Jan  5 20:10 - 20:11  (00:00)    
root     pts/4        10.0.0.1         Sat Jan  5 20:10 - 20:18  (00:07)
last 全部登陸信息
[root@ace ~]# lastlog
Username         Port     From             Latest
root             tty1                      Wed Jan  9 14:05:51 +0800 2019
bin                                        **Never logged in**
daemon                                     **Never logged in**
adm                                        **Never logged in**
lp                                         **Never logged in**
sync                                       **Never logged in**
shutdown                                   **Never logged in**
halt                                       **Never logged in**
mail                                       **Never logged in**
uucp                                       **Never logged in**
operator                                   **Never logged in**
games                                      **Never logged in**
gopher                                     **Never logged in**
ftp                                        **Never logged in**
nobody                                     **Never logged in**
dbus                                       **Never logged in**
vcsa                                       **Never logged in**
abrt                                       **Never logged in**
haldaemon                                  **Never logged in**
ntp                                        **Never logged in**
saslauth                                   **Never logged in**
postfix                                    **Never logged in**
sshd                                       **Never logged in**
tcpdump                                    **Never logged in**
oldbody                                    **Never logged in**
lastlog 系統中全部用戶的最近一次的登陸信息
chmod u+x oldboy.txt
chmod u-x oldboy.txt
chmod u=x oldboy.txt
chmod u=rwx oldboy.txt


chmod +x oldboy.txt === chmod ugo+x oldboy.txt  === chmod a+x oldboy.txt 



主人    家人     陌生人
use    group   other
chmod
chown       用戶。用戶組         文件
chown
chmod  chown  
都有-R  參數   遞歸

慎用

 

echo 123 | tr '0-9' 'a-h'
將0-9替換爲a-h
cut -c 2-11 
截取第2-11個字符

 

[root@ace ~]# seq 10
2
4
6
8
10

[root@ace ~]# seq -w 10
02
04
06
08
10

seq
seq

 

chpasswd   name:password

# 更改用戶密碼,格式有要求
# 能夠批量修改
# chpasswd <123.log

 

mount 
查看掛載狀態
iostat -dk  1 5
iostat -dk  1  /dev/sda
查看磁盤io
dd if=dev/zero  of=/data/bigfile

ctrl+c
顯示寫速度
 
 

 

 

 

[root@liushuo ~]# vmstat 1 5
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st
 2  0  86744 146884 109104 1222692    0    0    23    20    4    1  4  1 94  1  0
 0  0  86744 146744 109108 1222700    0    0    12     0  176  356  0  0 99  1  0
 0  0  86744 146620 109112 1222732    0    0    28     0  187  334  2  1 96  1  0
 0  0  86744 147800 109116 1222732    0    0    12     0  189  373  1  0 99  0  0
 0  0  86744 147816 109120 1222740    0    0    12     0  171  340  0  0 99  1  0

 

[root@liushuo ~]# dstat
You did not select any stats, using -cdngy by default.
----total-cpu-usage---- -dsk/total- -net/total- ---paging-- ---system--
usr sys idl wai hiq siq| read  writ| recv  send|  in   out | int   csw 
  4   1  94   1   0   0|  23k   20k|   0     0 |   0    11B| 265   488 
  2   1  97   0   0   0|  16k    0 | 559B 1733B|   0     0 | 193   487 
  0   1  98   1   0   0|  12k    0 | 518B 1079B|   0     0 | 160   315 
  0   0  98   2   0   0|  16k   96k| 560B 1531B|   0     0 | 187   399 
  1   0  99   0   0   0|  12k    0 |  96B  408B|   0     0 | 160   316 
  0   1  98   1   0   0|  12k    0 | 471B  640B|   0     0 | 173   329

 

 

 1.vi編輯器具備三種工做模式?
命令模式    編輯模式    底線命令模式
 

3.在 Linux系統中,壓縮文件後生成後綴爲.gz文件的解壓命令是?
gzip -rv filename  #壓縮文件爲filename.gz
gzip -d filename.gz  #解壓縮文件去掉.gz後綴
 

5.在 Linux系統中,壓縮文件後生成後綴爲.xz文件的解壓命令是?
xz -d #解壓縮
xz -z  #壓縮
 

 

groupadd   建立用戶組
  -g 指定gid 數字          默認用戶建立時,與uid一致

 

 

 

查看磁盤空間的佔用狀況

a    全部文件系統的磁盤使用狀況,包括0塊的文件系統        
k    以k字節爲單位顯示
i     顯示i節點信息,而不是磁盤塊
t     顯示各指定的文件系統的磁盤空間的使用狀況    
x    列出不是某一指定類型的文件系統的磁盤空間的使用狀況
h    以更直觀的方式顯示磁盤空間
T    顯示文件系統類型
df
du 查看文件或目錄所佔用的空間
a    顯示所有目錄或目錄下的每一個文件所佔用的磁盤空間
b    大小用bytes來表示
c    最後在加上總計
h    以直觀的方式顯示大小
--max-depth=N    只打印層級大小等於指定數值的文件夾的大小
s    只顯示個文件大小的總和
x    只計算屬於同於文件系統的文件
L    計算全部的文件大小
du

 

 

wget
--spider  模擬爬蟲
-q    安靜訪問,
-o /dev/null 不輸出
-T --timeout 超時時間
-t    --tries 重試次數

 

curl
-I    只看響應頭
-s    安靜的
-o    /dev/null  不輸出
-w   %{http_code}  返回狀態碼,man查看具體參數
-m  數據傳輸最長時間
 
curl -I -s -w "%{http_code}\n" -o /dev/null  www.baiud.com

 

cut
-c    截取字符串的子串 按位置; such as :2-11

 

zip  oldbody.txt.zip   oldboy.txt
壓縮文件

 

 

init 0
poweroff            # 拔電源
halt                # 手動關電源





[root@ace ~]# shutdown --help
Usage: shutdown [OPTION]... TIME [MESSAGE]
Bring the system down.

Options:
  -r                          reboot after shutdown
  -h                          halt or power off after shutdown
  -H                          halt after shutdown (implies -h)
  -P                          power off after shutdown (implies -h)
  -c                          cancel a running shutdown
  -k                          only send warnings, don't shutdown
  -q, --quiet                 reduce output to errors only
  -v, --verbose               increase output to include informational messages
      --help                  display this help and exit
      --version               output version information and exit

時間可能有不一樣的格式,最多見的只是簡單的單詞「如今」,它會帶來系統當即降低。其餘有效的格式是+m,其中m是等待的分鐘數直到關機,hh:mm,指定24小時時鐘上的時間。

默認狀況下,系統會進入維護(單用戶)模式,您可使用如下方式進行更改-r或-h選項,分別指定從新啓動或系統中止。h選項可使用-H或-P進行進一步修改,以指定是中止系統仍是關閉系統以後。默認值由關閉腳本決定。
關機
init 6
reboot
shutdown -r 1
shutdown -r now
重啓

 

tracroute/tracert命令

 

 

顯示主機的端口與服務網絡鏈接狀態,ESTABLISHED表示創建鏈接的狀態,數量即表示網絡鏈接數
netstat(ss-centos7)
顯示主機的端口與服務網絡鏈接狀態。
lsof

 

 

grep   sed  awk  均可以過濾,grep 效率最高

sed    查找、修改、替換文件

awk    找文件的行的操做

 

suid  setuid   
做用:運行某一個命令的時候至關於這個命令的全部者(root)
-rwsr-xr-x(4755)
設置方法:chmod  u+s /bin/rm  或者chmod  4755 /bin/rm
危險:全部用戶運行命令的時候都至關因而root
passwd命令
4就是suid sticky粘滯位 drwxrwxrwt(
1777) /tmp目錄 1、任何人均可以在這個目錄裏建立目錄(原來權限是777) 2、每一個人智能管理本身的文件,其餘處理不了 sgid locate 做用:運行某一個命令的時候至關於這個命令的家人(root)
 數學計算
[root@VM_0_15_centos ~]# echo   '2*3' |bc
6
[root@VM_0_15_centos ~]# awk 'BEGIN{print 1/3}'
0.333333
[root@VM_0_15_centos ~]# echo   '1/3' |bc
0
[root@VM_0_15_centos ~]# 

 

 linux的一些語法

 

echo {01..50}                 
echo {a..f}
echo stu{a..f}
顯示行號
:set nu   #顯示行號
:set nonu #取消顯示行號
 
[root@ace ~]# grep -n "." nginx.conf 
[root@ace ~]# sed '=' nginx.conf |xargs -n2 
[root@ace ~]# awk '{print NR}' nginx.conf 
[root@ace ~]# awk '{print NR,$0}' nginx.conf 
[root@ace ~]# nl nginx.conf

 

將一些特殊的文件複製到指定目錄
方法1 find+$() 
  cp   $(find /app/logs/ -type f -name "*.log")  /tmp/a/
  find /app/logs/ -type f -name "*.log" -exec cp {} /tmp/b/  \;
  find /app/logs/ -type f -name "*.log" |xargs cp -t /tmp/c
for  time in  {01..20};do  date -s "201705$time"; touch access_www_$(date +%F).log ;done
如今須要從文件中過濾出「oldboy」和「31333741」字符串,請給出命令.
 
[root@ace oldboy]# sed 's#I am ##g' oldboy.txt |sed 's#,myqq is##g'
[root@ace oldboy]# sed 's#,# #g' oldboy.txt |awk '{print $3,$6}'
[root@ace oldboy]# tr "," " " <oldboy.txt |awk '{print $3,$6}'
[root@ace oldboy]# awk -F "[, ]"  '{print $3,"原封不動的輸出"$6}' oldboy.txt
        -F "[, ]" 表示以逗號或者空格做爲菜刀 分隔符 

 

cd - 至關於cd  $OLDPWD
回到上一次cd以前

[root@ace sysconfig]# echo $OLDPWD
/etc/sysconfig

 

 

find /oldboy -type f -name "*.txt"|xargs sed 's#www.etiantian.org#www.oldboyedu.com#g'
sed 's#www.etiantian.org#www.oldboyedu.com#g'  $(find /oldboy -type f -name "*.txt")
sed 's#www.etiantian.org#www.oldboyedu.com#g'  `(find /oldboy -type f -name "*.txt"`
find /oldboy -type f -name "*.txt"  -exec ls -l  {}  \;

 
 
 &&       前邊執行對了,後邊在執行
 ;        先後沒有什麼區別
 

 

 linux環境變量
使用env查看全部變量

PS1 [\u@\h \W]\$ [root@ace data]#
PS1='[\u@\h \W \t]\$' # 修改默認樣式

 

修改PATH環境變量
##臨時
[root@ace ~]# echo $PATH
/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
[root@@ace ~]# export PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin 
[root@@ace ~]# echo $PATH
/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin 

##永久
把環境變量的配置命令追加到/etc/profile中
export PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
source /etc/profile 

 


PATH的做用:
  一、環境變量
  二、存放的命令的位置、目錄

執行一個命令的過程
一、系統會出PATH裏面的位置查找命令 是否存在
二、存在就執行
三、不存在就報錯,command not found

 

 

 linux文件屬性 

 

文件全部者的權限,文件所屬組的權限 和其餘用戶對文件的權限
     文件                    目錄 
r    讀取文件的內容           查看目錄的內容(須要x權限) 
w    修改文件的內容(須要r)    在目錄下面建立 刪除文件(須要x權限)
x    執行文件(須要r)          進入到目錄的權限(cd)

刪除一個文件,須要看是否對該目錄是否有wx權限

 

1.網站是經過傀儡用戶運行的www
2.網站用戶上傳目錄,file 644 dir 755 www www 
3.除了上傳目錄以外 file 644 dir 755 root root

 

根據umask計算出系統默認的權限規則
1.對於目錄 777直接減去umask
2.對於文件 666減去umask的值,若是umask某一位上面是奇數,減完umask以後奇數位須要+1
# umask 032 能夠直接更改 臨時 永久 /etc/profile

 

文件系統屬性(文件屬性)
經常使用的   #a=====append 只能追加
         #i=====immutable 不可更改
  

[root@online01 ~]# lsattr oldboy.txt 
-------------e- oldboy.txt
[root@online01 ~]# chattr +a oldboy.txt             
[root@online01 ~]# lsattr oldboy.txt 
-----a-------e- oldboy.txt
[root@online01 ~]# cat oldboy.txt 
hello.txt
[root@online01 ~]# echo hello >>oldboy.txt
[root@online01 ~]# cat oldboy.txt
hello.txt
hello
[root@online01 ~]# echo hello >oldboy.txt
-bash: oldboy.txt: Operation not permitted
[root@online01 ~]# rm -f oldboy.txt
rm: cannot remove `oldboy.txt': Operation not permitted
[root@online01 ~]# mv oldboy.txt  /tmp/
mv: cannot move `oldboy.txt' to `/tmp/oldboy.txt': Operation not permitted

 

 
[root@ace ~]# stat 123,txt 
  File: `123,txt'
  Size: 200           Blocks: 8          IO Block: 4096   regular file
Device: 803h/2051d    Inode: 654110      Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2019-01-05 20:08:04.410631441 +0800                #    access time        文件的訪問時間 
Modify: 2019-01-05 20:07:56.730630296 +0800                #      modified time      文件的修改時間
Change: 2019-01-05 20:07:56.730630296 +0800                #    change time        文件屬性的改變時間 

atime隨着訪問就變,形成大量的寫磁盤
解決::--->只有ctime變了之後atime才變

 

[root@oldboyedu01-nb ~]# file /etc/hosts  # 查看文件是什麼類型(普通文件、二進制文件、文本文件、數據文件)不會因後綴更改而變化 /etc/hosts: ASCII text

 

文件名不是文件的屬性
inode是用來存放文件屬性的。 格式化建立文件系統的自動建立。          
                      ls -i 查看文件的inode號碼
                      df -i 查看inode使用狀況
block是用來實際存放數據的位置。    格式化建立文件系統的時候自動建立。
                      ls -lh查看文件的大小
                      df -h 查看磁盤的使用狀況
inode特色:
存放着block的位置(指向block的指針)
inode節點號要相同的文件,護衛硬連接文件
inode在一個文件系統(分區),是惟一的。
block特色:
block是實際存放數據的位置 block 4k(centos
6.x) 1k 8k 建立大文件會佔用多個block,若是文件很小1k,4k剩餘的空間會被浪費。 建立一個非空文件要佔用一個inode和至少1個block 每讀取一個block就會消耗一次磁盤I/O(input/output 磁盤讀寫)。

 

 

 

  

[root@oldboyedu01-nb oldboy]# lsof |grep delete
rsyslogd  1250      root    2w      REG                8,3 7803924480     130420 /var/log/secure (deleted)
軟件名稱                                                   文件大小              文件名    

 (deleted)---標記 這個文件的硬連接數量爲0,進程調用數不爲0。

  

 linux正則匹配 

 

支持正則匹配的有   grep   sed  awk

 

基礎正則 (basic regular expression)BRE grep /sed / awk 支持 ^ $ . *  []   [^]
*   0次及以上 (貪婪匹配)
.任意一個字符,包括空格(能夠匹配屢次),不包含字符 grep是一個字符一個字符匹配,經過-o參數查看
擴展正則(extended regular expression)ERE           egrep / sed -r / awk 支持                    |    +    {}     ()         ?
egrep 'oldboy|linux' oldboy.txt
egrep 'oldb(o|e)y' oldboy.txt
()  括號中的內容至關因而一個總體 後向引用(反向引用)
echo 123456|sed -r 's#(.*)#<\1#g'

 

 

\n    回車換行

 

 

linux命令行快捷鍵

 

Ctrl + a   把光標移動到《行首》
Ctrl + e 把光標移動到《行尾》 Ctrl + c 取消當前的操做 cancel Ctrl + d logout命令(當前行沒有任何內容,退出當前用戶) Ctrl + l (小寫字母L) 清除屏幕內容 clear Ctrl + u 剪切光標所在位置到行首的內容 Ctrl + k 剪切光標所在位置到行尾的內容 ctrl + y 粘貼 ctrl + → 把光標向右移動一個單詞 ctrl + ← 把光標向左移動一個單詞 history |grep awk Ctrl + r search 搜索歷史命令,繼續搜索

 

netstat(ss-centos7)    顯示主機的端口與服務網絡鏈接狀態,ESTABLISHED表示創建鏈接的狀態,數量即表示網絡鏈接數lsof    顯示主機的端口與服務網絡鏈接狀態。nginx

相關文章
相關標籤/搜索