Linux Command Shorthand

Source: Internet
Author: User
Keywords linux linux sentence linux commands

The Linux command line is a text interface to your computer. Often referred to as the shell, terminal, console, prompt or various other names. 

vim editor

There are 3 common modes of vim:

Normal mode
Insert mode
Command line mode
Normal mode: cursor can be moved, copied and pasted, deleted, etc.

vim filename.xxx # If not, open after creation, and open directly after opening and enter normal mode
yy # copy the current line
5yy #copy the next 5 lines
p # paste
dd # delete the current line
5dd # delete the next 5 lines
:set nu # set line number
:set nonu # cancel line number
G # come to the end
gg # Back to the first line
u # undo the operation just now


shift + g # Move the cursor to the tenth line

:wq # save and exit
:q! # Force exit (do not save the changes just now)
:q # If you have not edited after opening, you can exit like this, otherwise you can only use wq and q!
When opening the file, it is in normal mode, press i to enter insert mode (editable).
To return to normal mode from insert mode, press the ESC key.
Press: from normal mode to command line mode.
When vim pastes the code, the format is disordered. How to do?

:set paste # enter paste mode

Then press i to paste it. It should be noted that you need to exit the paste mode after pasting.

:set nopaste # Exit paste mode

How to find it with vim?
Press / in the normal mode, and then input the character string you want to find.
For example, if you want to find eg in a file, just:

/eg

Commands such as boot and restart
shutdown -h now # Shut down immediately
shutdown -h 1 # Shut down after 1 minute
shutdown -r now # restart now
halt # Shut down directly
reboot # reboot the system
sync # Flash the data in the memory to the hard disk

User switching and logout
su user name # just switch the user, will not change the original user's working directory and other environment variable directories
su-vth # Switch to the vth user, and switch the working directory and other environment variable directories to vth.
#Previous, the working directory is switched to /home/vth
sudo su # Authorize root privileges to the current user without switching the working directory. Only need to enter the current user's password.
# But this method requires the root user in the /etc/sudoers file
# root ALL=(ALL) ALL Copy a line and replace root with the username. This file is read-only,
# If you want to modify, you can raise the right.
su-xm # Switch to user Xiaoming
logout # Logout user in run level 3
exit # Exit the current user
su, sudo, su-xxx comparison:
If you have su, you have root privileges, without changing the directory and environment variables, and you must enter the password when switching.
su-xxx # For low-level to high-level, you need to enter a password, change the directory and environment variables.
sudo su # You only need to enter the current user's password when executing. But make sure to add the current stuff in /etc/sudoers

User Management
Linux users must belong to at least one group. If the group is not specified when adding the user, then it is a group by itself.

useradd xm # add user xm
useradd -d /home/dog xm # Add user xm and set the home directory to /home/dog
useradd -g xmzu xm # Create xm user and add it to the xmzu user group
# Note that the statement above must first exist in the xmzu group, otherwise it cannot work.
usermod -g shaolin xm # Change the group to which user xm belongs to shaolin
# Note that the above statement must exist in the shaolin group first, otherwise it will not work.
passwd xm # root user changes the password to xm
Note that the prompt is $ for ordinary users, # for root users
userdel xm # Delete the xm user, but keep the home directory it created
userdel -r xm # Delete the xm user and the home directory it created # Destroy the roots
id xm # View user information
When switching users with su-root, exit can return to the original user.
There is no need to enter a password when changing from a user with high authority to a user with low authority, and vice versa.
groupadd wudang # Create wudang group
groupdel wudang # Delete the wudang group. Note that you cannot delete the wudang group when there are members
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.