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

Introduction of Linux operating system and command skills

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

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

This article mainly explains "the introduction of Linux operating system and command skills". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "the introduction of Linux operating system and command skills".

Basic properties of Linux files Linux files and directories management Linux users and user groups management Linux disk management vi/vimvimVi/Vim is the default editor for all Unix/Linux operating systems ZQ exits unconditionally: Q! Unconditionally exit ZZ save and exit: wq save and exit j move down one line k move one line up / search forward in the file (special characters such as / need to use transfer characters\, if matching baidu/agile/agile requires input: / baidu\ / agile\ / agile)? Search back in the file n search the next N reverse search the next # replace all an of the entire file with b:%s/a/b/g# replace the first an of lines 1 to 3 with the first an of the lines 1 to 3, replace all an of the lines 1 to 3 with all the an of the lines 1 to 3, use the sed-I command to add, delete, modify and check the text string and use the skill log # # # tail## countdown 300 lines and enter real-time monitoring file write mode tail-300f shopbase.log# displays the last 20 lines of the file example.txt tail-n 20 example.txt# displays the last ten lines of the file example.txt and after the file content is added Automatically displays the contents of the new file. Tail-f example.txt# displays the last 50 lines of the file example.txt and automatically displays the new file contents when the file content is added. Tail-n 50-f example.txt# dynamic display the last 100 lines containing java content tail-100f file1 | grep java#cat## displays the line in the file file that matches the foo string and 5 lines cat error.log up and down | grep-C 5 'foo'# displays foo and the first 5 lines cat error.log | Grep-B 5 'foo'# displays foo and the last five lines of cat error.log | grep-A 5' foo'# contains multiple keywords cat example.txt | grep dongshihao | grep ciOnline# ignores the case search keyword cat f.txt | number of occurrence of grep-I shopbase# keywords cat f.txt | grep-c shopbase#grep# # File search grep forest f.txt# multiple files search grep forest f.txt cpf.txt# directory to find all files that match keywords grep 'log' / home/admin-r-n # specify a single file suffix grep' import' ~ / code-r-n-- include'* .java'# specify multiple file suffixes grep 'shopbase' / home/admin-r-n-include *. {vm Java} # Anti-matches grep 'shopbase' / home/admin-r-n-- exclude *. {vm,java} # find## looks up the filename.txt file under / directory by name. Find /-name filename.txt# recursively finds all xml files find. -name "* .xml" # Recursively find all xml files that contain hello world in their contents find. XML. -name "* .xml" | xargs grep "hello world" # multiple directories to find find / home/admin / tmp / usr-name\ * .log # look for find by name (case-insensitive). -iname\ * .log # all subdirectories under the current directory find. -type d# details of all symbolic links in the current directory find / usr-type l# symbolic links eg:inode directory find / usr-type l-name "z*"-ls# files over 250000k, of course + changed to-is less than find / home/admin-size + 250000k# query file find / home/admin f-perm 777-exec ls-l {}\ # find / home/admin-atime-1 files accessed within 1 day find / home/admin-ctime-1 files modified within 1 day find / home/admin-mtime-1 files accessed within 1 minute find / home/admin-amin-1 files find / home/admin-cmin-1 files modified within 1 minute find / home/admin modified within 1 minute -mmin-delete the file find. /-size 0 with zero file size | xargs rm-f & # find and delete the file find / data-ctime + 7-exec rm-rf {}\ created 7 days ago in the directory / data. Find / data-ctime + 7 | xargs rm-rf# looks up the file and copies it to the / opt directory method 1:find / etc-name httpd.conf-exec cp-rf {} / opt/\; #-exec executes the following command, {} represents the result of the previous output,\ End command method 2:find / etc-name httpd.conf | xargs-I cp {} / opt #-I means that the output result is {} instead of # to view files larger than 1G in the root directory. The default unit is b. You can use other units, such as C, K, Mfind /-size + 1024m # find the IP address ifconfig | grep-o'[0-9]\ {1 if 3\}\. [0-9]\ {1 NR 3\}\. [0-9]\ {1J 3\}\. [0-9]\ {1J 3\}'#-o display only matching characters # View 20 to 30 lines in the text (a total of 100 lines) method 1:awk'{if (NR > 20 & & NR)

< 31) print $0}' test.txt方法2:sed -n '20,30p' test.txt 方法3:head -30 test.txt |tail#查看压缩日志文件zcat test.gzzless test.gz#搜索当前目录包含某个字符串的文件(找到该字符串在哪个文件的第几行)grep -rn "test" *文本分析 awk是一个强大的文本分析工具,相对于grep的查找,sed的编辑,awk在其对数据分析并生成报告时,显得尤为强大。简单来说awk就是把文件逐行的读入,以空格为默认分隔符将每行切片,切开的部分再进行各种分析处理。 #####################awk#####################文件aa11 a12 a13b21 b22 b23c31 c32 c33文件b11 12 1321 22 2331 32 33文件ca:b:cd:e:fg:h:i#基础命令awk '{print $2,$3}' aa12 a13b22 b23c32 c33awk '{print NR,$0}' a b1 a11 a12 a132 b21 b22 b233 c31 c32 c334 11 12 135 21 22 236 31 32 33 awk '{print FNR,$0}' a b1 a11 a12 a132 b21 b22 b233 c31 c32 c331 11 12 132 21 22 233 31 32 33awk '{print FNR,FILENAME,$0}' a b1 a a11 a12 a132 a b21 b22 b233 a c31 c32 c331 b 11 12 132 b 21 22 233 b 31 32 33awk '{print FILENAME,"NR="NR,"FNR="FNR,"$"NF"="$NF}' a ba NR=1 FNR=1 $3=a13a NR=2 FNR=2 $3=b23a NR=3 FNR=3 $3=c33b NR=4 FNR=1 $3=13b NR=5 FNR=2 $3=23b NR=6 FNR=3 $3=33echo 1 2 3 | awk -F: '{print $1,$2,$3}' ca b cd e fg h i#匹配ldbawk '/ldb/ {print}' f.txt#不匹配ldb awk '!/ldb/ {print}' f.txt#匹配ldb和LISTEN awk '/ldb/ && /LISTEN/ {print}' f.txt #第五列匹配ldb awk '$5 ~ /ldb/ {print}' f.txt#文本左对齐:awk '{printf "%-15s %-10s %-20s\n",$1,$2,$3}' test.txt#文本右对齐:awk '{printf "s s %20s\n",$1,$2,$3}' test.txt#从如下日志中求出feature、model两个过程耗时平均值2019-11-13 15:23:08 INFO [DubboServerHandler-127.0.0.1:20880-thread-199] (AInterfaceImpl.java:128) - A_task: where:B, strategy:READ_SPEED_REGRESSION_V9_OPT, uid:123@wx.163.com, traceId:123, feature(FeatureExtractor,400,112ms), model(400, success, 31ms), allCost: 143mscat engine_ctr.log | grep FeatureExtractor | grep B | awk -F "[,()]" '{print $10}' | awk -F "ms" '{print $1}' | awk '{sum+=$1} END {print "Average = ", sum/NR}'cat engine_ctr.log | grep FeatureExtractor | grep B | awk -F "[,()]" '{print $15}' | awk -F "ms" '{print $1}' | awk '{sum+=$1} END {print "Average = ", sum/NR}'文件#使用stat命令查看一个文件的属性,访问时间(Access)、修改时间(modify)、状态改变时间(Change)stat index.php#文件夹读写权限chmod -R 777 文件夹#重命名mv oldNameFile newNameFile#递归复制整个文件夹cp -r sourceFolder targetFolder#批量解压tar.gz方法1:find . -name "*.tar.gz" -exec tar zxf {} \;方法2:for tar in *.tar.gz; do tar zxvf $tar; done方法3:ls *.tar.gz | xargs -i tar zxvf {} #筛除出文件中的注释和空格方法1:grep -v "^#" httpd.conf |grep -v "^$"方法2:sed -e '/^$/d' -e '/^#/d' httpd.conf >

Http.conf or sed-e'/ ^ # / d / ^ $/ d' #-e execute multiple sed command methods 3:awk'/ ^ [^ #] / | / "^ $" 'httpd.conf or awk'! / ^ # | ^ $/ 'httpd.conf# filter / etc/passwd file all user methods 1:cat / etc/passwd | cut-d:-F1 method 2:awk-F ":"' {print $1}'/ etc/passwd other commonly used (continuously updated) # memory Usage free-h # View java process ps aux | grep java# look up elastic process kill-9 forcibly kill process ps-ef | grep-- process color elastic# terminating thread number 19979 kill-9 1997 kill to find out if there is a process named tomcat: ps-aux | grep tomcat# view the top 10 memory-consuming processes ps-aux | sort-k4nr | head-n 1 check the usage of all processes and ports: netstat-apn# if found Port 8080 is occupied by 8979 java processes with PID You can further check the details: ps-aux | grep 8979ps-aux | grep java# to view the running time of the process ps-p 24525-o lstart Etime# directly uses the port number to view the process: netstat-apn | grep 808 ports to see which process the port belongs to lsof-I: 808 checks the file handle opened by the process lsof-p pid#iptables forwards native port 80 to local port 8080 iptables-t nat-A PREROUTING-p tcp-- dport 80-j REDIRECT-- to-ports 808 ports view all network connections netstat-antp# only looks at the listening port information netstat-lntp# People log in to su as root-root# to establish a link with root Execute commands through root su root# use Super Admin to execute commands # sudo command requires the password of the current user to be entered The su command requires entering the password of the root user sudo rm a.txt# to generate an 8-bit random string method 1:echo $RANDOM | md5sum | cut-c 1-8 method 2:openssl rand-base64 4 method 3:cat / proc/sys/kernel/random/uuid | cut-c 1-delete the command text ctrl+ u# delete the command text from the beginning to the end ctrl+k# cursor move to the beginning of the command ctrl+ a # Move the cursor to the end of the command ctrl + e# multiple command execution Use semicolons to separate cd / temp/log/ Rm-rf * multiple commands are executed, separated by semicolons (make sure the previous one is successful, otherwise the current directory will be deleted) cd / temp/log/&&rm-rf * # terminates and resumes the process of executing ctrl+z and fg# to quickly find the commands you need: man-k "copy files" redis

Set redis access password

At this point, I believe you have a deeper understanding of the "introduction of the Linux operating system and command skills". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

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

Internet Technology

Wechat

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

12
Report