1、查看文件:
? ? ? 1.1、查看文件:
? ? ? ? ? ? ? ?cat xxx.log ? ? ?一下子將內(nèi)容刷新出來
? ? ? ? ? ? ? ?more xxx.log ? ?一頁頁的將內(nèi)容刷新出來(按空格)
? ? ? ? ? ? ? ?less xxx.log ? ? ?從后往前看
? ? ? 1.2、實時查看文件:
? ? ? ? ? ? ? ?tail ? ?實時查看文件內(nèi)容 ? ? ?->> ? ?ctrl + c ?打斷tail查看
? ? ? ? ? ? ? ?tail -f xxx.log ? 實時查看文件
? ? ? ? ? ? ? ?tail -F xxx.log ? ?-F = -f + -retry ? ? (查看在重試)
? ? ? ? ? ? ? ?tail -200f xxx.log ? 實時查看最新200行文件內(nèi)容
2、輸出打印
? ? ? echo “123” ? ? 打印123
3、追加和覆蓋
? ? ? a >> xxx.log ? ?將a內(nèi)容追加到xxx.log文件中
? ? ? a > xxx.log ? 將a內(nèi)容覆蓋到xxx.log文件中
4、系統(tǒng)別名 ?alias
? ? ? 4.1、設(shè)置臨時別名:
? ? ? ? ? ? ? ?alias bxx = 'cd /root/baixiaoxue/1'
? ? ? 4.2、設(shè)置永久別名:
? ? ? ? ? ? ? ?設(shè)置全局變量文件
5、環(huán)境變量文件
? ? ? 5.1、全局:/etc /profile
? ? ? ? ? ? ? source /etc/profile
步驟:
? ? ? ? vi /etc/profile 進入文件最后
? ? ? ? 書寫:#alias
? ? ? ? alias bxx = 'cd /root/baixiaoxue/1'
? ? ? ? 保存退出
? ? ? ? source /etc/profie
。。。。。。#表示注釋
5.2、個人: /.bash_profile、.bashrc
? ? ? ? ? ? ? ? ? ? source .bash_profile ? ?生效 ?
? ? ? ? ? ? ? ? ? ? . .bash_profile ? ?生效
步驟:ll -a. ? ?......查看隱藏文件
? ? ? ? ? ?vi /.bash_profile
? ? ? ? ? ?#alias?
? ? ? ? ? ?alias bxx = 'cd /root/baixiaoxue/6'
? ? ? ? ? ?wq
? ? ? ? ? ?cd
? ? ? ? ? ?source .bash_profile
6、切換個人目錄:su - baixiaoxue
? ? ? - 切換用戶之后,執(zhí)行環(huán)境變量文件:.bash_profile,并且進入該用戶的家目錄
? ? ? su baixiaoxue 切換用戶,環(huán)境變量不改變
su -?
7、刪除
? ? ? -f(強制刪除)
? ? ? -r(文件夾)
? ? ? rm xxx.log 刪除一個文件,詢問
? ? ? rm -f xxx.log 刪除一個文件,不詢問
? ? ? rm -rf xxx 刪除文件夾,詢問
? ? ? rm -rf /不能做(全部刪除)
? ? ? rm -rf $path/* ? ?=>> ? rm -rf /*
8、設(shè)置變量
? ? ? path=6 ? ? ? (key=balue)不能有空格 ?
? ? ? echo $path ? ? 打印路徑在刪除
? ? ? rm -rf $path/* ? ? 刪除文件子集
? ? ? rm -rf $path ? ? ? ? 刪除本身及其所有子集
9、history ? !70 ? ?查看歷史命令和執(zhí)行第70行命令
10、用戶、用戶組的常用命令
? ? ? ? [root@hadoop001 baixiaoxue]# ll
? ? ? ? total 20
? ? ? ? drwxr-xr-x. 4 root root 4096 May? 7 22:04 1
? ? ? ? -rw-r--r--. 1 root root? ? 8 May? 7 21:54 20180502.log
* ? ? 模糊匹配
? ? ? ?10.1、添加用戶及用戶組
? ? ? ? ? ? ? ? ? [root@hadoop001 baixiaoxue]# ll /usr/sbin/user*
? ? ? ? ? ? ? ? ? -rwxr-x---. 1 root root 103096 Dec? 8? 2011 /usr/sbin/useradd
? ? ? ? ? ? ? ? ? -rwxr-x---. 1 root root? 69560 Dec? 8? 2011 /usr/sbin/userdel
? ? ? ? ? ? ? ? ? -rws--x--x. 1 root root? 42384 Aug 23? 2010 /usr/sbin/userhelper
? ? ? ? ? ? ? ? ? -rwxr-x---. 1 root root? 98680 Dec? 8? 2011 /usr/sbin/usermod
? ? ? ? ? ? ? ? ? -rwsr-xr-x. 1 root root? 9000 Nov 23? 2013 /usr/sbin/usernetctl
? ? ? ? ? ? ? ? ? [root@hadoop001 baixiaoxue]# ll /usr/sbin/group*
? ? ? ? ? ? ? ? ? -rwxr-x---. 1 root root 54968 Dec? 8? 2011 /usr/sbin/groupadd
? ? ? ? ? ? ? ? ? -rwxr-x---. 1 root root 46512 Dec? 8? 2011 /usr/sbin/groupdel
? ? ? ? ? ? ? ? ? -rwxr-x---. 1 root root 50800 Dec? 8? 2011 /usr/sbin/groupmems
? ? ? ? ? ? ? ? ? -rwxr-x---. 1 root root 61360 Dec? 8? 2011 /usr/sbin/groupmod
添加用戶: ? useradd bg
查看用戶的id: id bg
刪除用戶:user delbg
查看home下的用戶文件夾:
? ? ? ? [root@hadoop001 baixiaoxue]# ll /home
? ? ? ? total 8
? ? ? ? drwx------. 27 baixiaoxue baixiaoxue 4096 Jun? 6 22:09 baixiaoxue
? ? ? ? drwx------.? 4? ? ? ? 501? ? ? ? 501 4096 Jun? 6 22:22 bg
10.2、管道符
? ? ? ? ? ?cat /etc/passwd ? ? 查看所有用戶信息
? ? ? ? ? ?cat /etc/passwd | grep bg ? ?查看關(guān)于bg用戶的信息
? ? ? ? ? ?//關(guān)于用戶信息
? ? ? ? ? ?[root@hadoop001 baixiaoxue]# cat /etc/passwd | grep bg
? ? ? ? ? ?bg:x:501:501::/home/bg:/bin/bash
? ? ? ? ? //關(guān)于用戶組信息
? ? ? ? ? [root@hadoop001 baixiaoxue]# cat /etc/group | grep bg
? ? ? ? ? bg:x:501:
10.3、添加用戶組
? ? ? ? ? ?查看用戶組方法
? ? ? ? ? ?ll /usr/sbin/group*
? ? ? ? ? ?創(chuàng)建用戶組
? ? ? ? ? ?grouped bigdata
? ? ? ? ? ?將bg用戶放入到bigdata用戶組中
? ? ? ? ? ?usermod -a -G bigdata bg
? ? ? ? ? ?[root@hadoop001 home]# usermod -a -G bigdata bg
? ? ? ? ? ?[root@hadoop001 home]# id bg
? ? ? ? ? ?uid=501(bg) gid=501(bg) groups=501(bg),502(bigdata)
? ? ? ? ? ?將bg該用的主組設(shè)置為bigdata
? ? ? ? ? ?[root@hadoop001 home]# usermod -g bigdata bg
? ? ? ? ? ?[root@hadoop001 home]# id bg?
? ? ? ? ? ?uid=501(bg) gid=502(bigdata) groups=502(bigdata)
11、查看命令
? ? ? ? ? ?user mod --help
12、設(shè)置密碼
? ? ? ? passwd bg
? ? ? ? [root@hadoop001 ruoze]# passwd bg
? ? ? ? Changing password for user bg.
? ? ? ? New password:
? ? ? ? BAD PASSWORD: it is too simplistic/systematic
? ? ? ? BAD PASSWORD: is too simple
? ? ? ? Retype new password:
? ? ? ? passwd: all authentication tokens updated successfully
13、exit ?退出當(dāng)前用戶,返回上一次用戶
14、臨時獲取root的最大權(quán)限
? ? ? ? permission denied 沒有權(quán)限
? ? ? ? sudo rz ? ? ? ?rz(別名設(shè)置)
? ? ? ? vi /etc/sudoers
? ? ? ? 找到root?
? ? ? ? 將一個用戶添加到 ?/etc/sudoers文件然后是無密碼?
? ? ? ? baixiaoxue ALL=(root) NOPASSWD:ALL
? ? ? ? wq!
? ? ? ? sudo ls -l /root
15、進程:
15.1、查看
? ? ? ? [root@hadoop001 ~]# ps -ef | grep tail
? ? ? ? root? ? ? 3070? 3048? 0 00:36 pts/3? ? 00:00:00 grep tail
15.2、殺死
? ? ? ? ? ?第二列是pid?
? ? ? ? ? ?殺死pid為3070的進程: ?kill -9 3070 ? ? ? ? ? ? (-9力度最大)
? ? ? ? ? ?殺死多個pid的進程:kil -9 3070 3071?
? ? ? ? ? ?殺死有關(guān)tail的所有進程(先查看一下是否要全部殺死): kill -9 $(pgrep -f tail)
16、端口號
[root@hadoop001 ~]# ps -fe|grep ssh
root? ? ? 1313? ? 1? 0 Jun06 ?? ? ? ? 00:00:00 /usr/sbin/sshd
root? ? ? 2081? 1313? 0 Jun06 ?? ? ? ? 00:00:00 sshd: root@pts/1
root? ? ? 2855? 1313? 0 Jun06 ?? ? ? ? 00:00:00 sshd: root@pts/2
root? ? ? 3044? 1313? 0 00:35 ?? ? ? ? 00:00:00 sshd: root@pts/3
root? ? ? 3097? 3048? 0 00:48 pts/3? ? 00:00:00 grep ssh
[root@hadoop001 ~]# netstat -nlp|grep 1313
tcp? ? ? ? 0? ? ? 0 0.0.0.0:22? ? ? ? ? ? ? ? ? 0.0.0.0:*? ? ? ? ? ? ? ? ? LISTEN? ? ? 1313/sshd? ? ? ? ?
tcp? ? ? ? 0? ? ? 0 :::22? ? ? ? ? ? ? ? ? ? ? :::*? ? ? ? ? ? ? ? ? ? ? ? LISTEN? ? ? 1313/sshd
問題:打開某個xxx服務(wù)的web界面: 需要ip和端口號
1.1獲取ip:ifconfig
1.2獲取端口號:
ps -ef|grep xxx ? ?->能得到這個服務(wù)的pid
netstat -nlpgrep pid ? ?->根據(jù)pid獲取到端口號 ? ?或者 ? ? ?netstat -nlpgrep xxx ? ?->根據(jù)xxx服務(wù)獲取到端口號