1、查看用户信息 :id username
第一列为用户名,第二列为所属主用户组,每个用户有唯一一个所属主组,第三列为所属所有用户组列表
[root@hadoop002 etc]# id jepson
uid=500(jepson) gid=500(jepson) groups=500(jepson)
2、查看当前所在路径:pwd
[root@hadoop002 etc]# pwd
/etc
3、家目录路径:~
普通用户:/home/xxx
root用户:/root
4、切换路径:cd
cd 相对/绝对路径
切换到家目录:cd ~ 或者 cd 空格
[root@hadoop002 etc]# cd
[root@hadoop002 ~]# cd ~
[root@hadoop002 ~]#
回撤到上次所在路径:cd -
[root@hadoop002 jepson]# cd -
/root
[root@hadoop002 ~]# pwd
/root
切换到上层路径:cd ..
5、清空屏幕:clear
6、显示目录所有文件以及文件夹:ls
显示所有文件详细信息:ll -h #ll为ls -l的缩写,文件的-h显示大小不准确
显示所有文件加隐藏文件详细信息:ll -a
[root@hadoop002 ~]# ll -a
total 232
dr-xr-x---. 27 root root 4096 Jan 25 19:05 .
dr-xr-xr-x. 26 root root 4096 Jan 25 18:10 ..
按修改时间排序显示文件信息:ll -rt
drwxr-xr-x. 2 root root 4096 Jan 25 16:33 Videos
drwxr-xr-x. 2 root root 4096 Jan 25 16:33 Templates
drwxr-xr-x. 2 root root 4096 Jan 25 16:33 Public
drwxr-xr-x. 2 root root 4096 Jan 25 16:33 Pictures
7、查看本机的IP:Linux是ifconfig,windows是ipconig
[root@hadoop002 ~]# ifconfig
eth0 Link encap:Ethernet HWaddr 00:0C:29:3F:B1:2C
inet addr:192.168.153.131 Bcast:192.168.153.255 Mask:255.255.255.0
8、创建目录: mkdir
创建单级目录:mkdir a
创建层级目录:mkdir -p a/b/c
创建并行目录:mkdir a b c
9、移动文件:mv
移动文件或文件夹: mv 源路径 目标路径 #移动时可以更改文件的名字
10、复制文件:cp
复制文件:cp 源文件 目标文件 #移动时可以更改文件的名字
复制文件夹: cp -r 源文件夹 目标文件夹 #移动时可以更改文件夹的名字
11、查看命令帮助: XXX --help
Usage为命令使用列子,[option] 表示为可选参数
[root@hadoop002 ~]# ll --help
Usage: ls [OPTION]... [FILE]...
List information about the FILEs (the current directory by default).
Sort entries alphabetically if none of -cftuvSUX nor --sort.
Mandatory arguments to long options are mandatory for short options too.
-a, --all do not ignore entries starting with .
-A, --almost-all do not list implied . and ..
12、查看文件: cat 、more 、less、tail
cat 文件:文件内容一下全部显示刷在屏幕上,适合查看小文件
more 文件: 空格键下翻页,b键上翻页,enter键一行行翻,q退出
less 文件:上翻行是上箭头,下翻行是下箭头,q退出
tail -300f 文件:实时监控文件尾部内容,但是文件删除重建后无用
tail -F 文件:实时监控文件尾部内容,但是文件删除重建后也可继续监控,F = f+retry
13、内容覆盖:> ,内容追加:>>
[root@hadoop002 ~]# echo "wsktest2" >> install.log20190125
[root@hadoop002 ~]# tail -2f install.log20190125
*** FINISHED INSTALLING PACKAGES ***wsktest
wsktest2
[root@hadoop002 ~]# echo "wsktest3" > install.log20190125
[root@hadoop002 ~]# cat install.log20190125
wsktest3
[root@hadoop002 ~]#
14、输出打印:echo
[root@hadoop002 ~]# echo ${PATH} #${变量A}:获取变量A的值
/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
[root@hadoop002 ~]#
15、移动比复制快
16、别名: alias
查询显示所有别名:alias
[root@hadoop002 ~]# alias
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'
设置别名:alias wsktest='cd /root'
[root@hadoop002 ~]# alias wsktest='cd /root'
[root@hadoop002 ~]# wsktest
[root@hadoop002 ~]# cd /usr/
[root@hadoop002 usr]# wsktest #但是只能对当前session有效,复制的窗口是无效的
[root@hadoop002 ~]#
17、永久的环境变量文件:该文件中的配置是session永久有效
全局环境变量文件:/etc/profile
个人环境变量文件: ~/.bash_profile 与 ~/.bashrc
设置别名永久生效: vi /etc/profile ; 编辑;编辑后 source /etc/profile
17、创建文件:touch
[root@hadoop002 ~]# touch newFIle
[root@hadoop002 ~]# ll newFi*
ls: cannot access newFi*: No such file or directory
[root@hadoop002 ~]# ll newF*
-rw-r--r--. 1 root root 0 Jan 25 20:56 newFIle
19、文件删除:rm
强制删除文件:rm -f 文件
强制删除文件夹:rm -rf 文件夹
模糊匹配删除:rm -rf ./log* #强制删除当前文件夹下log开头的所有文件文件夹
rm是高危命令,禁止任何情况下 rm -rf /*发生 ,删库是要跑路的
20、shell编程:设置变量
[root@hadoop002 ~]# wskbl=哈哈 #=两边不能有空格
[root@hadoop002 ~]# echo ${wskbl} #${} 使用变量
哈哈