70條常用Linux基礎(chǔ)命令總結(jié)
[root@ping ~]# tree -L 1 /
#使用tree 命令查看根目錄下的一層的目錄結(jié)構(gòu)
ls - list directory contents
[root@ping ~]# ls -l /
以長(zhǎng)格式顯示文件和目錄的信息
[root@ping ~]# ls -d /
顯示目錄和文件
[root@ping ~]# ls -d /*
根目錄下的所有的目錄和文件
cd - Change the shell working directory
[root@ping ~]# cd -
上次一次所在的目錄
[root@ping /]# cd .
當(dāng)前目錄
[root@ping ~]# cd ..
這個(gè)目錄的上一次目錄
[root@ping /]# cd ~
當(dāng)前用戶(hù)的家目錄
pwd -?? Print the name of the current working directory.
[root@ping ~]# pwd
查看當(dāng)前所處的目錄
cp - copy files and directories
[root@ping ~]# cp
拷貝文件或目錄
alias - Define or display aliases
[root@ping ~]# alias rm ="mv"
定義別名alies 為mv 命令
unalias - Remove each NAME from the list of defined aliases
[root@ping ~]# alias
alias -rf='you want remvoe files or directories to mv'
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'
[root@ping ~]# unalias mv
取消mv這個(gè)別名
cat - concatenate files and print on the standard output
[root@ping ~]# cat -n /root/.bashrc
查看文件內(nèi)容并列出行號(hào)
find - search for files in a directory hierarchy
option:!取反、-a(and)并且、-o(or)
[root@ping ~]# find / -type f -name "useradd"
查找根目錄下文件類(lèi)型為文本文件并且包含名字是"useradd" 的文件路徑
head - output the first part of files
[root@ping ~]# head /etc/services
默認(rèn)查看文件前十行內(nèi)容
tail - output the last part of files
[root@ping ~]# tail /etc/passwd
默認(rèn)查看文件后十行內(nèi)容
[root@ping ~]# tail -f /var/log/messages
查看文件動(dòng)態(tài)更新的內(nèi)容
rpm - RPM Package Manager
[root@ping ~]# rpm -ivh /mnt/Packages/elinks.el6_3.x86_64.rpm
安裝顯示輸出rpm軟件包情況
[root@ping ~]# rpm -qa | grep mysql
查看當(dāng)前系統(tǒng)安裝關(guān)于"mysql"的rpm包名
yum - Yellowdog Updater Modified
[root@ping ~]# yum -y install ftp
用yum安裝ftp管理工具
[root@ping ~]# yum grouplist
查看當(dāng)前系統(tǒng)已經(jīng)安裝和可以安裝的包組
[root@ping ~]# yum -y groupinstall PostgreSQL 數(shù)據(jù)庫(kù)服務(wù)器
向當(dāng)前系統(tǒng)中安裝一組軟件包
[root@ping ~]# yum info
顯示關(guān)于軟件包或組的詳細(xì)信息
[root@ping ~]# yum groupinfo
查看yum和各個(gè)參數(shù)的詳細(xì)信息
[root@ping ~]# yum serache all
在軟件包詳細(xì)信息中搜索指定字符串
seq - print a sequence of numbers
[root@ping ~]# seq 5
生成序列從1到5的數(shù)字
[root@ping ~]# seq 3 5
生成序列從3到5的數(shù)字
[root@ping ~]# seq 3 3 10
生成序列3到10中間隔多少個(gè)數(shù)字
[root@ping ~]# seq -s "" 5
12345
-s指定分隔符為空
[root@ping ~]# seq -w 10
生成兩位數(shù)的數(shù)字并對(duì)齊
hostname - show or set the system’s host name
[root@ping ~]# hostname
ping
顯示系統(tǒng)主機(jī)名
uname - print system information
[root@ping ~]# uname -r
2.6.32-573.el6.x86_64
顯示當(dāng)前系統(tǒng)的內(nèi)核版本和操作系統(tǒng)位數(shù)
[root@ping ~]# uname -a
Linux ping 2.6.32-573.el6.x86_64 #1 SMP Wed Jul 1 18:23:37 EDT 2015 x86_64 x86_64 x86_64 GNU/Linux
顯示當(dāng)前系統(tǒng)的所有版本信息
[root@ping ~]# uname -m
x86_64
顯示當(dāng)前系統(tǒng)的操作系統(tǒng)位數(shù)
whoami - print effective userid
[root@ping ~]# whoami
root
查看當(dāng)前登錄系統(tǒng)的用戶(hù)名
su - run a shell with substitute user and group IDs
[root@ping ~]# su - ping
切換普通用戶(hù)為ping
logout -? Exit a login shell
[root@ping ~]# logout
退出當(dāng)前登錄shell
history - Display or manipulate the history list
[root@ping ~]# history
查看當(dāng)前用戶(hù)輸入命令的歷史記錄
[root@ping ~]# history -d 122
指定122行的命令歷史記錄清除
[root@ping ~]# history -c
清除當(dāng)前用戶(hù)輸入命令所有歷史記錄
runlevel - output previous and current runlevel
[root@ping ~]# runlevel
N 3
查看當(dāng)前系統(tǒng)的運(yùn)行級(jí)別
init - Upstart process management daemon
[root@ping ~]# init 5
切換當(dāng)前系統(tǒng)的運(yùn)行級(jí)別
chkconfig? -? updates? and queries runlevel information for system services
[root@ping ~]# chkconfig sshd on
使ssh服務(wù)開(kāi)機(jī)自啟動(dòng)
[root@ping ~]# chkconfig --list sshd
查看ssh服務(wù)在每一個(gè)運(yùn)行級(jí)別是否為開(kāi)機(jī)自啟動(dòng)
which - shows the full path of (shell) commands
[root@ping ~]# which ps
搜索ps命令的絕對(duì)路徑
whereis? -? locate the binary, source, and manual page files for a com-mand
[root@ping ~]# whereis jobs
搜索命令的文件所在的絕對(duì)路徑
[root@ping ~]# whereis -b ping
只搜索命令的二進(jìn)制文件的絕對(duì)路徑
開(kāi)戶(hù)網(wǎng)卡和重新讀取配置文件
[root@ping ~]# ifdown eth0 && ifup eth0? ==》? [root@ping ~]# /etc/init.d/network reload
blkid - command-line utility to locate/print block device attributes
[root@ping ~]# blkid
查看當(dāng)前系統(tǒng)塊設(shè)備的UUID號(hào)
BASH_BUILTINS(1)
alias, bg, bind, break, builtin, caller, cd, command,
compgen, complete, compopt,? continue,? declare,? dirs,? disown,? echo,enable,? eval,? exec, exit, export, false, fc, fg, getopts, hash, help,history, jobs, kill, let, local, logout, mapfile, popd, printf,? pushd,pwd,? read, readonly, return, set, shift, shopt, source, suspend, test,times, trap, true, type, typeset, ulimit, umask, unalias, unset, wait
#Linux中所有的內(nèi)置命令,我們說(shuō)which只能在PATH變量中搜索命令的絕對(duì)路徑,內(nèi)置命令是內(nèi)置在bash中的,所以我們找不到
[root@ping ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0 #《==物理設(shè)備名,eth1表示第2塊網(wǎng)卡
ONBOOT=yes?? ??? #《==控制網(wǎng)卡是否為開(kāi)機(jī)自啟動(dòng)
NM_CONTROLLED=yes? #《==是一個(gè)可以讓networkmanage管理的工具
BOOTPROTO=none???? #《==其中,proto取下列值這一:none,引導(dǎo)時(shí)不使用?? ??? ?????? 協(xié)議;static靜態(tài)分配地址;bootp,使用bootp協(xié)議
使用dhcp協(xié)議
IPADDR=192.168.114.5 #《==ip address是IP地址
netmask=255.255.255.0? #《==子網(wǎng)掩碼,劃分網(wǎng)絡(luò)位和主機(jī)位。
resolv.conf? - resolver configuration file
[root@ping ~]# cat /etc/resolv.conf
#DNS的客戶(hù)端文件,DNS在網(wǎng)卡的文件中也可以配置
[root@ping ~]# cat /etc/resolv.conf
nameserver 8.8.8.8
nameserver 202.106.0.20
#一般最好配置兩個(gè)DNS,一個(gè)主,一個(gè)備
# 不要配置網(wǎng)卡里設(shè)置DNS優(yōu)先于/etc/resolv.conf
小結(jié):
1、客戶(hù)端DNS可以在網(wǎng)卡配置文件里設(shè)置(ifcfg-eth0)
2、客戶(hù)端DNS也可以在/etc/resolv.conf里設(shè)置
3、網(wǎng)卡里的設(shè)置DNS優(yōu)先于/etc/resolv.conf
hosts - The static table lookup for hostnames
[root@ping ~]# cat /etc/hosts
#設(shè)定用戶(hù)IP與名字(或域名)的對(duì)應(yīng)解析表,相當(dāng)于本地LAN局域網(wǎng)內(nèi)的DNS
對(duì)應(yīng)windows的文件路徑:C:\Windows\System32\drivers\etc\hosts
/etc/hosts:局域網(wǎng) 主機(jī)名和ip地址的解析,相當(dāng)于DNS工具
hosts企業(yè)里的作用:
1.開(kāi)發(fā)、產(chǎn)品、測(cè)試等人員,用于通過(guò)正式的域名測(cè)試產(chǎn)品
2.服務(wù)器之間的調(diào)用可以用域名(內(nèi)部DNS),方便遷移
[root@ping ~]# cat /etc/sysconfig/network
#配置主機(jī)的主機(jī)名的配置文件
fstab - static information about the filesystems
[root@ping ~]# cat /etc/fstab
設(shè)置文件系統(tǒng)掛載信息的文件,使得開(kāi)機(jī)自動(dòng)掛載磁盤(pán)分區(qū)
The third field:such as adfs, affs, autofs,coda, coherent, cramfs, devpts, efs, ext2, ext3,? hfs,? hpfs,? iso9660,jfs,? minix,? msdos,? ncpfs,? nfs,? ntfs,? proc, qnx4, reiserfs, romfs,smbfs, sysv, tmpfs, udf, ufs, umsdos, vfat, xenix,? xfs,? and? possiblyothers.
包含了所有的Linux文件系統(tǒng)類(lèi)型
df - report file system disk space usage
[root@ping ~]# df -h
#以人類(lèi)可讀的信息查看磁盤(pán)掛載信息
mount - mount a filesystem
[root@ping ~]# mount
查看當(dāng)前系統(tǒng)中所使用的文件系統(tǒng)類(lèi)型
[root@ping ~]# mount -t ext4 -o loop,noatime,noexec /dev/sdb1 /mnt
-o 參數(shù):noatime,noexec不改變時(shí)間戳,不改變命令
手動(dòng)掛載一個(gè)文件系統(tǒng)
掛載:
1.命令
[root@ping ~]# mount -t ext4 -o noexec /dev/sdb1 /mnt
2.文件
[root@ping ~]# vim /etc/fstab
dd - convert and copy a file
[root@ping ~]# dd if=/dev/zero of=/dev/sdb1 bs=4096 count=10
生成一個(gè)文件系統(tǒng)
mke2fs - create an ext2/ext3/ext4 filesystem
[root@ping ~]# mkfs.ext4 /dev/sdb1
格式化文件系統(tǒng)/dev/sdb1
測(cè)試手動(dòng)掛載:
1.創(chuàng)建一個(gè)虛擬的塊設(shè)備
dd if=/dev/zero of=/dev/sdb1 bs=4906 count=100
2.格式化
mkfs.ext4 /dev/sdb1
3.掛載
mount -t ext4 -o loop,noatime,noexec /dev/sda1 /mnt
fsck - check and repair a Linux file system
[root@ping ~]# fsck -A /dev/sda
磁盤(pán)檢查(不要檢查好磁盤(pán)),卸載的狀態(tài)檢查