linux实用却易被忽略的指令
cd -
切换到上一次目录
cd ../
切换到上一层目录
ls -l -a
查看隐藏文件,文件或文件夹以.开头
ls -l -h
查看文件的大小,非文件夹
ls -l -rt
查看文件,按照时间顺序 ,加r是最近的在下面
touch xxx
直接创建一个空的文件
more xxx
查看文件,空格翻下,b翻上
cat 1.log > 2.log 把1的内容覆盖2
echo “asd” >> 1.log 把asd增加到1.log
alias asd='cd /root/asd'
设置快捷命令,然而是零时的,换一个窗口就不能用了。
如果想要设置全局,需要去/etc/profile
设置,然后source /etc/profile
生效
切换用户:su xxx 或者 su - xxx 区别在于切换后的路径不同
rm -rf
f指的是删除时不再询问,r是顺便删除文件夹
查看某命令的帮助文档:man xxx 详细
xxx --help 不详细但用的多
环境变量文件
全局: /etc/profile
source /etc/profile
个人: 家目录/.bash_profile
家目录/.bashrc
source 家目录/.bash_profile
. .bash_profile
bash_profile和bashrc的区别:
前者是交互式login方式运行
后者是交互式nologin方式运行
登录系统时获得的顶层shell,无论是通过本地终端登录,还是通过网络ssh登录。这种情况下获得的login shell是一个交互式shell。
在终端下使用--login选项调用bash,可以获得一个交互式login shell。
在脚本中使用--login选项调用bash(比如在shell脚本第一行做如下指定:#!/bin/bash --login),此时得到一个非交互式的login shell。
使用"su -"切换到指定用户时,获得此用户的login shell。如果不使用"-",则获得non-login shell。
要识别一个shell是否为login shell,只需在该shell下执行echo $0:
# echo $0
如果输出为该shell名字,加上一个‘-‘前缀,则说明该shell为login shell。
bash_profile 登陆只执行一次。
查看历史命令
history
用户和用户组命令
[root@hadoop000 ~]# 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 ~]# 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 ~]#
[root@hadoop000 ~]# useradd huhu
[root@hadoop000 ~]# id huhu
uid=503(huhu) gid=504(huhu) groups=504(huhu)
huhu用户 huhu用户组 同时huhu用户组为主组
[root@hadoop000 ~]# userdel huhu
[root@hadoop000 ~]#
[root@hadoop000 ~]# useradd huhu
useradd: warning: the home directory already exists.
Not copying any file from skel directory into it.
Creating mailbox file: File exists
[root@hadoop000 ~]# ll /home/
total 16
drwx------. 4 huhu huhu 4096 Sep 9 23:37 huhu
drwx------. 5 jepson jepson 4096 Sep 9 23:34 jepson
drwx------. 4 ruoze ruoze 4096 Sep 7 22:55 ruoze
drwx---r--. 4 rz rz 4096 Sep 9 23:25 rz
[root@hadoop000 ~]#
这里里面放的家目录路径等
[root@hadoop000 ~]# vi /etc/passwd
这就相当于把home/huhu放到了tmp,并且不让登陆,503和504是用户标识号和组标识号
huhu:x:503:504::/tmp:/bin/false
家目录修改
执行的命令类型
[root@hadoop000 ~]# cat /etc/group |grep huhu
huhu:x:504:
[root@hadoop000 ~]#
[root@hadoop000 ~]#
[root@hadoop000 ~]# groupadd boss
[root@hadoop000 ~]#
all,group
//-a相当于增加而不是直接修改 G是次要组
[root@hadoop000 ~]# usermod -a -G boss huhu
[root@hadoop000 ~]#
[root@hadoop000 ~]# id huhu
uid=503(huhu) gid=504(huhu) groups=504(huhu),505(boss)
[root@hadoop000 ~]#
//g是用户所属群组相当于所有
[root@hadoop000 ~]# usermod -g boss huhu
[root@hadoop000 ~]# id huhu
uid=503(huhu) gid=505(boss) groups=505(boss)
[root@hadoop000 ~]#
[root@hadoop000 ~]# usermod -a -G huhu huhu
[root@hadoop000 ~]#
[root@hadoop000 ~]# id huhu
uid=503(huhu) gid=505(boss) groups=505(boss),504(huhu)
[root@hadoop000 ~]#
passwd 重置用户密码