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 basic operation commands of Linux

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

Xiaobian to share with you what the basic operating commands of Linux, I believe most people still do not know how, so share this article for your reference, I hope you have a lot of harvest after reading this article, let's go to understand it together!

Linux Basic Operating Commands

File and directory management

create and delete

Created by: mkdir

Delete: rm

Delete non-empty directory: rm -rf file directory

delete log rm log (equivalent: $find ./- name "log" -exec rm {} ; )

Move: mv

Copy: cp (Copy directory: cp -r)

Create a file touch

Views

Show files ls in the current directory

Sort by time to display catalog items as a list ls -lrt

ls -l

View file content cat can add more, less to control the size of the output content

cat a.textcat a.text | morecat a.text| less

permissions

Change file owner chown

Change file read, write, execute properties chmod

Recursive subdirectory modification: chown -R tuxapp source/

Add script executable permissions: chmod a+x myscript

Pipeline and redirection

Take the result of the previous command as input to the next command|

Concatenation: Use semicolons;

If the previous item succeeds, execute the next item; otherwise, do not execute: &&

If the previous one fails, the next one will be executed:||

ls /proc && echo suss! || echo failed.

text processing

File search find

There are many find parameters, and this article only introduces a few common ones.

-name Search by name

-type By type

-atime Visit time

find . -atime 7 -type f -printfind . -type d -print //list all directories only find / -name "hello.c" find hello.c file

Text search grep

grep match_patten file //default access to matching rows

common parameters

-o outputs only matching text lines VS -v outputs only text lines without matches

-c Count the number of times a file contains text

grep -c "text" filename

-n Print matching row number

-i Ignore case when searching

-l Print only file names

grep "class" . -R -n #Recursive search for text in multi-level directories (favorite for programmers searching code) cat LOG.* | tr a-z A-Z | grep "FROM " |grep "WHERE" > b #Find all SQL queries with where conditions in the log

Text substitution sed

sed [options] 'command' file(s)

first substitution

sed 's/text/replace_text/' file //Replace the first text match of each line

global substitution

sed 's/text/replace_text/g' file

After default replacement, output the replaced content. If you need to replace the original file directly, use-i:

sed -i 's/text/repalce_text/g' file

Remove blank rows

sed '/^$/d' filed's/book/books/' file #replace strings in text: sed 's/book/books/g'filed'/^$/d' file #delete blank lines

Data stream processing awk

Detailed tutorials can be found at www.example.com... http://awk.readthedocs.io/en/latest/chapte

awk ' BEGIN{ statements } statements2 END{ statements } '

workflow

1. Execute the statement block in begin;

2. Read a line from a file or stdin, then execute statements2, repeating the process until the file is all read;

3. Execute the end statement block;

special variables

NR: indicates the number of records, corresponding to the current line number during execution;

NF: indicates the number of fields, which always corresponds to the number of fields in the current row during execution;

$0: This variable contains the text content of the current line during execution;

$1: Text content of the first field;

$2: Text content of the second field;

awk '{print $2, $3}' file#Log format: '$remote_addr - $remote_user [$time_local] "$request" $status $body_bytes_sent "$http_referer" "$http_user_agent" "$http_x_forwarded_for"'#10 most visited IPawk '{a[$1]++}END{for(i in a)print a[i],i| "sort -k1 -nr| head -n10"}' access.log

sort sort

-n Sort numerically VS -d Sort lexicographically

-r reverse sort

-k N specifies sorting by column N

sort -nrk 1 data.txtsort -bd data //Ignoring leading white space characters like spaces

Go heavy uniq

Eliminate duplicate rows

sort unsort.txt | uniq

Statistics WC

wc -l file //count the number of lines wc -w file //count the number of words wc -c file //count the number of characters above is the basic operation command of Linux What are all the contents, thank you for reading! I believe that everyone has a certain understanding, hope to share the content to help everyone, if you still want to learn more knowledge, welcome to pay attention to 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

Servers

Wechat

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

12
Report