##Commonly used commands alias (alias) In the
Linux basics series One of thementioned ls -l=ll, this is the alias in Linux, use alias to view the system default alias.
[root@hadoop001 ~]# alias alias cp='cp -i' alias egrep='egrep --color=auto' alias fgrep='fgrep --color=auto' alias grep='grep --color=auto' alias l.='ls -d .* --color=auto' alias ll='ls -l --color=auto' alias ls='ls --color=auto' alias mv='mv -i' alias rm='rm -i' alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'
alias alias = command stringto take effect in the current session. If you want it to take effect all the time, please addat the end of the environment variable file## Add the above command in #. Please see the next section for environment variables.
[root@hadoop001 ~]# alias ul='cd /usr/local' [root@hadoop001 ~]# alias alias cp='cp -i' alias egrep='egrep --color=auto' alias fgrep='fgrep --color=auto' alias grep='grep --color=auto' alias l.='ls -d .* --color=auto' alias ll='ls -l --color=auto' alias ls='ls --color=auto' alias mv='mv -i' alias rm='rm -i' alias ul='cd /usr/local' <-- 新增的 alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde' [root@hadoop001 ~]# ul [root@hadoop001 local]# pwd /usr/local
#env alias ul='cd /usr/local'
. /etc/profile 或者 source /etc/profile
. When you open this file, you will find that it actually involves another file~/.bashrc. So if you want to set alias, add the above code at the end of the two files.
# .bash_profile # Get the aliases and functions if [ -f ~/.bashrc ]; then . ~/.bashrc fi # User specific environment and startup programs #env alias rc='cd /root/xxx'
. ~/.bash_profile . ~/.bashrc 或者 source ~/.bash_profile source ~/.bashrc
rm (delete)
. What I often hear is rm -rf /*, which means to delete the library and run away. Of course, most people will not run it directly like this, but this error may occur in the shell script. The following scenarios lead to this situation.
shell脚本可能会这样 xxxpath=xxx/xx ...(逻辑部分) rm -rf $xxxpath/* 这里就是个坑 如果一空值赋予给了xxxpath,那么不就成了rm -rf /* 所以在生产上凡是碰见rm -rf强制删除文件夹的,路径一定先判断存在不,不存在 就skip;就存在就rm
User/User Group Command Collection
[root@hadoop001 ~]# id dengdi uid=1001(dengdi) gid=1001(dengdi) groups=1001(dengdi) 用户ID 主组ID 所有组
dengdi(用户名):x:1001(用户id):1001(主组id)::/home/dengdi(家目录):/bin/bash(执行解释器) 如果/bin/bash变成/bin/false或者/sbin/nologin,这个用户就不能登陆了
[root@hadoop001 ~]# ll /home/ total 0 drwx------. 3 centos centos 70 Jun 28 2017 centos drwx------ 2 1001 1001 59 Jun 17 23:48 dengdi
[root@hadoop001 ~]# userdel dengdi [root@hadoop001 ~]# useradd dengdi useradd: warning: the home directory already exists. Not copying any file from skel directory into it. Creating mailbox file: File exists
[root@hadoop001 ~]# ll -a /home/dengdi/ total 12 drwx------ 2 dengdi dengdi 59 Jun 17 23:48 . drwxr-xr-x. 4 root root 32 Jun 17 23:48 .. -rw-r--r-- 1 dengdi dengdi 18 Apr 11 2018 .bash_logout -rw-r--r-- 1 dengdi dengdi 193 Apr 11 2018 .bash_profile -rw-r--r-- 1 dengdi dengdi 231 Apr 11 2018 .bashrc
skel directory is all the hidden files in .bash*. Try to delete these and switch to the dengdi user.
[root@hadoop001 ~]# ll -a /home/dengdi/ total 16 drwx------ 2 dengdi dengdi 79 Jun 18 00:06 . drwxr-xr-x. 4 root root 32 Jun 17 23:48 .. -rw------- 1 dengdi dengdi 5 Jun 18 00:06 .bash_history -rw-r--r-- 1 dengdi dengdi 18 Apr 11 2018 .bash_logout -rw-r--r-- 1 dengdi dengdi 193 Apr 11 2018 .bash_profile -rw-r--r-- 1 dengdi dengdi 231 Apr 11 2018 .bashrc [root@hadoop001 ~]# rm -rf /home/dengdi/.* rm: refusing to remove ‘.’ or ‘..’ directory: skipping ‘/home/dengdi/.’ rm: refusing to remove ‘.’ or ‘..’ directory: skipping ‘/home/dengdi/..’ [root@hadoop001 ~]# ll -a /home/dengdi/ total 0 drwx------ 2 dengdi dengdi 6 Jun 18 00:08 . drwxr-xr-x. 4 root root 32 Jun 17 23:48 .. [root@hadoop001 ~]# su - dengdi Last login: Tue Jun 18 00:07:26 CST 2019 on pts/0 -bash-4.2$
So the skel directory determines whether your [root@hadoop001 ~] or -bash-4.2$ 6. groupadd user group==> add new user group usermod -a -G user group dengdi==> ;Add a new member of the user group as dengdi usermod -g user group dengdi==>Modify xxx as the main group
[root@hadoop001 ~]# groupadd bigdata [root@hadoop001 ~]# id ruoze uid=501(ruoze) gid=501(ruoze) groups=501(ruoze) [root@hadoop001 ~]# usermod -a -G bigdata ruoze [root@hadoop001 ~]# id ruoze uid=501(ruoze) gid=501(ruoze) groups=501(ruoze),502(bigdata) [root@hadoop001 ~]# usermod -g bigdata ruoze [root@hadoop001 ~]# id ruoze uid=501(ruoze) gid=502(bigdata) groups=502(bigdata) 这里重新指定主组之后,会丢失原来的主组
usermod -d 路径 用户 或者 vi /etc/passwd
su ruoze 切换用户 当前路径不会变,就是切换之前的路径 su - ruoze 切换用户 且切到该用户的家目录,且执行环境变量文件生效
For more Linux articles, please visit theLinux Tutorialcolumn to learn!
The above is the detailed content of Linux Basics Series 2. For more information, please follow other related articles on the PHP Chinese website!