Home  >  Article  >  Operation and Maintenance  >  Linux Basics Series 2

Linux Basics Series 2

步履不停
步履不停Original
2019-06-19 15:53:263207browse

Linux Basics Series 2

##Commonly used commands

alias (alias)

In the

Linux basics series One of the mentioned 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'
Use

alias alias = command string to take effect in the current session. If you want it to take effect all the time, please add at 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=&#39;alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde&#39; [root@hadoop001 ~]# ul [root@hadoop001 local]# pwd /usr/local
Environment variables

    Global environment variables /etc/profile in Linux is a global variable. No matter which user you log in with, you can use all variables in this file. Following the previous section on how to set alias in global environment variables, add the following code at the end of the file.
  1. #env alias ul=&#39;cd /usr/local&#39;
  2. Of course, adding code is not enough. You must make global variables effective. You can use the following commands.
. /etc/profile 或者 source /etc/profile

    Personal environment variables only For individual users, the storage path is in
  1. ~/.bash_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=&#39;cd /root/xxx&#39;
  2. To make it effective, it is also the above two.
. ~/.bash_profile    . ~/.bashrc 或者 source ~/.bash_profile    source ~/.bashrc

rm (delete)

Generally, rm -rf file name is used. This method will force the file or folder to be deleted.

-f means forced, -r means OK folder

. 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
history (command record)

history -c is to clear the command record. Of course, when an individual user logs in, ~/.bash_history will also record commands, so if you want to clear it, remember to also clear it Delete it.

User/User Group Command Collection

    useradd username==>Add a user, its home directory is in /home/username
  1. id username==>Show user and user group information
  2. [root@hadoop001 ~]# id dengdi uid=1001(dengdi) gid=1001(dengdi) groups=1001(dengdi) 用户ID             主组ID           所有组
    1. cat /etc/passwd==>Show all User information
    2. dengdi(用户名):x:1001(用户id):1001(主组id)::/home/dengdi(家目录):/bin/bash(执行解释器)   如果/bin/bash变成/bin/false或者/sbin/nologin,这个用户就不能登陆了
      userdel username==>Delete user Deleting a user will delete the /etc/passwd record; At the same time, if there are no other users in the group , then delete the group but the home directory is still there, but the user and user group have changed
    1. [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
      Execute userdel and then useradd
    1. [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
    2. Let’s see what the skel directory prompted by the system is. We ll -a /home/dengdi
    [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) 这里重新指定主组之后,会丢失原来的主组

      Respecify the user's home directory
    1. usermod -d 路径 用户 或者 vi /etc/passwd
      Switch user
    1. su ruoze   切换用户 当前路径不会变,就是切换之前的路径 su - ruoze 切换用户 且切到该用户的家目录,且执行环境变量文件生效
    ##passwd user==>Set password or reset password

    For more Linux articles, please visit the Linux Tutorial column 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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:Linux Basics Series 1Next article:Linux Basics Series 1