05-005 [Linux] practical command

1. Specify run level

Run Level Description:
0: Off
1: Single User
2: Multi-user state no network services
3: multiuser state in which a network service
4: The system does not use the reserved user
5: GUI
6: reboot the system
commonly run level 3 and 5 to modify the default run level can change the file
/ etc / inittab the id: 5: initdefault line of data

2. Switch to the specified operating level instructions

int [0123456]
Topic: how to find the root password, if we are not careful, forget the root password, how to recover?
Ideas: into single-user mode, and then modify the root password. Because the single-user mode, root can log in without a password.
Summary
boot -> press enter key at boot -> see an interface input E -> see a new interface, to select a second row (edit the kernel) in the input e-> In the last input line 1, then enter enter key -> b input again, this time will enter the single-user mode.
At this time, we enter into single-user mode, use the passwd command to change the root password.

3. Help command

man [commands or configuration file] (Function Description: obtaining help information)
for example, man ls

help command: xx command to view the help information

Or Baidu

4. File Directory class

  1. pwd: display nitrogen working directory absolute path
  2. ls [options] [directory or file]: Displays the file and directory parameters -a show hidden files, -l ls -al displayed as a list
  3. cd Parameters: Switch to the specified directory parameter may be an absolute or relative path home directory cd ~
  4. mkdir [options] [directory] want to create: Create a directory mkdir -p / home / animal / tiger create multi-level directory
  5. rmdir [options] [to delete empty directories ] the content can not be deleted, it can be deleted with rm -rf / home / dog
  6. touch xx.txt: Create an empty file
  7. cp [important]: cp [options] source dest common -r option recursively copy the entire folder represents an example cp /home/hello.txt bbb / cp -r test / bbb / (This command has the same file if finding the target directory, you will be prompted coverage, use \ cp this command will force overwrite the original file, will not prompt)
  8. rm [options] you want to delete a file or directory -r: recursive delete the entire folder -f: Force delete does not prompt for example rm -rf bbb / rm a.txt rm -f dd.txt
  9. mv oldNameFile newNameFile (rename) mv /home/pig.txt / root / (file moving)
  10. cat [option] [file you want to view]: browse the files can not be modified cat -n / etc / profile | more Display Line No. and Paging
  11. More text filters based vi editor, the full screen to display the contents of the film by page text file. more / etc / profile
hot key Features
Blank Down
enter Down one line
q Representatives immediately leave more, no longer displays the contents of the file
Ctrl+ F Scroll down to screen
Ctrl+ B Return to the previous screen
= Output current line number
:f The output file name and line number of the current row
  1. To view a file less: the split-screen view file contents, and more similar to, but more powerful than, supports a variety of display terminals. less command displays the file, it is not a one-off show after the entire file is loaded, but you need to load the contents of the display, for displaying large files with high efficiency.
hot key Features
Blank Down
[pagedown] Down
[pageup] Page Up
q Leaving less
/ String Looking down [String]: n: Find downwardly N: up to find
? Character string Looking down [String]: n-: Find N up: Find down
  1. The tail command and command >>> output redirection, the original file will cover >> append, not overwrite the original contents of the file, but append to the file, such as: ls -l> a.txt //// ls -l >> b.txt //// cat file 1> file 2 is equivalent to copy the contents of 1 to 2 //// echo "content" file >>

  2. echo [options] [output] content: the content of the output to the console output echo $ PATH $ PATH environment variable

  3. head file: 10 lines to view the file contents before the first (default) head -n 6 files: before the specified display a few lines

  4. tail file: 10 lines after viewing the file contents (default) tail -n 5 file: After a review of five lines of the file tail -f file: View real-time updates, common

  5. ln -s [the original file or directory soft link] [name] (the original file to create a soft link, the equivalent of shortcuts for Windows) For example: ln -s / root linkToRoot delete: rm -rf linkToRoot (not to take / Oh, otherwise deleted can not afford)

  6. history: View all the history command history n:! View recently used a nice 10 numbered instructions can execute this command directly
    Here Insert Picture Description

The date and time class

  1. 显示时间 date
    date
    date +%Y
    date +%m
    date +%d
    date +"+%Y-%m-%d %H:%M:%S"
  2. Set time
    date -s "2020-01-01 00:00:00" to set the current system time
  3. cal command
    cal [options]
    cal displays the current calendar
    cal 2020 show the current calendar

6. Search Find class

  1. find instructions
    find command from the specified directory traversal subdirectories recursively, will satisfy the condition file or directory is displayed in the terminal.
    find search range [] [Option]
    -name find / -name Home a.txt find / -name * .txt
    -user find / opt -user the nobody
    -size find / -size + 200M (+ means greater than - represents no less than equal to )

  2. locate command
    to quickly locate the file path. Without having to traverse the entire file system, in order to ensure the accuracy of the results, the administrator must be regularly updated locate time.
    As a result of inquiries locate command based on a database, so before the first run, you must create a database using locate updatedb command.
    updatedb
    the locate hello.txt

  3. grep command and the pipe symbol |
    grep filtering lookup, pipeline at |, represents a result of the processing before the command output to the command processing later.
    grep [options] Find content source file
    -n display matching lines and line number
    -i ignore case
    CAT hello.txt | grep -n yes
    CAT hello.txt | grep -ni yes

7. The compression and decompression class

  1. gzip / gunzip (compression / decompression)
    gzip hello.txt (only compressed into * .gz, after compression does not retain the original file)
    gunzip hello.txt.gz
  2. zip / unzip (compression / decompression)
    ZIP [options] xxx.zip
    -r recursive compression, ie compression directory -r mypackage.zip ZIP / Home /
    unzip [options] xxx.zip
    storage directory specified after -d decompress files unzip -d / opt / tmp mypackage.zip
  3. tar command
    pack a * .tar.gz file
    tar [options] XXX.tar.gz packaged content
    -c produce .tar package file
    -v displays detailed information about
    the file name -f specify the compression
    -z pack while compressing
    -x unpack. tar file
    tar - zcvf mytxt.tar.gz / Home / package
    tar - zxvf mytxt.tar.gz / opt / decompression (prior to the specified directory exists)

Learn finishing in Linux

Published 53 original articles · won praise 0 · Views 365

Guess you like

Origin blog.csdn.net/weixin_40778497/article/details/104046362