03-Linux常用命令二&三

1.

ifconfig 查看當(dāng)前ip? linux

ipconfig ? ? window

云服務(wù)器 只有內(nèi)網(wǎng)網(wǎng)卡,外網(wǎng)網(wǎng)卡? kafka

2.CRT/XSHELL 鏈接 Linux

3.文件創(chuàng)建

? vi

? touch xxx.log 創(chuàng)建一個(gè)空的文件


4.文件夾創(chuàng)建

? mkdir xxx? 創(chuàng)建1層

? mkdir -p 1/2/3 連續(xù)創(chuàng)建3層

? mkdir 4 5 6? 同層1下子創(chuàng)建3個(gè)目錄


5.mv 移動(dòng)文件或文件夾? 原路徑是不存在

mv 20180427.log ruoze/

6.cp 復(fù)制文件或者文件夾 原路徑是存在的

文件: cp 20180502.log ruoze/

文件夾: cp -r 4 1/

7.查看文件的內(nèi)容

cat 20180427.log 一下子將內(nèi)容刷新出來

more 20180427.log 一頁頁的按空格鍵翻

less 20180427.log

tail? ? ? ? ? ? ? 實(shí)時(shí)查看文件內(nèi)容

tail -f 20180427.log? ?

tail -F 20180427.log? -F = -f -retry

http://blog.itpub.net/30089851/viewspace-2134067/

tail -200f install.log.syslog? 倒著查看最新200行,且實(shí)時(shí)

log4j? 10份

xxx.log 系統(tǒng)記錄日志10份

100M就切1次:

mv xxx.log xxx.log1

touch xxx.log

8.

echo "456" > 20180502.log? 覆蓋

echo "123" >> 20180502.log 追加

9.輸出打印

echo "1234"

10.mv 和 cp誰快?

I'd argue for cp being the fastest, even if marginally so.

Between drives, 'mv' should essentially amount to cp + rm (copy to destination, then delete from source). On the same filesystem, 'mv' doesn't actually copy the data, it just remaps the inode, so it is far faster than cp.?

Rsync will be slower than cp since, it still needs to copy the entire file - and it has additional overhead (even if minor in this case). Rsync may win in the case where you already have the majority of data one the target drive and would only need to copy a small delta.

11.別名

alias

臨時(shí): alias rz='cd /root/ruoze/1/'

永久: 取決于設(shè)置全局還是個(gè)人

12.環(huán)境變量文件

全局:

/etc/profile?

source /etc/profile? 生效

個(gè)人:? .bash_profile 、.bashrc

~/.bash_profile

source ~/.bash_profile? 生效

. ~/.bash_profile? ? 生效

13.刪除

rm xxx.log 刪除一個(gè)文件,詢問

rm -f xxx.log 刪除一個(gè)文件,不詢問

rm -rf xxx? 刪除文件夾

rm -rf / 不能做

在shell腳本:一定要校驗(yàn)path變量是否等于空

path=""?

rm -rf $path/* ==> rm -rf /*

14.設(shè)置變量

path=6

key=value

15.history !70 查看歷史命令和執(zhí)行第70行

16.用戶,用戶組的常用命令

[root@hadoop000 ruoze]# 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@hadoop000 ruoze]#

[root@hadoop000 ruoze]#

[root@hadoop000 ruoze]# 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

[root@hadoop000 ruoze]#

[root@hadoop000 ruoze]# useradd ruoze? 自動(dòng)創(chuàng)建一個(gè)用戶和用戶組,名稱一樣

[root@hadoop000 ruoze]# id ruoze

uid=501(ruoze) gid=501(ruoze) groups=501(ruoze)

[root@hadoop000 ruoze]#

gid: 主組

groups:所有組

刪除

[root@hadoop000 ruoze]# userdel ruoze

[root@hadoop000 ruoze]# id ruoze

id: ruoze: No such user

[root@hadoop000 ruoze]#

再次創(chuàng)建

[root@hadoop000 ruoze]# useradd ruoze

useradd: warning: the home directory already exists.

Not copying any file from skel directory into it.

Creating mailbox file: File exists

[root@hadoop000 ruoze]#

查看/home/xxx用戶名稱的文件夾

[root@hadoop000 ruoze]# ll /home/

total 8

drwx------. 4 jepson jepson 4096 May? 2 22:14 jepson

drwx------. 4 ruoze? ruoze? 4096 May? 2 22:29 ruoze

[root@hadoop000 ruoze]#

用戶和用戶組的文件

[root@hadoop000 ruoze]# cat /etc/passwd | grep ruoze

ruoze:x:501:501::/home/ruoze:/bin/bash

[root@hadoop000 ruoze]#

[root@hadoop000 ruoze]# cat /etc/group | grep ruoze

ruoze:x:501:

[root@hadoop000 ruoze]#

[root@hadoop000 ruoze]# groupadd bigdata

[root@hadoop000 ruoze]# id ruoze

uid=501(ruoze) gid=501(ruoze) groups=501(ruoze)

[root@hadoop000 ruoze]# usermod -a -G bigdata ruoze

[root@hadoop000 ruoze]# id ruoze

uid=501(ruoze) gid=501(ruoze) groups=501(ruoze),502(bigdata)

[root@hadoop000 ruoze]# usermod -g bigdata ruoze

[root@hadoop000 ruoze]# id ruoze

uid=501(ruoze) gid=502(bigdata) groups=502(bigdata)

17.管道符 |

cat /etc/passwd | grep ruoze

18.查看命令幫助

usermod --help

man usermod

19.設(shè)置密碼

passwd ruoze

20.切換用戶

[root@hadoop000 ruoze]# su ruoze

[ruoze@hadoop000 ruoze]$ pwd

/root/ruoze

[ruoze@hadoop000 ruoze]$

[root@hadoop000 ruoze]#

[root@hadoop000 ruoze]# su - ruoze

[ruoze@hadoop000 ~]$

- 1.切換用戶之后,執(zhí)行環(huán)境變量文件.bash_profile

? 2.且進(jìn)入該用戶的家目錄

? hadoop

? su hadoop? su - hadoop

? xxxx? ? ? xxxxxx

記住2件事:1.? history

? ? ? ? ? 2.? 查看環(huán)境變量文件

21.exit 退出當(dāng)前用戶,返回上一次用戶

22.臨時(shí)獲取root的權(quán)限 sudo

[jepson@hadoop000 ~]$ rz

-bash: cd: /root/ruoze/6/: Permission denied

[jepson@hadoop000 ~]$

[jepson@hadoop000 ~]$

[jepson@hadoop000 ~]$ sudo rz

We trust you have received the usual lecture from the local System

Administrator. It usually boils down to these three things:

? ? #1) Respect the privacy of others.

? ? #2) Think before you type.

? ? #3) With great power comes great responsibility.

[sudo] password for jepson:

jepson is not in the sudoers file.? This incident will be reported.

[jepson@hadoop000 ~]$

將一個(gè)用戶添加到/etc/sudoers文件然后無密碼

[root@hadoop000 1]# vi /etc/sudoers

## Allow root to run any commands anywhere

root? ? ALL=(ALL)? ? ? ALL

jepson? ALL=(root)? ? ? NOPASSWD:ALL

[jepson@hadoop000 ~]$ ls -l /root

ls: cannot open directory /root: Permission denied

[jepson@hadoop000 ~]$

[jepson@hadoop000 ~]$ sudo ls -l /root

total 108

-rw-r--r--. 1 root root? ? 0 May? 2 21:12 20180502.log

-rw-------. 1 root root? 1382 Apr 28 05:21 anaconda-ks.cfg

drwxr-xr-x. 3 root root? 4096 Apr 27 22:37 Desktop

drwxr-xr-x. 2 root root? 4096 Apr 27 21:40 Documents

drwxr-xr-x. 2 root root? 4096 Apr 27 21:40 Downloads

-rw-r--r--. 1 root root 49565 Apr 28 05:20 install.log

-rw-r--r--. 1 root root 10033 Apr 28 05:16 install.log.syslog

drwxr-xr-x. 2 root root? 4096 Apr 27 21:40 Music

drwxr-xr-x. 2 root root? 4096 Apr 27 21:40 Pictures

drwxr-xr-x. 2 root root? 4096 Apr 27 21:40 Public

drwxr-xr-x. 3 root root? 4096 May? 2 22:20 ruoze

drwxr-xr-x. 2 root root? 4096 Apr 27 21:40 Templates

drwxr-xr-x. 2 root root? 4096 Apr 27 21:40 Videos

[jepson@hadoop000 ~]$

23.進(jìn)程

查看

[jepson@hadoop000 ~]$ ps -ef | grep tail

root? ? 24215? 2254? 0 21:29 pts/1? ? 00:00:00 tail -f 20180502.log

root? ? 26027? 2254? 0 21:32 pts/1? ? 00:00:00 tail -F 20180502.log

root? ? 26034? 2254? 0 21:35 pts/1? ? 00:00:00 tail -F 20180502.log

root? ? 26049? 2254? 0 21:37 pts/1? ? 00:00:00 tail -F 20180502.log

第二列是pid

kill -9 24215

殺死關(guān)于tail命令的所有進(jìn)程之前,給我ps -ef|grep tail查看確認(rèn)清楚

kill -9 26027 26034? 26049

kill -9 $(pgrep -f tail)

24.端口號(hào)

[root@hadoop000 ~]# ps -ef|grep ssh

root? ? ? 1432? ? 1? 0 20:45 ?? ? ? ? 00:00:00 /usr/sbin/sshd

root? ? ? 2248? 1432? 0 21:09 ?? ? ? ? 00:00:01 sshd: root@pts/1,pts/2,pts/3,pts/4

root? ? 26570? 2332? 0 23:14 pts/2? ? 00:00:00 grep ssh

[root@hadoop000 ~]# netstat -nlp|grep 1432

tcp? ? ? ? 0? ? ? 0 0.0.0.0:22? ? ? ? ? ? ? ? ? 0.0.0.0:*? ? ? ? ? ? ? ? ? LISTEN? ? ? 1432/sshd? ? ? ? ?

tcp? ? ? ? 0? ? ? 0 :::22? ? ? ? ? ? ? ? ? ? ? :::*? ? ? ? ? ? ? ? ? ? ? ? LISTEN? ? ? 1432/sshd? ? ? ? ?

[root@hadoop000 ~]#

打開某個(gè)xxx服務(wù)的web界面: http://ip:端口/

ifconfig

ps -ef|grep xxx -->pid

netstat -nlp|grep pid -->port

netstat -nlp|grep xxx -->port

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容