Linux user management, file management and common commands

User Management

basic introduction:

The Linux system is a multi-user and multi-tasking operating system. Any user who uses system resources must apply for an account from the system administrator, and then enter the system as this account.

Add user

  • useradd username

  • By default, the user's home directory is under /home/username

  • When the user is successfully created, the user's home directory will be automatically created

  • You can use useradd -d /home/test/username to specify where the new user is placed

Specify/change password

  • Basic syntax: passwd username

  • Display the directory where the current user is located: pwd

delete users

  • userdel username

  • User deletion is root authority

  • Delete the user, but keep the home directory: userdel username

  • Delete the user and the user's home directory: userdel -r username

  • In general, when deleting a user, keep the user's home directory, in case you leave and come back

Query user information

  • Basic usage: id username

Switch user:

  • If the current user permissions are insufficient, you can switch to a high-privilege user through the su + command

  • Basic usage su - switch username

View current user/login user

  • Basic usage: who am i

user group:

Similar to roles, the system can perform unified management on users with commonality/permissions

  • New group: groupadd group name

  • Delete group: groupdel group name

  • When adding a user, add the group directly: useradd -g user group username

  • Modify the user's group: usermod -g user group username

  • The relevant files of the user's group are under /etc. When you encounter them, search them yourself.

Practical instructions

Specify runlevel:

  • Runlevel description:

    • 0: shutdown

    • 1: Single user: retrieve lost password

    • 2: There is no network service in multi-user state

    • 3: Multi-user status has network services

    • 4: The system is reserved to the user for use

    • 5: Graphical interface

    • 6: System restart

    • The commonly used run levels are 3 and 5, and the default user level can also be specified

    • Switch between different run levels through init. Usually it is a switch between 3 and 5

    • How to modify the operation level and query the current user level to query by yourself

How to retrieve the root password (Centos7) (Han Shunping Linux Lecture 26)

Check it out yourself, hope to remember the password! ! ! It cannot be changed remotely, only to the local server

help command

  • man Get help information

    • Man ls Check the function of ls, of course, it is best to use Baidu

  • help Get information about shell built-in commands

    • help cd

file directory class

  • pwd displays the absolute path of the current directory

  • ls

    • ls -a displays all files and directories in the current directory, including hidden ones

    • ls -l displays information in a list

  • cd command

    • cd ~ back to your home directory

    • cd / back to the root directory

  • mkdir command

    • mkdir is used to create a directory mkdir /home/dog can only create a first-level directory

    • -p mkdir directory can be used to create multi-level directories

  • rmdir command

    • rmdir is used to delete empty directories

    • rmdir -rf Forcefully delete a directory, whether it is empty or not

    • rm -rf delete directory

  • touch command

    • touch hello.txt is used to create an empty file

  • cp

    • Copy the file to the specified file directory

    • Usage: cp [file] specify address

    • cp /home/hello.txt bbb/

    • Copy the entire directory of home/bbb to aaa: cp -r /home/bbb/ /home/aaa/ Copy the files in bbb to aaa recursively

    • \cp -r force overwrite without reminding

  • rm command

    • rm' removes a file or folder

    • rm -r deletes an entire folder recursively

    • rm -f Force delete without reminder

    • rm -rf combination

  • mv command (equivalent to cut)

    • Move or rename files and directories

    • mv old filename filename

    • mv filename (with directory) new folder

    • Move the entire directory mv bbb/ /home/

  • cat command

    • cat filename, read only

    • cat -n hello.txt View hello and display the number of lines

    • cat can only browse files. For convenience, the pipeline command | more is usually used to hand over the results obtained by cat to more for processing.

  • more command

    • It is a text filter based on the VI editor, which displays the content of the text file page by page in a full-screen manner. There are several shortcut keys built into the more command

    • more files to view

    • Instructions:

      1. Space bar: page down

      2. enter to turn down a line

      3. q leave more, no longer display content

      4. Ctrl + F Scroll down one screen

      5. ctrl + B to return to the previous bottle

      6. = output the current line number

      7. :f output filename and line number of current line

  • less instruction

    • Used to view file content in split screen

    • The basic grammar has been searched by myself, and it is very friendly to displaying large files

  • echo command

    • Output content to the console

    • echo option output

  • head

    • Used to view the beginning of the file

    • head -n 5 the first five lines of the file

  • tail command

    • for viewing the end of the file

  • > and >> directives
    • output redirection and >> append

    • echo hello > new.txt redirects the content entered into the terminal to new.txt, which is a kind of coverage

    • ls -l >> new.txt Append the content to new.txt without overwriting

  • In command

    • Soft links are also called symbolic links, similar to the shortcuts in Windows, which mainly store the path of linking other files

    • In -s source directory shortcut name

  • history

    • View executed historical commands

    • history view all

    • history 10 view the latest ten

    • !387 Execute the historical command numbered 387

Guess you like

Origin blog.csdn.net/weixin_68798281/article/details/131997009