The author uses AliYun server ECS and the image is Ubuntu. The detailed version information of Ubuntu is as follows: Ubuntu 18.04.4LTS (GNU/Linux 4.15.0-91-generic x86_64), how to buy a cloud server is beyond the scope of this article. If you are just learning, you can use VirtualBox to install Ubuntu.

#Connecting to the server
$ ssh <username>@<hostname>
#Updating system Sources
$ apt update
#Upgrading system Sources
$ apt upgrade
Copy the code

Required environment and application

Git

#Install git
$ apt install git
Copy the code

Command Line Configuration

# 1. Initialize Settings
$ git config --global user.name 'youngjuning'
$ git config --global user.email '[email protected]'
# 2. Setting 'color. UI' to 'auto' makes the output of the command more readable.
$ git config --global color.ui auto
Git remembers the username and password
$ git config --global credential.helper store
# 4, the core autocrlf
$ git config --global core.autocrlf input
Copy the code

Linux or Mac systems use LF as the line terminator, so you don’t want Git to automatically convert files when checking them out; For example, if a file ends at the end of a line (CRLF) then you might want to modify it by changing core. Trigger LF to input and then forcing Git to change CRLF to LF at commit and end at checkout: This preserves CRLF in checkout files on Windows systems, and IT preserves LF on Mac and Linux systems, including repositories.

Java

#Install jre and JDK
$ apt install openjdk-8-jre-headless openjdk-8-jdk-headless
Copy the code

Node

Node.js is a JavaScript runtime based on the Chrome V8 engine. We use the n module to maintain the version of Node:

$ apt install nodejs npm build-essential
$ sudo npm install -g npm n
#Install the latest version
$ sudo n latest
## Other commands ##
#Install the specified version
$Sudo n 10.16.0
#Install the latest stable version
$ sudo n lts
#Delete the specified version
$N the rm 12.10.0
#All cached versions except the current version
$ n prune
Copy the code

oh-my-zsh

After modifying ~/. ZSHRC, run the source ~/. ZSHRC command for the modification to take effect immediately

Echo $SHLL Displays the current Shell

  • apt install zsh
  • git clone https://github.com/robbyrussell/oh-my-zsh.git ~/.oh-my-zsh
  • `cp ~/.oh-my-zsh/templates/zshrc.zsh-template ~/.zshrc
  • nano ~/.zshrc
  • findZSH_THEME="robbyrussell",robbyrussellReplace withys
  • Change the default Shell:chsh -s /bin/zsh
  • Command highlighted
    • git clone https://github.com/zsh-users/zsh-syntax-highlighting.git "$HOME/.zsh-syntax-highlighting" --depth 1
    • echo "source $HOME/.zsh-syntax-highlighting/zsh-syntax-highlighting.zsh" >> "$HOME/.zshrc"
  • Re-open the command line
  • echo "export EDITOR=nano" >> ~/.zshrc

vim

You are advised to use github.com/amix/vimrc

$ git clone --depth=1 https://github.com/amix/vimrc.git ~/.vim_runtime
$ sh ~/.vim_runtime/install_awesome_vimrc.sh
$ echo "set number" >> ~/.vimrc
$ echo "set showcmd" >> ~/.vimrc
$ source ~/.vimrc
Copy the code

directory

  • /
    • bin: contains executables that are used by all users
    • boot: contains files closely related to Linux startup
    • dev: contains peripherals. It has subdirectories, each of which corresponds to a peripheral
    • etc: contains the system configuration file
    • home: Indicates the user’s private directory
    • lib: contains the library file called by the program, for example.soClosing document
    • media: Removable peripherals (USB disk, SD card, DVD, CD, etc.) inserted into the computer
    • mnt: Used to mount some devices temporarily
    • opt: An optional application software package used to install most third-party software and plug-ins
    • root: home directory of superuser root
    • sbin: Used to contain system-level important executables
    • srv: contains data to be retrieved after the network service is started
    • tmp: a place where ordinary users and programs store temporary files
    • usr: Unix Software Resource, which installs most of the programs that users want to call
    • var: usually contains program data, such as log files

Common commands

Linux command search engine: git. IO/Linux

  • reboot: Restarts the running Linux operating system
  • halt: Shut down the system
  • shutdown: Command to shut down the system. The shutdown command can shutdown all programs, and restart or shutdown as required by the user.
  • poweroff: Direct operation can be shut down
  • history: Displays the history command
  • whice: Finds and displays the absolute path to the given command
  • pwd: Displays the current working directory. (Print Working Directory)
  • source: Reads and executes commands from the specified file in the current Shell environment, making the file changes effective immediately.
  • updatedb: Creates or updateslocateThe database file required for the command
  • uname -a: Displays information about all Linux systems
  • cat /proc/version: Displays Linux information
  • cat /etc/lsb-release: View distribution information
  • echo $SHELL: Current shell
  • service <service> force-reload|reload|restart|start|status|stop
  • systemctl start|stop|restart|status|reload:
    • enable: The service automatically starts upon startup
    • disable: The service does not automatically start upon startup
    • is-enabled: Check whether the service automatically starts upon startup
    • list-unit-files --type=service: Displays the starting and disabling status of services at different levels

File management

File directory operation

  • Ls: displays the directory list

    • -a: Lists all files, including implied files starting with “.”.
    • -l: In addition to each file name, you can add information about the file type, permission, number of hard links, owner name, group name, size (byte), and time (if no other time is specified, it indicates the time of modification)llInstead of
  • Du: displays Disk Usage for each file and directory.

    • -aor-all: Displays the size of individual files in a directory.
    • -hor--human-readable: Improves the readability of information in units of K, M, and G.
    • -sor--summarize: Displays only the total value and lists only the final sum.
  • Cat-n: Connect multiple files and print to standard output. (concatenate)

  • less -N

    • Space bar: Forward one page (one screen)
    • B key: Back one page (one screen)
    • D key: Forward half page (half screen)
    • U key: Back half page (half screen)
    • Enter key/E key/Down arrow: Forward one line
    • Y key/up arrow: Back one line
    • Q key: Stops reading files and stops the less command
    • = key: show where you are in the file
    • / key: enter the search mode
      • N key: jumps to the next match
      • Shift + N: Jumps to the previous match
  • Head: Displays the beginning of the file

  • Tail: Displays the last lines of a specified file on the screen

    • -f: Displays the latest content added to the file.
    • The -s < number of seconds >And:-fOption to specify the number of seconds to monitor file changes. Default is 1 second
  • Touch: Creates a new empty file

  • Mkdir: used to create directories

    • -por--parents: If the upper-layer directory to be created has not been created, the system will create the upper-layer directory as well
  • Cp: Copies the source file or directory to the destination file or directory

    • -ror-R: Recursive, processing all files in a specified directory along with subdirectories, recursive
  • Mv: renames a file or directory

  • Rm: used to delete a given file or directory

    • -ror-R: Recursive, processing all files in a specified directory along with subdirectories, recursive
    • -f: Deletes files or directories forcibly
  • Ln: used to create links for files

    • Hard link defects: Generally, you can only create hard links pointing to files, but not to directories
    • A hard link is one that uses the sameinodeNumber, but the file name is different
    • ls -i: displayinodeNo.
    • -s.--symbolic: Creates symbolic links to source files instead of hard links
  • Locate: a file search tool that is easier to use than find. It must be used together with UpdatedB

  • Find: finds files in the specified directory

    1. What do you find?

    • -name < template style > : specifies a string as the template style to find files or directories

    • -size < file size > : searches for files that match the specified file size

    • -type < file type > : searches for files that match the specified file type.

      • F Common files
      • L sign connection
      • D directory
      • C character device
      • B block device
      • S a socket
      • p Fifo
    • -atime <24 hours > : searches for files or directories that have been accessed at a specified time, expressed in 24 hours.

    • -exec < execute instruction > : Execute the find instruction if the return value of the find instruction is True

      find . -name *.txt -exec chmod 600 {} \;

      You can replace it with -ok,ok will let you confirm the operation

Rights management

  • Sudo su: Switch the root identity to substitute do

  • Useradd -m: The new system user created automatically creates the user’s home directory

  • Passwd: allows users to change their passwords

  • ‘userdel -r: Used to delete the given user and the files associated with the user

  • Users: displays all users currently logged in to the system

  • Usermod: Used to modify basic user information

    • -l: Renames a user./homeThe user home directory name in the
    • -g: Modifies the group to which a user belongs
    • -G: Adds users to multiple groups.segmentation
    • -aG-ag: Enter a new group without leaving the original group
  • Groupadd: Used to create a new workgroup

  • Groups: Prints the workgroup to which the specified user belongs

  • Chown: used to change the owner or group of a file or directory

    chown <username>[:gruop] <file|dir>

    • -R: recursive processing, all files and subdirectories in a specified directory are processed together
  • CHGRP: used to change the owning group of a file or directory

  • Chmod: used to change the permission of a file or directory

    The first bit indicates the file type, the second to fourth bits indicate the read, write, and execute permissions of the owner, the fifth to seventh bits indicate the read, write, and execute permissions of the same group of users, and the eighth to tenth bits indicate the read, write, and execute permissions of other users. Use – placeholder if you do not have permission. If SELinux is enabled, there will be one more in the 11th place.

    • The file type
      • d: Abbreviation of directorydirectory
      • l: short for linklink
      • -: file
    • r: Short for readread
    • w: Indicates the abbreviation of Writewrite
    • x: indicates the abbreviation of executeExecute/run. You can run this file
    • .: Security label for SELinux, if the 11th bit has one.“Indicates that SELinux is enabled
    • Assign permissions by numbers

      • No permission: 0
      • Execute permission: 1
      • Write permission: 2
      • Write execution permission: 3
      • Read permission: 4
      • Read execution permission: 5
      • Read and write permission: 6
      • Read/write execution permission: 7
    • Use letters to assign permissions

      • U: Short for user, which means “user” in English. Represents the owner
      • G: Group. Group user
      • O: Other is short for other in English. Indicates other users
      • A: Short for all, it means all in English. Represents all users
      • + : the plus sign indicates that the permission is added
      • – : the minus sign indicates the deletion of the permission
      • = : equal sign, indicating permission assignment

      Chmod u+rx file: The owner of file file has read and run permissions

      Chmod g+r file: indicates the group of file file. Add the read permission to other users

      Chmod o-r file: deletes the read permission for file file from other users

      Chmod g+r o-r file: indicates the group of file file. Add the read permission to other users and remove the read permission to other users

      Chmod go-r file: indicates the group of file file. Remove the read permission of other users and other users

      Chmod +x file: Grants the running permission to all users of file file

      Chmod u= RWX,g=r,0= -file: the owner of file allocates read, write, and execute permissions. Other users in the group have been assigned read permission but cannot write or execute data. Other users do not have any permissions

Regular expressions and data manipulation

Grep: Filters data

Grep (Global Search Regular expression(RE) and print out the line) is a powerful text search tool. It can use regular expressions to search text. And print out the matching lines. A specific character used for filtering/searching. Regular expression can be used with a variety of commands, the use is very flexible.

  • -i --ignore-case: Ignores the difference in case of characters.
  • -n --line-number: Indicates the column number before displaying the column that matches the template style.
  • -v --revert-match: Reverse lookup.
  • -R/-r --recursive: Searches all subdirectories and subfilesrgrepalternative
  • -E --extended-regexp: Using the template style as an extended normal representation means using extended regular expressions. You can useegrepInstead of
    • grep -E ^p /etc/profile
    • grep -E [at] /etc/profile
    • grep -E [0-4] /etc/profile
    • grep -E [a-zA-Z] /etc/profile

Regular expression

^ # Anchor line start like '^grep' matches all lines starting with grep.$    'grep$' matches all lines ending with grep.# matches a non-newline character such as 'gr.p' matches GR followed by any character, then p. * # matches zero or more previous characters such as '*grep' matches all lines followed by one or more Spaces. Use.* # together to represent any character. [] # match a specified range of characters, such as '[Gg]rep' match Grep and Grep. [^] # matches A character that is not in the specified range, for example: '[^ a-fh-z]rep' matches the beginning of A letter that does not contain a-r and t-z, following the line of rep. \ [.. \) # marks a match character, such as '\(love)', where love is marked as 1. \< # Anchors the beginning of a word, such as :'\<grep' matches lines that contain words starting with grep. \> # Anchor the end of a word, such as 'grep\>' matches a line that contains a word ending with grep. X \{m\} # repeats the character x, m times, such as: '0\{5\}' matches a line containing five O's. X \{m,\} # repeats the character x at least m times, such as: 'o\{5,\}' matches lines with at least five O's. X \{m,n\} # repeats the character x at least m times, but not more than n times, e.g. 'o\{5,10\}' matches lines with 5--10 o's. \w # matches literal and numeric characters, that is, [A-za-z0-9], as in: 'G\w*p' matches G followed by zero or more literal or numeric characters, followed by p. The inverted form of \W # \W matches one or more non-word characters, such as periods, etc. \b # word lock, such as '\bgrep\b' matches only grep.Copy the code

Sort file sort

Sorts all lines in a text file.

  • -o.--output=FILE: writes the result to FILE instead of standard output.sort -o name.txt name_sorted.txt
  • -r.--reverse: Put the results in reverse order.
  • -R:--random-sortSort randomly, but group the same rows.
  • -n.--numeric-sort: Sort by number.

The main purpose

  • Sort the contents of all input files and output them.
  • When there is no file or file for-, reads standard input.

Wc File Statistics

Count the number of lines, words, and bytes of a file

The wc command counts the number of bytes, words, and lines in the specified file and displays the statistics result. The WC command can be used to calculate the Byte count, word count, or column count of a 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. The WC also gives the presidential count of the specified file.

  • -c: Indicates the number of bytes counted, or--bytesor--chars: Displays only Bytes
  • -l: Statistics the number of rows, or--lines: Displays only the number of columns
  • -m: Indicates the number of characters. This mark cannot be associated with-cLogo used together
  • -w: Count the number of words, or--words: Displays only the word count. A word is defined as a string separated by whitespace, tabs, or newline characters
  • -L: Prints the length of the longest line

Uniq: deletes the duplicate content in the file

Duplicate lines are displayed or ignored. The uniq command is a bit “dumb” and can only convert consecutive repeated lines into a single line

  • -c.--count: Increase the number of repeats at the beginning of each line
  • -d.--repeated: Displays only the values of duplicate rows

The main purpose

  • Writes adjacent duplicate lines from an input file (or standard input) to an output file (or standard output).
  • When there are no options, adjacent duplicate rows are merged into one.

Cut: Cuts part of the file

Connect files and print to standard output devices

  • -c: Displays only the specified range of characters in the line,cut -c 2-4 file
  • -d: Specifies the field separator. The default field separator is TAB.
  • -f: Displays the contents of a specified field.Cut -d, -f 1,3 notes.csv;cut -d , -f 2- notes.csv

Output redirection

The black hole file /dev/null, which has a unique property, is always empty. It invalidates any data sent to /dev/null

>Redirect to a file

  • If the file does not exist, create a new one
  • If the file already exists, the contents of the file will be overwritten and the user’s consent will not be sought

>>Redirect to the end of the file

The function of >> is similar to >, but it is not as dangerous as >. It appends the redirected content to the end of the file. If the file does not exist, the file is created

2 >2 > >Redirect to standard error output

$ cat not_exist_file.csv > results.txt 2> errors.log
Copy the code

2 > &1Portfolio is meeting

  • Redirect standard error output to the same location as standard output
  • Cover:cat not_exist_file_csv > results.txt 2>&1
  • End append:cat not_exist_file_csv >> results.txt 2>&1

Stdin, stdout, stderr

  • Input data from the keyboard to the terminal. This is standard input, or STdin
  • When a terminal receives a command input from the keyboard, it produces two types of output
    • Standard output: stdout. Information output by a terminal (excluding error messages)
    • Standard error output: stderr. Error information output by the terminal

Input redirection

<Read from a file

  • cat notes.csv

    • catThe command accepts the notes.csv file name as input
    • So it opens the notes.csv file first
    • Then print out the contents of the file
  • cat < notes.csv

    • catThe command accepts input directly from the notes.csv file
    • catThe command simply prints its contents
    • Open the file and pass the file contents tocatThe command work is left to the terminal

<<Read from the keyboard

  • <<The symbol is used to redirect keyboard input to the input of a command
  • sort -n << END

|Pipe symbol

Take the output of one command as the input of another

  • The legendary “pipe symbol” :|
  • |Since the symbol is called a pipe character, its purpose is to build a command pipe.
  • Pipes are also a type of redirect stream
  • cut -d , -f 1 notes.csv | sort > sorted_names.txt
  • du -h | sort -n | head
  • sudo grep log -Ir /var/log | cut -d : -f 1 | sort | uniq
    • -I: Excludes binary files
    • -r: used for recursive traversal

Process and system monitoring

  • W: Displays the information of the current login user

  • Uptime: Displays the load information of the Linux system

    The ability to print how long the system has been running and the average load of the system. The uptime command displays the following information: current time, how long the system has been running, how many users have logged in, and the average load of the system in the past 1 minute, 5 minutes, and 15 minutes.

  • Tload: displays the system load status

    Graphically outputs the current system load average to a specified terminal. Assuming that no terminal number is given, the load state is displayed on the terminals where the tload instruction is executed

  • Who: displays information about current users

    The information about the current user is displayed. Executing the who command shows which users are currently logged in to the system. Executing the WHO command alone lists the login account number, the terminal used, the login time, and from where or which X monitor is being used.

  • Ps: Reports the process status of the current system

    • The output
      • UID: indicates the user running the process
      • PID: process identifier. Each process has a unique process id
      • PPID: indicates the parent process ID of the program
      • TTY: terminal on which the process is running
      • TIME: indicates the running TIME of a process
      • CMD: The name of the program that generates this process
    • practice
      • -ef: lists all processes of all users on all terminals, which can be easily viewed with pipesps -ef | less
      • -efH: Lists processes in tree form
      • -u: Lists the processes running by this user
      • -aux: Filters processes by CPU and memory usage
        • ps -aux --sort -pcpu | less: Lists the CPU usage in descending order
        • ps -aux --sort -pmem | less: Sorted by memory usage in descending order
      • ps -axjfpstree: Displays processes in a tree structure

    Indicates the process status of the current system. The kill command can be used to interrupt and delete unnecessary programs at any time. The ps command is the most basic and powerful process view command. You can use this command to determine which processes are running and their status, whether the process is finished, whether the process is dead, which processes are using too many resources, etc. Most of the information can be obtained by executing this command.

  • Top: Displays or manages executing programs

    • Q key: Exit
    • H key: Display help documents
    • Key B: Bold some information
    • F /F key: Adds or removes columns from the process list
    • U key: filter display by user
    • Key K: Terminates a process
    • S key: change the page refresh time, the default page refresh every 3 seconds
  • Kill: Terminates a process based on the process ID

    • 9 -: Forcibly ends a process
  • Killall: Terminates all processes by process name, in combination with find

glances

$ apt install glances -y
Copy the code

htop

$ apt install htop -y
Copy the code

Manage front and background processes

&Symbol: background running process

  • cp file.txt file-copy.txt &
  • find / -name "*log" > output_find 2>&1 &

nohup: Separates the process from the terminal

Whether or not the output of the nohup command is redirected to the terminal, the output is appended to the nohup.out file in the current directory. Hangup, hung

If the nohup.out file in the current directory is not writable, the output is redirected to the $HOME/nohup.out file. If no file can be created or opened for appending, the command specified by the command argument cannot be called. If standard error is a terminal, all output from the specified command to standard error is redirected to the same file descriptor as standard output.

Ctrl + Z. The bg process is running in the background

Jobs: Displays background process status

Fg: Enables the process to run foreground

Decompression and compression of files

  • tar: Archive tool used in Linux for packaging and backup
    • -cvfCreate a tar archive,tar -cvf a.tar a/
      • C: Short for create
      • V: verbose, indicating redundancy. The operation details are displayed
      • F: short for file, specifying archive files
    • -tf: Displays the contents of the archive without unpacking
    • -xvf: Unpack the archive
      • Extract, extract, extract
    • -zcvfArchive, and then use gzip to compress the archive
    • -zxvf: Unzip the gzip compression, and then unzip the archive
    • -jcvf: archive, and then compress the archive with bzip2
    • -jxvf: Unzip the bzip2 compression, then unzip the archive
  • zcat,zmore,zless
  • bzcat,bzmore,bzless
  • unzip,unrar:apt install zip

Timing and delay execution

Date: Displays or sets the system time and date

  • date +"%H"11:
  • date +"%H:%M:%S": 11:15:51
  • date +"%Y-%m-%d"2020-03-29:
  • date +"%Y-%m-%d %H:%M:%S": the 2020-03-29 11:15:51
  • Change the system time:date 10121430

At: Performs a task at a specified time

The at command is used to run a command at a specified time. At allows a fairly complex set of methods for specifying times. It can accept the time specified in hh:mm (hour: minute) format for the day. If that time has passed, do it the next day. It’s also possible to specify the time by using vague words such as midnight, noon, and teatime (teatime, usually 4 p.m.). Users will also be able to use a 12-hour clock, which indicates morning or afternoon by adding AM or PM to the end of the time. You can also specify the date on which the command is executed. The specified format is Month Day, MM/DD/YY, or DD.MM. Yy. Month, year). The specified date must follow the specified time.

While all of the above is absolute timing, you can also use relative timing, which is useful for scheduling orders that will be executed shortly. The format is now + count time-units, where now is the current time and time-units can be minutes, hours, days, or weeks. Count is the number of days, hours, etc. A better method of timing is to specify the time to complete the command directly using today and tomorrow.

  • at 22:10, will prompt you to enter the command to<EOT>The end of the input
  • at 22:10 tomorrow: Tomorrow at 22:10
  • at 22:10 03/30/2020: implemented at 22:10 on March 20, 2020
  • at now +10 minutes: The command will be executed in 10 minutes

Atq: lists the AT task list of the current user

  • Q is the first letter of queue.

The atq command displays the list of tasks to be executed in the system, that is, the AT task list of the current user.

Atrm: deletes the specified task from the task queue

The atrm command is used to delete a task from the task queue.

Sleep: Delays the current action for a period of time

  • touch file.txt; sleep 10; rm file.txt

&&,||,;

  • &&:&&The following commands are executed only when the preceding command is successfully executed
  • ||:||If the preceding command fails to be executed, subsequent commands are executed
  • ;: The command after the semicolon is executed regardless of whether the command before the semicolon is successfully executed

Crontab submits and manages tasks that users need to perform periodically

The crontab command is used to submit and manage tasks that need to be executed periodically. Similar to scheduled tasks in Windows, after the OS is installed, the service tool is installed by default and the Crond process is automatically started. The Crond process checks whether there are tasks to be executed every minute. If there is a task to be executed, it is automatically executed.

  • -e: Edit the timer Settings for the user;
  • -l: lists the timer Settings for the user;
  • -r: Deletes timer Settings for the user.
  • -u < user name >: Specifies the name of the user to set the timer.

m h dom mon dow command

  • Order formula: hour, day, month, week

  • M: Short for minute (0 to 59)

  • H: Short for hour (0 to 23)

  • Dom: Short for day of month (0-31)

  • Mon: short for month, the month (1 to 12)

  • Dow: Abbreviation of day of week (0 to 6, Sunday is 0)

  • Command: Indicates the command that needs to be executed periodically

Special characters:

  • Asterisk (*) : indicates all possible values. For example, the asterisk (*) in the month field indicates that the command will be executed every month after all restrictions on other fields are met.
  • Comma (,) : comma-separated values specify a list range, for example, “1,2,5,7,8,9”
  • Middle bar (-) : A range of integers can be represented by a middle bar between integers, for example “2-6” for “2,3,4,5,6”
  • Slash (/) : You can use a slash to specify the interval frequency. For example, 0-23/2 indicates that the interval is executed every two hours. A forward slash can be used with an asterisk, for example, */10. If it is used in the minute field, the command is executed every 10 minutes.

The instance

To restart the cron service, run the systemctl cron.service restart command

The command is executed every minute

* * * * * command

Copy the code

Execute at the 3rd and 15th minutes of each hour

3,15 * * * * command

Copy the code

It is implemented at the 3rd and 15th minutes between 8 a.m. and 11 a.m

3,15 8-11 * * * command

Copy the code

The third and 15th minutes of every other day from 8 a.m. to 11 a.m

3,15 8-11 */2 * * command

Copy the code

The 3rd and 15th minutes are run every Monday morning from 8am to 11am

3,15 8-11 * * 1 command

Copy the code

Restart the SMB at 21:30 every night

30 21 * * * /etc/init.d/smb restart

Copy the code

Restart the SMB at 4:45 on the first, 10th, and 22nd of each month

45 1,10,22 * * /etc/init.d/ SMB restartCopy the code

Restart the SMB at 1:10 a.m. every Saturday and Sunday

10 1 * * 6 0 /etc/init.d/ SMB restartCopy the code

Restart the SMB every 30 minutes between 18:00-23:00 every day

*/30 18-23 * * * /etc/init.d/smb restart

Copy the code

SMB restarts at 11:00pm every Saturday night

0 23 * * 6 /etc/init.d/smb restart

Copy the code

Restart the SMB every hour

* */1 * * * /etc/init.d/smb restart

Copy the code

Restart the SMB every hour between 11 p.m. and 7 a.m

* 23-7/1 * * * /etc/init.d/smb restart

Copy the code

Restart the SMB on the 4th of each month and at 11am on Mondays through Wednesdays

0 11 4 * mon-wed /etc/init.d/smb restart

Copy the code

Restart the SMB at 4:00 a.m. on January 1

0 4 1 jan * /etc/init.d/smb restart

Copy the code

Hourly execution/etc/cron.hourlyScripts in a directory

01 * * * * root run-parts /etc/cron.hourly

Copy the code

SSH

  • Global SSH client configuration:/etc/ssh/ssh_config
  • SSH client configuration:~/.ssh/config
    • if~/.sshNone, executessh localhost
    • nano configedit
  • SSH server configuration:/etc/ssh/sshd_config

Common configuration parameters in the server config file

  • Port: SSHD service Port number (default: 22)
  • PermitRootLogin: Whether to log in as the root user (yes by default)
  • PasswordAuthentication: whether PasswordAuthentication is allowed (the default is yes)
  • PubkeyAuthentication: Whether to allow public key authentication login (default yes)
  • PermitEmptyPasswords: whether to allow empty password login (insecure. Default no)

Client config file configuration

$ nano ~/.ssh/config
Copy the code
Host aliyun
  HostName 47.98.152.68
  Port 22
  User root
Copy the code
$ ssh aliyun
Copy the code

Configure password-free login

  1. Generating key pairs (public and private) in the client

    ssh-keygen -t rsa -C "[email protected]"

    • In the ~/.ssh/ directory, two new files are generated

      • Id_rsa: the private key
      • Id_rsa.pub: public key
  2. Ssh-copy-id: installs the local SSH public key file to the account corresponding to the remote host

    $SSH - copy - id - I ~ /. SSH/id_rsa pub [email protected]
    Copy the code

    The ssh-copy-id command copies the local host’s public key to the remote host’s authorized_keys file. The ssh-copy-id command also sets appropriate permissions for the remote host’s home directory (home) and ~/. SSH, and ~/.ssh/authorized_keys.

    • -i: Specifies the public key file

After setting password free, you still want to log in with password:

$SSH -o PreferredAuthentications=password -o PubkeyAuthentication=no [email protected]
Copy the code

Test Github password free login:

ssh -T [email protected]

Linux network

Wget: tool for downloading files in Linux

Using the wget command, you can download the file from the specified URL. Wget is very stable and adaptable to very narrow bandwidth and unstable networks. If the download fails due to network problems, WGET will keep trying until the entire file has been downloaded. If the server interrupts the download process, it reconnects to the server to pick up where it left off. This is useful for downloading large files from servers with limited link times.

Wget supports HTTP, HTTPS, and FTP protocols, and can use HTTP proxies. Automatic download means that WGET can be executed in the background after the user logs out of the system. This means that you can log in to the system, start a WGET download task, then log out, and wGET will run in the background until the task is complete, which saves a lot of trouble compared to most other browsers which require the user to be constantly involved in downloading large amounts of data.

It is used to download resources from the network. The default directory for downloading resources is the current directory. Wget, while powerful, is relatively simple to use:

  1. Support breakpoint downupload function is also the biggest selling point of Network Ant and FlashGet. Now, Wget can also use this function, those users who are not good network can rest assured;
  2. Support both FTP and HTTP download mode Although most software can be downloaded using HTTP, sometimes you still need to download software using FTP.
  3. Support proxy server to the security intensity of the system is very high, generally will not be directly exposed to their own system on the Internet, so, support proxy software download must have some functions;
  4. The setting is convenient and simple. Users who are accustomed to the graphical interface are not used to the command line. However, the command line has more advantages in setting.
  5. Program small, completely free program small can be considered, because now the hard disk is too big; Completely free has to be considered, even though there are a lot of so-called free software on the Internet, but the advertising of these software is not our favorite.

SCP: encrypted mode to copy files between local and remote hosts

The SCP command is used to copy files remotely under Linux. Similar to the cp command, cp is copied locally, not across servers, and SCP transfers are encrypted. It might affect the speed a little bit. When your server’s hard drive becomes read-only, use SCP to remove files. SCP is also very resource-intensive and does not add much to the system load, where rsync is nowhere near as efficient. Although rsync is faster than SCP, it can cause very high disk I/O in the case of large numbers of small files, while SCP has little impact on system use.

$ scp file.txt [email protected]
Copy the code

netstat -ntulp | grep 9001

Check the port usage

Rsync: remote data synchronization tool

The rsync command is a remote data synchronization tool that can quickly synchronize files between multiple hosts over a LAN/WAN. Rsync synchronizes files between local and remote hosts using what’s called the “rsync algorithm,” which is fairly fast because it only sends different parts of two files, rather than the whole one at a time. Rsync is a very powerful tool, and its commands have a number of feature options, which are explained below.

  • By default, rsync does not delete files in the target directory during synchronization. For example, if a file is deleted from your source directory (the directory being synchronized), rsync does not delete the same file in the synchronized directory.rsync -arv --deleteYou can delete

Back up to another directory on the same computer with rsync:

$ rsync -arv Images/ backups
Copy the code
  • -a: Keeps all information about the file, including permissions, modification dates, etc. A stands for archive, yesThe archiveThe meaning of
  • -r: recursive call. All files that indicate subdirectories are also included. R stands for recursive, yesrecursiveThe meaning of
  • -v: Redundant mode. The detailed operation information is displayed. V is short for verbose, yesredundantYou mean

Synchronize local files to server with rsync:

$Rsync - arvz -- progress -- delete [email protected]: ~ / Desktop/blog/home/yangjunning /
Copy the code

Backup to seven Niuyun

Installing the Command line tool (qshell)

  1. Enter home directory:cd ~
  2. Download the zip package:Wget HTTP: / / http://devtools.qiniu.com/qshell-linux-x86-v2.4.1.zip
  3. Decompression package:Unzip the ~ / qshell - Linux - x86 - v2.4.1. Zip
  4. Run at any position:~ / mv qshell - Linux - x86 - v2.4.1 / usr/local/bin/qshell
  5. Jurisdiction:chmod +x /usr/local/bin/qshell
  6. Delete compressed packages:Rm - rf ~ / qshell - Linux - x86 - v2.4.1. Zip

Key set

The commands that require authentication depend on the AccessKey and SecretKey of the Qiniu account. Therefore, before running such commands, you need to use the Account command to set AccessKey and SecretKey.

$ qshell account -- ak sk name
Copy the code

Note: AK and SK are in qiniuyun Console -> Personal Center -> Key Management.

You can continuously add ak, SK, and name information of accounts by using the qshell account. Qshell will save the information of these accounts. You can use the qshell user command to list account information, switch between accounts, and delete accounts

Account management

You can use the qshell user subcommand to manage recorded multi-account information.

  1. qshell user lsYou can list all account information under the account
  2. qshell user cuCan be used to switch accounts
  3. qshell user cuIf not, it will switch to the latest account; For example, AFTER I finish the operation of account A, I useqshell user cu BWhen you get to account B, use itqshell user cuI can cut back to account A

qupload2

Synchronize data to seven cow space, with synchronization progress information, and data upload integrity check (imperative), please see the documentation for details

$ qshell qupload2 --src-dir=/var/lib/docker/volumes --bucket=my-docker-volumes
Copy the code