Linux發行版介紹、Linux系統基礎使用入門、Linux命令幫助、Linux基礎命令
CPU(運算器、控制器)、memory、I/O(輸入設備、輸出設備)
程序運行模式: 用戶空間:user space,us (可執行普通指令) 內核空間:system space (可執行特權指令) POS:Postable Operating System 可移植操作系統 POSIX 可移植操作系統規範 運行程序格式: Windows:EXE,庫文件dll(dynamic link library 動態鏈接庫) Linux:ELF,庫文件so(shared object 共享對象) 程序:指令+數據 指令:只讀 數據:讀寫 程序:算法+數據結構 庫調用,系統調用:允許被調用的程序; malloc() 申請內存空間;free() 釋放內存空間; 編程語言 匯編語言:微碼編程(系統級程序員) 系統中某些於硬件相關的特有代碼、驅動程序開發; 高級語言:C、C++ 系統級應用、驅動程序 高級應用:java、python、php 應用程序 Linux的發行版: slackware: suse: sles suse企業版 opensuse debian: ubuntu mint redhat: rhel:redhat enterprise linux 企業版 每18個月發行一個新版本 CentOS:兼容rhel的格式 fedora:個人桌面版 測試新軟件程序 每6個月發行一個新版本 ArchLinux Gentoo LFS:Linux From scratch Android:kernel+busybox+java虛擬機 GNU:GPLv2、GPLv3、LGPL(lesser寬松的GPL) Apache:apache BSD:bsd
程序包管理器:
rpm:
RHEL、Fedora、suse、CentOS
dpt:
Debian、Ubuntu
自由軟件:
自由使用、自由學習和修改、自由分發、自由創建衍生版
Linux的哲學思想:
1、一切皆文件;把幾乎所有資源,包括硬件設備都組織為文件格式;
2、由眾多單一目的的小程序組成;一個程序只實現一個功能,而且做好,組合小程序完成復雜任務;
3、盡量避免跟用戶交互;目標:實現腳本編程,以自動完成某些功能;
4、使用純文本文件保存配置信息;目標:一款使用的文本編輯器即能完成系統配置功能;
如何獲取CentOS的發行版:
http://mirrors.aliyun.com
http://mirrors.sohu.com
終端:
用戶與主機交互,必然用到的設備,終端設備
物理終端:直接接入本機的顯示器和鍵盤:/dev/console
虛擬終端:附加在物理終端之上的以軟件方式虛擬實現的終端,CentOS 6默認啟動的6個虛擬終端
Crtl+Alt+F#:[1-6]
圖形終端:附加在物理終端之上的以軟件方式虛擬實現的終端,但額外會提供桌面環境;
設備文件路徑:/dev/tty#
模擬終端:圖形界面下打開的命令行接口,基於ssh協議或telnet協議等遠程打開的界面
設備文件:/dev/pts/# [0,oo) 零-正無窮
查看當前的終端設備:tty
命令示例如下:
/dev/pts/2
交互式接口:啟動終端後,在終端設備附加一個交互式應用程序
GUI:
X protocol、windows manager、desktop
Desktop:
GNOME(C,gtk圖形開發庫)
KDE(C++,qt圖形開發庫)
XFCE(輕量級桌面)
CLI:
shell程序:
sh(bourn)
csh
tcsh
ksh
bash(bourn again shell)遵循GPL協定
zsh
顯示當前使用的shell:
#echo $SHELL
[root@localhost ~]# echo $SHELL
/bin/bash
顯示當前系統使用的所有shell:
#cat /etc/shells
[root@localhost ~]# cat /etc/shells
/bin/sh
/bin/bash
/sbin/nologin
/bin/tcsh
/bin/csh
/bin/ksh
命令提示符:prompt
[root@localhost ~]#
[root@localhost ~]:PS1
prompt:
管理員:#
普通用戶:$
[root@localhost ~]# echo $PS1
[\u@\h \W]\$
u:表示用戶
h:表示主機名
W:表示工作目錄
命令:
輸入命令,回車
提請shell程序找到鍵入命令所對應的可執行程序或代碼,並由其分析或提交給內核分配資源將其運行起來;
表現為一個或多個進程;
在shell中可執行的命令有兩類:
內建命令:由shell自帶的,而且通過某命令形式停工;
外部命令:在當前系統的某文件系統系統路徑下有對應的可執行程序文件
which、whereis
[root@localhost ~]# which tty
/usr/bin/tty
[root@localhost ~]# which cat
/bin/cat
[root@localhost ~]# whereis tty
tty: /usr/bin/tty /usr/share/man/man4/tty.4.gz /usr/share/man/man1/tty.1.gz /usr/share/man/man1p/tty.1p.gz
[root@localhost ~]# whereis cat
cat: /bin/cat /usr/share/man/man1/cat.1.gz /usr/share/man/man1p/cat.1p.gz
區別內建或外部命令:
#type command
內建命令:
[root@localhost ~]# type cd
cd is a shell builtin
外部命令:
[root@localhost ~]# type tty
tty is hashed (/usr/bin/tty)
運行命令:
命令格式:
commmand [options選項...] [arguments參數...]
選項:用戶啟用或關閉命令的某個或某些功能
短選項:-c,例如:-l、-h
多個短選項可合並使用,例如:-l、-h,可寫作:-lh
[root@localhost ~]# ls -l -h
total 72K
-rw------- 1 root root 1.3K Mar 15 16:47 anaconda-ks.cfg
drwxr-xr-x 2 root root 4.0K Mar 15 16:53 Desktop
-rw-r--r-- 1 root root 37K Mar 15 16:47 install.log
-rw-r--r-- 1 root root 3.6K Mar 15 16:47 install.log.syslog
-rw-r--r-- 1 root root 195 Mar 15 16:51 scsrun.log
[root@localhost ~]# ls -lh
total 72K
-rw------- 1 root root 1.3K Mar 15 16:47 anaconda-ks.cfg
drwxr-xr-x 2 root root 4.0K Mar 15 16:53 Desktop
-rw-r--r-- 1 root root 37K Mar 15 16:47 install.log
-rw-r--r-- 1 root root 3.6K Mar 15 16:47 install.log.syslog
-rw-r--r-- 1 root root 195 Mar 15 16:51 scsrun.log
長選項:--word,例如:--long,--human-readable
長選項一般不能合並使用
[root@localhost ~]# ls --human-readable
anaconda-ks.cfg Desktop install.log install.log.syslog scsrun.log
參數:命令的作用對象;向命令提供數據;
註意:
1、多選項、以及多參數和命令之間都應該使用空白字符分隔;
2、取消命令執行,Ctrl+c;
文件系統:
Windows C:\Program files\office1\word\word.exe
Linux /etc/sysconfig/network-scripts/ifcfg-eth0
文件有兩類數據:
元數據:metadata 數據屬性信息、存放在索引中
數據:data
1、文件名嚴格區分字符大小寫:file1、File1、FILE1是不同的部件;
2、文件名可使用除/以外的任意字符,不建議使用特殊字符;/是根目錄,路徑分隔符;
3、文件名長度最長不能超過255個字符;
4、所有以.開頭的文件,均為隱藏文件;
路徑:
絕對路徑,從根目錄起始的路徑:
[root@localhost ~]# cd /etc/sysconfig/network-scripts/
[root@localhost network-scripts]# pwd
/etc/sysconfig/network-scripts
相對路徑,從當前目錄起始的路徑:
[root@localhost ~]# cd /etc
[root@localhost etc]# pwd
/etc
[root@localhost etc]# cd sysconfig/network-scripts/
[root@localhost network-scripts]# pwd
/etc/sysconfig/network-scripts
.:表示當前目錄
..:表示當前目錄的上一級目錄、父目錄
當前目錄:current directory,也稱作working directory;工作目錄
pwd:print working directory 顯示工作目錄
LSB:linux standard base linux標準庫
Linux命令幫助的獲取
外部命令:都有一個可執行程序,位於文件系統某目錄下:
which、whereis
shell程序搜尋可執行程序文件的路徑定義在PATH環境變量中
# echo $PATH
[root@localhost ~]# echo $PATH
/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
註意:自左向右的搜尋
格式:command [options...] [arguments...] (命令 選項... 參數...)
內建命令: # help command
外部命令:
1、# command --help # command -h
2、使用手冊(manual) # man command
3、信息頁 # info command
4、程序自身的幫助文檔 readme、install、changelog
5、程序官方文檔、官方站點的Documentation
6、發行版的官方文檔
7、Google
內部命令幫助
# help command
[root@localhost ~]# help cd
cd: cd [-L|-P] [dir]
shell搜尋到的外部命令的路徑結果會緩存到kv(key-value鍵值)存儲中
history命令:
作用是什麽?相關的環境變量是什麽?有用的選項?
管理命令歷史,會讀取命令歷史文件中記錄的命令:~/.bash_history
[root@localhost ~]# cat .bash_history
cat .bash_history
echo "" > .bash_history
cat .bash_history
history -a
登錄進shell後新執行的命令只會記錄在緩存中:這些命令會在用戶退出時“追加”到命令歷史文件中:
history:
-a:追加本次會話新執行的命令歷史列表到歷史文件中;
[root@localhost ~]# history -a
[root@localhost ~]# cat .bash_history
echo "" > .bash_history
history -a
cat .bash_history
init 6
history -a
-d # :刪除歷史中指定的命令;
-c:清空命令歷史;
[root@localhost ~]# history -c
[root@localhost ~]# history
1 history
快捷操作:
!#:調用歷史中第#條命令;
[root@localhost ~]# history
1 history
2 ls
3 history
[root@localhost ~]# !2
ls
anaconda-ks.cfg install.log scsrun.log
Desktop install.log.syslog
!string:調用歷史中最近一個以string開頭的命令;
[root@localhost ~]# history
1 history
2 cd
3 ls
4 history
[root@localhost ~]# !c
cd
!!:執行上一條命令
[root@localhost ~]# history
1 history
2 ls
3 cd
4 history
[root@localhost ~]# !!
history
1 history
2 ls
3 cd
4 history
5 history
外部命令獲取幫助:
man command
手冊頁:/usr/share/man
man1...man8
man1:用戶命令
man2:系統調用
man3:C庫調用
man4:設備文件及特殊文件
man5:配置文件格式
man6:遊戲
man7:雜項
man8:管理類的命令
註意:有些命令在不止一個章節中存在幫助手冊
要查看指定章節中的手冊:man # command;whatis command該命令可以幫助查詢敏玲在哪些章節中存在幫助手冊;
[root@localhost ~]# whatis passwd
passwd (1) - update user‘s authentication tokens
passwd (5) - password file
passwd (rpm) - The passwd utility for setting/changing passwords using PAM
passwd [sslpasswd] (1ssl) - compute password hashes
[root@localhost ~]# man 1 passwd
[root@localhost ~]# man 5 passwd
man命令的配置文件:/etc/man.config
manpath /path/to/somewhere:指定新的手冊文件搜索位置
MANPATH_MAP /bin /usr/share/man
MANPATH_MAP /sbin /usr/share/man
MANPATH_MAP /usr/bin /usr/share/man
MANPATH_MAP /usr/sbin /usr/share/man
MANPATH_MAP /usr/local/bin /usr/local/share/man
MANPATH_MAP /usr/local/sbin /usr/local/share/man
MANPATH_MAP /usr/X11R6/bin /usr/X11R6/man
MANPATH_MAP /usr/bin/X11 /usr/X11R6/man
MANPATH_MAP /usr/bin/mh /usr/share/man
man -M /path/to/somewhere command:到指定位置下搜索comand命令的手冊頁並顯示之;
[root@localhost ~]# man -M /usr/share/man passwd
幫助手冊中的段落說明:
NAME 命令名稱、基本功能
SYNOPSIS 使用簡要幫助
DESCRIPTION 描述詳細功能
OPTIONS 選項
EXAMPLE 使用示例
AUTHOR 作者
REPORTING BUGS 報告BUGS的文職
SEE ALSO 參考
SYNOPSIS:
[]:可選內容
<>:必選內容
a|b:二選一、或者多選一
...:同一內容可出現多次
man命令的操作方法:
space空格鍵、ctrl+V、ctrl+f、ctrl+F:向文件尾部翻屏
b、ctrl+B:向文件首部翻屏
d、ctrl+D:向文件尾部翻半屏
u、ctrl+U:向文件首部翻半屏
RETURN回車鍵、ctrl+N、ectrl+E、j、ctrl+J:向文件尾部翻一行
y、ctrl+Y、ctrl+P、k、ctrl+K:向文件尾部翻一行
q:退出
#:跳轉到第#行;
1G:回到文件首部
G:翻到文件尾部
文件搜索:
/keyword:以keyword指定的字符串為關鍵字,從當前位置向文件尾部搜索;不區分字符大小寫;
n:下一個
N:上一個
?keyword:以keyword指定的字符串為關鍵字,從當前位置向文件首部搜索;不分區字符大小寫;
n:跟搜索命令同方向,下一個
N:跟搜索命令反方向,上一個
info命令
info command
程序自身的幫助文檔
/usr/share/doc/command-version
[root@localhost ~]# cd /usr/share/doc
[root@localhost doc]# ll
total 3864
drwxr-xr-x 2 root root 4096 Mar 15 16:45 a2ps-4.13b
drwxr-xr-x 2 root root 4096 Mar 15 16:44 acl-2.2.39
drwxr-xr-x 2 root root 4096 Mar 15 16:47 alacarte-0.10.0
drwxr-xr-x 2 root root 4096 Mar 15 16:45 alchemist-1.0.36
drwxr-xr-x 2 root root 4096 Mar 15 16:45 alsa-lib-1.0.17
基礎命令:
date:
date [option]...[+format]:顯示
format:顯示符號
%y 兩位的年份
[root@localhost doc]# date +%y
18
%Y 四位的年份
[root@localhost doc]# date +%Y
2018
%m 月份
[root@localhost doc]# date +%m
03
%h 月份英文縮寫
[root@localhost doc]# date +%h
Mar
%d 當月的幾號
[root@localhost doc]# date +%d
19
%H 小時
[root@localhost doc]# date +%H
11
%M 分鐘
[root@localhost doc]# date +%M
03
%S 秒鐘
[root@localhost doc]# date +%S
28
%s unix元年到現在的秒數
[root@localhost doc]# date +%s
1521428720
%D 日期
[root@localhost doc]# date +%D
03/19/18
%F 日期
[root@localhost doc]# date +%F
2018-03-19
%T 時間
[root@localhost doc]# date +%T
11:07:57
date [MMDDhhmm[[cc]yy][.ss]] :設置日期時間
MM:月份
DD:幾號
hh:小時
mm:分鐘
yy:兩位年份
ccyy:四位年份
.ss:秒鐘
[root@localhost doc]# date 0319112018.00
Mon Mar 19 11:20:00 CST 2018
[root@localhost doc]# date 031911202018.00
Mon Mar 19 11:20:00 CST 2018
Linux的兩種時鐘:
系統時鐘:由Linux內核CPU的工作頻率進行的計時:date
硬件時鐘:hwclock
[root@localhost doc]# date;hwclock
Mon Mar 19 11:22:51 CST 2018
Mon 19 Mar 2018 11:23:12 AM CST -0.812703 seconds
hwclock:顯示硬件時鐘
-s,--hctosys 以硬件時鐘為準設置系統時鐘
[root@localhost doc]# hwclock -s
[root@localhost doc]# date;hwclock
Mon Mar 19 11:24:59 CST 2018
Mon 19 Mar 2018 11:25:00 AM CST -0.634669 seconds
-w,--systohc 以系統始終為準設置硬件時鐘
[root@localhost doc]# hwclock -w
[root@localhost doc]# date;hwclock
Mon Mar 19 11:26:14 CST 2018
Mon 19 Mar 2018 11:26:16 AM CST -0.537715 seconds
cal:顯示日歷
[root@localhost doc]# cal
March 2018
Su Mo Tu We Th Fr Sa
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
目錄相關的命令
當前目錄或工作目錄
主目錄,家目錄;HOME
root:/root
普通用戶:/home/username、/home/tom
~:表示用戶的家目錄
cd
cd或cd~:表示切換到當前用戶的主目錄
[root@localhost ~]# cd
[root@localhost ~]# pwd
/root
[root@localhost tom]# cd ~
[root@localhost ~]# pwd
/root
cd ~username:表示切換到指定用戶的家目錄
[root@localhost ~]# cd ~tom
[root@localhost tom]# pwd
/home/tom
cd - :在上一個目錄和當前目錄之間來回切換
[root@localhost home]# cd -
/root
[root@localhost ~]# cd -
/home
.:表示當前目錄
..:表示當前目錄的父目錄
相關的環境變量
PWD:保存了當前目錄路徑
OLDPWD:上一次所在目錄路徑
[root@localhost home]# echo $PWD
/home
[root@localhost home]# echo $OLDPWD
/root
pwd:顯示當前工作目錄
ls:list 顯示指定路徑下的文件列表
ls [option]...[dir]...
-a,--all:顯示所有文件,包括隱藏文件
[root@localhost home]# ls -a
. .. tom
[root@localhost home]# ls --all
. .. tom
-l:長格式
-rw-r--r-- 1 root root 37412 Mar 15 16:47 install.log
-rw-r--r--
最左側的第一位:文件類型
-:普通文件
d:目錄文件
l:鏈接文件
b:塊設備
c:字符設備
p:管道文件
s:套接字文件
後面的9位,訪問權限,perm
數字1:文件被硬鏈接的次數;
左root:文件的owner,文件的屬主
右root:文件的group,文件的屬組
37412:文件的size
Mar 15 16:47:文件的最近一次被修改的時間
install.log:文件名
-h,--human-readable:單位換算,以人類易讀的格式顯示文件大小,通常與選項-l一起使用
[root@localhost ~]# ls -lh
total 72K
-rw------- 1 root root 1.3K Mar 15 16:47 anaconda-ks.cfg
drwxr-xr-x 2 root root 4.0K Mar 15 16:53 Desktop
-rw-r--r-- 1 root root 37K Mar 15 16:47 install.log
-rw-r--r-- 1 root root 3.6K Mar 15 16:47 install.log.syslog
-rw-r--r-- 1 root root 195 Mar 15 16:51 scsrun.log
-d:顯示目錄自身的相關屬性;通常要與-l一起使用;
[root@localhost ~]# ls -ld
drwxr-x--- 14 root root 4096 Mar 16 08:30 .
-r,--reverse:逆序顯示
[root@localhost ~]# ls -lr
total 72
-rw-r--r-- 1 root root 195 Mar 15 16:51 scsrun.log
-rw-r--r-- 1 root root 3672 Mar 15 16:47 install.log.syslog
-rw-r--r-- 1 root root 37412 Mar 15 16:47 install.log
drwxr-xr-x 2 root root 4096 Mar 15 16:53 Desktop
-rw------- 1 root root 1264 Mar 15 16:47 anaconda-ks.cfg
-R,--recurisve:遞歸顯示
[root@localhost ~]# ls -R /root
/root:
anaconda-ks.cfg Desktop install.log install.log.syslog scsrun.log
/root/Desktop:
stat /path/to/somefile:獲取指定文件的元數據屬性信息:
[root@localhost ~]# stat /etc/fstab
File: `/etc/fstab‘
Size: 534 Blocks: 16 IO Block: 4096 regular file
Device: fd00h/64768d Inode: 652169 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2018-03-19 09:01:14.000000000 +0800
Modify: 2018-03-15 16:44:22.000000000 +0800
Change: 2018-03-15 16:47:52.000000000 +0800
文件查看命令:cat、tac
cat [option]...[file]...
[root@localhost ~]# cat /etc/fstab /etc/issue
/dev/VolGroup00/LogVol00 / ext3 defaults 1 1
LABEL=/boot /boot ext3 defaults 1 2
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/VolGroup00/LogVol01 swap swap defaults 0 0
Red Hat Enterprise Linux Server release 5.7 (Tikanga)
Kernel \r on an \m
[root@localhost ~]# tac /etc/fstab /etc/issue
/dev/VolGroup00/LogVol01 swap swap defaults 0 0
proc /proc proc defaults 0 0
sysfs /sys sysfs defaults 0 0
devpts /dev/pts devpts gid=5,mode=620 0 0
tmpfs /dev/shm tmpfs defaults 0 0
LABEL=/boot /boot ext3 defaults 1 2
/dev/VolGroup00/LogVol00 / ext3 defaults 1 1
Kernel \r on an \m
Red Hat Enterprise Linux Server release 5.7 (Tikanga)
-E:顯示行結束符$
[root@localhost ~]# cat -E /etc/issue
Red Hat Enterprise Linux Server release 5.7 (Tikanga)$
Kernel \r on an \m$
$
-n:對顯示出的每一行進行編號
[root@localhost ~]# cat -n /etc/issue
1 Red Hat Enterprise Linux Server release 5.7 (Tikanga)
2 Kernel \r on an \m
3
文件內容類型查看命令:file
file /path/to/somewhere
[root@localhost ~]# file /etc/issue
/etc/issue: ASCII text
[root@localhost ~]# file /bin/ls
/bin/ls: ELF 64-bit LSB executable, AMD x86-64, version 1 (SYSV), for GNU/Linux 2.6.9, dynamically linked (uses shared libs), for GNU/Linux 2.6.9, stripped
[root@localhost ~]# file /dev/console
/dev/console: character special (5/1)
回顯命令:echo
-n:禁止自動添加換行符號
[root@localhost ~]# echo "how are you?"
how are you?
[root@localhost ~]# echo -n "how are you?"
how are you?[root@localhost ~]#
-e:允許使用轉義符
\n 換行
[root@localhost ~]# echo -e "how \nare you?"
how
are you?
\b 退格
[root@localhost ~]# echo -e "how\b are you?"
ho are you?
\t 制表符 Tab鍵
[root@localhost ~]# echo -e "how\t are you?"
how are you?
echo "$VAR_NAME":變量會替換,雙引號表示弱引用
[root@localhost ~]# echo "$PS1"
[\u@\h \W]\$
echo ‘$VAR_NAME‘ :變量不會替換,單引號表示強引用
[root@localhost ~]# echo ‘$PS1‘
$PS1
which:顯示命令對應的程序文件路徑
which [option] command
[root@localhost ~]# which ls
alias ls=‘ls --color=tty‘
/bin/ls
[root@localhost ~]# which cat
/bin/cat
--skip-alias:禁止顯示別名
[root@localhost ~]# which ls
alias ls=‘ls --color=tty‘
/bin/ls
[root@localhost ~]# which --skip-alias ls
/bin/ls
whatis:whatis命令顯示手冊部分的頁眉行。然後可以發出man命令以獲取附加的信息
[root@localhost ~]# whatis cd
cd (1p) - change the working directory
cd [builtins] (1) - bash built-in commands, see bash(1)
[root@localhost ~]# whatis mkdir
mkdir (1) - make directories
mkdir (1p) - make directories
mkdir (2) - create a directory
mkdir (3p) - make a directory
[root@localhost ~]# whatis useradd
useradd (8) - create a new user or update default new user information
使用makewathis命令可將當前系統上所有的幫助手冊及與之對應的關鍵字創建為一個數據庫。
Linux發行版介紹、Linux系統基礎使用入門、Linux命令幫助、Linux基礎命令