Notes: Linux regular operations

Linux directory structure: There is only one directory, the root directory
poweroff: linux shutdown command
usr: equivalent to program files
etc: storing system configuration files
root: system administrator default directory
home: storing other users' directory
pwd: printing current directory
cd /: Switch to the root directory
ll: view the contents of the current directory
touch 1.txt: create a file 1.txt in the current directory to
get ip: ifconfig
clear: clear the screen

View the directory structure
list: list
-a: list all files, together with hidden files (files starting with .) (commonly used)
-d: only list the directory itself, not the file data in the directory (commonly used )
-l: List long data strings, including file attributes and permissions, etc.; (commonly used)

ll: List file information
in the current directory ls -al: List file information in the current directory (including hidden files, special directories)
ll /bin/: List file information in the bin directory under the root directory

The result of the man command is output to the file and saved
#xcodebuild is the command to be viewed
#xcbd.txt is the saved file name
man xcodebuild | col -b> xcbd.txt

Switch directory command cd Abbreviation of Change Directory
cd ~: return to your home directory
cd /
cd -: return to the last working directory
cd …: means to go to the current upper-level directory
cd

Create directory
-m: configure file permissions! Direct configuration, no need to look at the face of the default permissions (umask)~
-p: help you directly recursively create the required directories (including the upper-level directories)!

mkdir a: create a folder under the current directory a
mkdir /root/b: create a directory under the root under the root directory b
mkdir -pv /root/c/e/d: create a directory structure under the root under the root c/ e/d

Delete the empty directory
rmdir [-p] Directory name
-p: delete the "empty" directory together with the upper level

When the file browse command
nl is displayed, output the line number by the way!
nl [-bnw] File
-b: Specify the way to specify the line number, there are two main ways:
-ba: indicates that the line number is also listed regardless of whether it is a blank line (similar to cat -n);
-bt: if it is available Line, the empty line do not list the line number (default value);
-n: List the line number representation methods, there are three main ways:
-n ln: The line number is displayed on the far left of the screen;
-n rn: The line number is displayed on the far right of its own field, and 0 is not added;
-n rz: the line number is displayed on the far right of its own field, and 0 is added;
-w: the number of digits occupied by the line number field.

head only look at the first few lines
head [-n number] File
-n: followed by a number, which means to display a few lines

cat command: If there is little content in the file, the
cat /root/file name can be displayed within one page

More command: If there is a lot of content in the file, the
more file name will not be displayed within one page.
Space key (space): means turning down one page;
Enter: turning down "one line";
/string: representing this Among the displayed content, search down for the keyword "string";
:f: display the file name and the number of lines currently displayed
immediately ; q: leave more immediately and no longer display the content of the file.
b or [ctrl]-b: It means to page back, but this action is only useful for files, not for pipelines.

Less command: If there is a lot of content in the file,
less can be displayed within one page -mN File name
Blank key: scroll down one page;
[pagedown]: scroll down one page;
[pageup]: scroll up one page;
/String: the function to search "string" downwards;
?string: the function to search "string" upwards;
n: repeat the previous search (related to / or ?!)
N: repeat the previous search in reverse (Related to/or?!)
q: leave the less program;
less has more search functions than more

tail command: view the content at the end of the file
tail [-n number] file
tail -10 /root/install.log view the last 10 lines in the install.log file

The wc command is used to count the word count.

Using the wc command, we can calculate the number of bytes, words, or columns of the file. If the file name is not specified, or the given file name is "-", the wc command will read data from the standard input device.
Syntax
wc [-clw][–help][–version][File...]
Parameters:
-c or -bytes or -chars Only display the number of bytes.
-l or -lines only display the number of lines.
-w or -words only display the number of words.
--Help Online help.
-Version Display version information.
File management
Copy files
cp install.log install02.log
cp -b install.log install02.log: If you overwrite the file, you can make a backup of the source file
cp ./install.log …/: Copy the install.log in the current directory Copy to the parent directory
cp /root/install.log /bin/1.txt: Copy the install.log file under /root to 1.txt under the bin directory under the root directory

Copy directory (either single-level directory or multi-level directory can be copied):
cp -r ./a ./b
cp -r /root/a /root/z

mv cut the file
mv /root/install.log /root/a/

Rename the file
mv /root/install.log /root/test.log

Delete file
rm -f file name
rm -f /root/file name

Delete the directory
rm -rf directory name
rm -rf /root/ directory name

Search for files/directories in a certain directory
find /root/ -name'in*': Search for files/directories that contain in and start with in in the root directory under the root directory

The function of which command is to search for the location of a system command in the path specified by the PATH variable and return the first search result. In other words, by using the which command, you can see whether a certain system command exists and where the command is being executed.Insert picture description here

User and user group management

To add a new user account, use the useradd command to
add a user account is to create a new account in the system, and then allocate resources such as user number, user group, home directory, and login Shell for the new account. The account just added is locked and cannot be used.
useradd option username
Parameter description:
option:
-c comment Specify a commentary description.
The -d directory specifies the user's home directory. If this directory does not exist, use the -m option to create a home directory.
-g user group specifies the user group to which the user belongs.
-G user group, user group specifies the additional group to which the user belongs.
-s Shell file specifies the user's login shell.
-u user number specifies the user number of the user, if there is also the -o option, you can reuse the identification number of other users.
Username:
Specify the login name of the new account.

Delete account
userdel option user name The
commonly used option is -r, its function is to delete the user's home directory together.

Modify account
usermod options.
Commonly used options for user names include -c, -d, -m, -g, -G, -s, -u, and -o. The meaning of these options is the same as the options in the useradd command. They can be users Specify the new resource value.

User password management
Available options:

-l Lock the password, that is, disable the account.
-u Password unlock.
-d Make the account no password.
-f Force the user to change the password the next time they log in.
If the default user name is, modify the current user's password.

The grep command is used to search for qualified strings in a file.

The grep command is used to find a file whose content contains the specified template style. If the content of a file is found to conform to the specified template style, the default grep command will display the column containing the template style. If no file name is specified, or the file name given is -, the grep command will read data from the standard input device.
Syntax
grep [-abcEFGhHilLnqrsvVwxy][-A<number of columns to display>][-B<number of columns to display>][-C<number of columns to display>][-d<action>][-e<template style>][ -f<template file>][–help][template style][file or directory...]
Parameters:
-a or --text: Do not ignore binary data.
-A<number of lines to display> or --after-context=<number of lines to display>: In addition to displaying the column that conforms to the template style, the content after the line is displayed.
-b or --byte-offset: Before displaying the line that conforms to the style, mark the number of the first character of the line.
-B<number of lines to display> or --before-context=<number of lines to display>: In addition to the line that conforms to the style, the content before that line is displayed.
-c or --count: Count the number of columns matching the style.
-C<number of display lines> or --context=<number of display lines> or -<number of display lines>: In addition to the line that conforms to the style, the content before and after that line is displayed.
-d <action> or --directories=<action>: When you specify that you want to find a directory instead of a file, you must use this parameter, otherwise the grep command will report information and stop the action.
-e<template style>
-E or --extended-regexp: Use the extended regular expression style.
-f<rule file> or --file=<rule file>: Specify a rule file whose content contains one or more rule patterns. Let grep find the content of the file that meets the rule conditions. The format is one rule pattern per line.
-F or --fixed-regexp: Treat styles as a list of fixed strings.
-G or --basic-regexp: Use the style as a normal notation.
-h or --no-filename: Before displaying the line that conforms to the style, do not mark the name of the file to which the line belongs.
-H or --with-filename: Before displaying the line that conforms to the style, it indicates the name of the file to which the line belongs.
-i or --ignore-case: Ignore the difference in character case.
-l or --file-with-matches: List the names of files whose content matches the specified pattern.
-L or --files-without-match: List file names whose contents do not conform to the specified pattern.
-n or --line-number: Before displaying the line that conforms to the style, mark the column number of the line.
-o or --only-matching: Only display the matching pattern part.
-q or --quiet or --silent: Do not display any information.
-r or --recursive: The effect of this parameter is the same as specifying the "-d recurse" parameter.
-s or --no-messages: Do not display error messages.
-v or --invert-match: Display all lines that do not contain matching text.
-V or --version: Display version information.
-w or --word-regexp: Only display all-character columns.
-x --line-regexp: Only display all columns that match.
-y: The effect of this parameter is the same as specifying the "-i" parameter.

Linux system user group management To
add a new user group, use the groupadd command. The format is as follows:
groupadd option user group The
available options are:
-g GID Specifies the group identification number (GID) of the new user group.
-o is generally used together with the -g option to indicate that the GID of the new user group can be the same as the GID of the existing user group in the system.

To delete an existing user group, use the groupdel command, the format is as follows:
groupdel user group

Use the groupmod command to modify the attributes of a user group. The syntax is as follows:
groupmod option user group
Commonly used options are:
-g GID specifies a new group identification number for the user group.
-o and -g options are used together, the new GID of the user group can be the same as the GID of the existing user group in the system.
-n new user group changes the name of the user group to a new name

If a user belongs to multiple user groups at the same time, the user can switch between user groups to have the permissions of other user groups.
After logging in, the user can use the command newgrp to switch to another user group. The parameter of this command is the destination user group. For example:
$ newgrp root
This command switches the current user to the root user group, provided that the root user group is indeed the main group or additional group of the user. Similar to the management of user accounts, the management of user groups can also be done through integrated system management tools.

Guess you like

Origin blog.csdn.net/weixin_46083166/article/details/105472035