1.
ifconfig 查看当前ip linux
ipconfig window
云服务器 只有内网网卡,外网网卡 kafka
2.CRT/XSHELL 链接 Linux
3.文件创建
vi
touch xxx.log 创建一个空的文件
4.文件夹创建
mkdir xxx 创建1层
mkdir -p 1/2/3 连续创建3层
mkdir 4 5 6 同层1下子创建3个目录
5.mv 移动文件或文件夹 原路径是不存在
mv 20180427.log ruoze/
6.cp 复制文件或者文件夹 原路径是存在的
文件: cp 20180502.log ruoze/
文件夹: cp -r 4 1/
7.查看文件的内容
cat 20180427.log 一下子将内容刷新出来
more 20180427.log 一页页的按空格键翻
less 20180427.log
tail 实时查看文件内容
tail -f 20180427.log
tail -F 20180427.log -F = -f -retry
http://blog.itpub.net/30089851/viewspace-2134067/
tail -200f install.log.syslog 倒着查看最新200行,且实时
log4j 10份
xxx.log 系统记录日志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
临时: alias rz='cd /root/ruoze/1/'
永久: 取决于设置全局还是个人
12.环境变量文件
全局:
/etc/profile
source /etc/profile 生效
个人: .bash_profile 、.bashrc
~/.bash_profile
source ~/.bash_profile 生效
. ~/.bash_profile 生效
13.删除
rm xxx.log 删除一个文件,询问
rm -f xxx.log 删除一个文件,不询问
rm -rf xxx 删除文件夹
rm -rf / 不能做
在shell脚本:一定要校验path变量是否等于空
path=""
rm -rf $path/* ==> rm -rf /*
14.设置变量
path=6
key=value
15.history !70 查看历史命令和执行第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 自动创建一个用户和用户组,名称一样
[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]#
再次创建
[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.设置密码
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.切换用户之后,执行环境变量文件.bash_profile
2.且进入该用户的家目录
hadoop
su hadoop su - hadoop
xxxx xxxxxx
记住2件事:1. history
2. 查看环境变量文件
21.exit 退出当前用户,返回上一次用户
22.临时获取root的权限 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 ~]$
将一个用户添加到/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.进程
查看
[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
杀死关于tail命令的所有进程之前,给我ps -ef|grep tail查看确认清楚
kill -9 26027 26034 26049
kill -9 $(pgrep -f tail)
24.端口号
[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 ~]#
打开某个xxx服务的web界面: http://ip:端口/
ifconfig
ps -ef|grep xxx -->pid
netstat -nlp|grep pid -->port
netstat -nlp|grep xxx -->port