Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the most efficient commands in Linux

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces what are the very efficient commands in Linux. It is very detailed and has a certain reference value. Friends who are interested must finish reading it!

There are many very efficient commands in Linux, which can be used to manage files, disks, memory, and so on.

Linux management disk

View current disk usage: df-h fdisk-l (View all hard drives) Server add hard drives: add in system Settings

Partition: fdisk / dev/sdb (sdb, sdc, sde) instruction: M (help), n (newly added partition) second step: instruction p (main partition) third step: write to disk w use: mount: mount / dev/sdb1 / data/ mount to / data directory, mount successfully as follows: high efficiency instruction Linux under Linux

Can be mounted to multiple devices mount / dev/cdrom / mnt

Vi command

All instructions are entered under the instruction line, not in edit mode! Copy multiline / single line: enter yy, then press k to delete a line: press dd; to delete a character: cursor to select a character, press x to delete a character / a line to return: U

Replace all contents of a file:% s/failymao/momo/g (after ESC: all [g means all] falilymao contents in the replacement file are momo

Replace a line with something:% s/momo/failymao/1 (replace the last line)

Add a character or blank character to the first line:% s/my/ my/g second method (add space after my):% s _ s/my/ my/g & / first line add:% s / ^ / (^ regular first line, & for append) end line add:% s _ impulse & hello (for end) insert blank line before matching line: press O (uppercase) under a character Insert blank line after line press o (lowercase) jump: jump last character: GG jump first character: gg find: / my delete everything after matching items: dG

Sed command

Replace all the contents of a file:

Sed's moment _ test.txt _ failymao _ S means to find) sed-I test.txt test.txt sed-I'/ IS/i 123456' test.txt (a stands for after) modify a profile information: sed'/ SELINUX/s/disabled/123456/g' / etc/selinux/config (modify / etc/selinux) The disabled after SELTINUX in the / config configuration file is 123456) the find command looks for a file in the current directory: * find. -name "test.txt" to find a file in the root directory: find /-name "test.txt" to find all files ending in a fixed format: find. Name "* .py" looks for directories or files that end in a fixed format: find. Name "* .py"-typt d (d for type directory) looks for directories or files ending in a fixed format: find. Name "* .py"-typt d-mtime + 1-size + 10m (d means directory,-mtime + 1 means more than one day -1 means within 1 day,-size means a file directory with a size of 10m) look for files containing certain contents: find / tmp/-name "*"-type f-name "momo" to copy: find / root/-name "*"-type f-name "* server*"-exec cp {} / samba\ (look for files containing server in / root directory, and (- exec) copy (cp) to ({} directory) / samba directory, (;) fixed format) package: find / root/-name "* .py"-exec tar czf zip_python.tar.gz {}\ Delete files: find / samba-name "*"-type f-name "* server*"-exec rm-rf {}\; (delete / samba, include all files with "server" in the file name! ) delete file = = equivalent to exec:find / root/-name "* .py" | xargs rm-rf {}\ (pipe character | xargs equals-exec) Pipe character grep filter file: the previous result is used as the latter input: cat test.txt | grep "hou" (check the contents of "hou" in the text.txt file) = = grep "hou" test.txt exclusion file: cat / etc/passwd | grep-v "mysql" (filter out the content of "mysql" in / etc/passwd and print out the result! ) print a fixed line filtered: ifconfig | grep "net" | awk'{print $1}'(print the ifconfig command containing the character net First column) grep regular grep'^ 10' text.txt match starts with 10` grep'10 $'text.txt matches ends with 10 grep "[0-9] [0-9] [0-9]" test.txt matches any composition of three digits grep "[Amurz]" test.txt matches fields containing the letters of Amurz (lowercase) grep "^ 112 $" text.txt matches (grep-E) ending with 112 [ 0-9] {1pr 3}\.) {3} matches any number of 0-9 1-3 times . Indicates a match., {3} three times to view memory, ip information to view memory information: free-m view cup: top view httpd:ps-ef | grep httpd view tcp port: netstat-tnl view udp: netstat-nul view current directory file size: total du-sh special instructions

Other application examples: maximum and minimum number of output text data

1121223444 334444 11 22 444,578 231231234 3443 3443 234553 12344512 14 567 456 23478 execute: cat number.txt | sed's / /\ nUniverse g' | grep-v "^ $" | sort-nr | sed-n '1pplacp` instruction details: 1) sed's / /\ nswap' converts all spaces to newline 2) | grep-v "^ $" excludes groups that begin with spaces,-v means exclude 3) | sort-nr sorts from big to small 4) | $p'- n for multiline printing, 1p for the first one, and $p for the last awk

Specify a line to print that matches

Cat test.txt | awk'{print $4}'- > print the matching fourth column ($NF represents the last column) cat / etc/passwd | awk-F:'{print $1}'-->-F represents format, custom format Print the first column sample ifconfig to match the IP address method 1: ifconfig eth2 | grep "broadcast" | awk'{print $2}'| sed's sed _ awk _ awk _ awk'{print $2}'| awk-F:'{print $2}'df-h | grep "/ $" | awk'{print $5}'| sed's jump% Universe G' print hard disk usage, remove the% sign

These are all the contents of the article "what are the most efficient commands in Linux?" Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report