linux命令点滴:
1.结果集中过虑 ls -all | grep houning,
2.强制保存退出 wq!,
q!不保存退出
3.ls -A 查看隐藏文件等
4.修改主机名称:/etc/hostname文件中内容重启机器(utuntu),重启系统查看
有些机器在/etc/sysconfig/network中;
/etc/hosts存放域名与IP对应关系, 域名与主机名无关系
5.添加用户:adduser houning/passwd 123456 ;
新建组:groupadd lmt
新建用户并添加组:useradd -g lmt houning
删除用户/组:userdel houning, groupdel lmt
6.finger:查看用户信息工具
7.查看侦听的程序 netstat -ap|grep 50030
8.groups 查看当前登录用户的组内成员
groups houning 查看用户所在组
9.某个目录下查找字符串: grep -rn "hadoop" ./
10.当前文件夹大小: du -sh .
指定文件大小:du -sk filename
11.scp -r文件夹/-p指定端口 /opt/hadoop/... root@ip /目标目录
12.远程关机:ssh -f root@ip shutdown -h now
13.使用sftp文件传输:sftp root@ip 登录
使用put上传文件到远程主机
使用get下载文件到本机
14.背景:制作不用密码可立即登录的ssh用户
问题:使用crontab服务中通过scp远程定期网络备份等? 不能
原因:默认情况下, 必须通过远程登录, 需要输入密码,crontab不会让你在
终端输入密码, 所以程序会一直卡住,
解决:通过密钥认证处理, 既然ssh可以使用密钥系统来比对数据,
15.vim中删除所有空行: :g/^$/d
16.高亮显示(配置/etc/vim/vimrc)
:set hlsearch
取消高亮显示
:set nohlsearch
忽略大小写
:set ignorecase
或者
:set ic
使linux终端显示256色
set t_Co=256
syntax on
缩进
set autoindent
set cindent
17.umask 可以查询到当前文件创建时的默认权限
~ 当前$home目录
. 匹配一个字符
grep "." fileName
^ 表示以一个字符或者字符串开头匹配的行
grep "^[0-9]" fileName 以一个数字开头的行
$ 表示以一个字符或者字符串匹配结尾
grep "^abc*" fileName 以字符串abc开头的行
[] 含有此括号内的任何一个字符
grep "^[A-Za-z0-9]" fileName 匹配一个字母或者数字开头的
\{\} 字符匹配的个数
grep "^A\{2\}B" 匹配一个以二个A开头的并且以B结尾的
grep "A\{2,4\}B" 匹配一个含有二个A并且4个以内的A开头的并且以B结尾的字符串
$0 脚本的名字
$1 传入方法的第几个参数值
$# 传入方法的参数的个数
$* 所有参数
$$ PID
$? 返回值
$@ 跟$*类似当作数组用
18.alias [自定义]=‘[源]' | /bin/目录下
-eq 数值相等。 -ne 数值不相等。 -gt 第一个数大于第二个数。 -lt 第一个数小于第二个数。
-le 第一个数小于等于第二个数。 -ge 第一个数大于等于第二个数
19.条件判断一些记录
if [ ! -x "$myfile"];//是否具有可执行权限
[ ! -d "$myPath"];//目录是否存在
[ ! -f "$myFile" ]; //文件是否存在
[ ! -n "$myVar" ]; 变量是否有值
if [ "$var1" = "$var2" ]; 两个变量是否相等
-a file exists.
-b file exists and is a block special file.
-c file exists and is a character special file.
-d file exists and is a directory.
-e file exists (just the same as -a).
-f file exists and is a regular file.
-g file exists and has its setgid(2) bit set.
-G file exists and has the same group ID as this process.
-k file exists and has its sticky bit set.
-L file exists and is a symbolic link.
-n string length is not zero.
-o Named option is set on.
-O file exists and is owned by the user ID of this process.
-p file exists and is a first in, first out (FIFO) special file or
named pipe.
-r file exists and is readable by the current process.
-s file exists and has a size greater than zero.
-S file exists and is a socket.
-t file descriptor number fildes is open and associated with a
terminal device.
-u file exists and has its setuid(2) bit set.
-w file exists and is writable by the current process.
-x file exists and is executable by the current process.
-z string length is zero.