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 practical skills of Linux

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

Share

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

This article mainly explains "what are the practical skills of Linux". Friends who are interested 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 "what are the practical skills of Linux"?

1. The method of quickly emptying files

There are N ways to quickly empty a file. I prefer the following one because it is the shortest.

$> access.log

Not enjoyable? Well, by the way, I'd like to summarize some of the other most common ways to empty files.

: > access.logtrue > access.logcat / dev/null > access.logecho-n "" > access.logecho > access.logtruncate-s 0 access.log

To put it simply,: in shell, it is a built-in command to indicate no-op, which probably means an empty statement, so the usage of: is to output nothing after executing the command, overwriting the empty content to the file.

two。 Quickly generate large files

Sometimes, on Linux, we need a large file to test the speed of uploading or downloading, and a large file can be generated quickly with the dd command.

$dd if=/dev/zero of=file.img bs=1M count=1024

The above command generates a file named file.img with a size of 1G.

3. Safely erase hard disk data

This paper introduces a method of erasing hard disk data, which is efficient and safe. You can easily do this through the dd command:

$dd if=/dev/urandom of=/dev/sda

Use / dev/urandom to generate random data and write the generated data to the sda hard disk, which is equivalent to safely erasing the hard disk data.

If Mr. Chen had learned this order at that time, there might not have been the Yanzhaomen incident.

4. Rapid production of system disk

When making a system disk under Linux, the old Mao Tao God's tools are all weak, so you can do it with a direct command:

$dd if=ubuntu-server-amd64.iso of=/dev/sdb

Haha, isn't it cool? sdb can be a U disk or an ordinary hard drive.

5. View the running time of a process

Perhaps, most students will only use ps aux, in fact, you can use the-o parameter to specify that only a specific field will be displayed, and you will get clearer results.

$ps-p 10167-o etimes,etime

ELAPSED ELAPSED

1712055 19-19:34:15

Get the running time of the process through etime. You can see that the process has been running for 19 days.

Similarly, you can specify that rss can only get memory information for that process with-o.

$ps-p 10167-o rss

RSS

2180

6. View logs dynamically and in real time

Through the tail command-f option, you can dynamically monitor changes in log files, which is very practical

$tail-f test.log

If you want to stop tail monitoring immediately when Failed and other information appear in the log, you can use the following command:

$tail-f test.log | sed'/ Failed/ Q'

7. Fast conversion of timestamp

Time operation is a common occurrence for programmers. Sometimes you want to be able to convert the timestamp to date time, or you can convert it quickly on the Linux command line:

$date-dong1234567890 + "Y-%m-%d H:%M:%S"

2009-02-14 07:31:30

Of course, you can also view the current timestamp on the command line

$date +% s

1617514141

8. Elegant computing program run time

Under Linux, you can easily get the run time of the program through the time command:

$time. / test

Real 0m1.003s

User 0m0.000s

Sys 0m0.000s

As you can see, the running time of the program is 1.003s. Careful students will see that real doesn't seem to be equal to user + sys, and it's much bigger than that. What's going on?

Let's first explain the meaning of these three parameters:

Real: clock time, that is, time spent from program execution to completion; user: time spent by cpu in user space during operation; sys: time spent by cpu in kernel space during operation

Because user and sys only count the time consumed by cpu, the call to sleep will block during the run of the program, or they may wait for the network or disk IO, which will consume a lot of time. So for similar cases, the value of real will be greater than the sum of the other two.

In addition, you will also encounter scenarios where real is much smaller than user + sys. What the heck is this?

This is easier to understand. If the program is parallel on multiple cpu, then the statistical time of user and sys is multiple cpu time, and the actual time consumed real is likely to be less than the sum of the other two.

9. Command line to view ascii code

In the process of development, we usually need to check the ascii code, which can be easily checked from the Linux command line without having to go to Google or Baidu.

$man ascii

10. Gracefully delete garbled files

In Linux systems, you will often encounter files with garbled names. Want to delete it, but can not enter the name through the keyboard, sometimes copy and paste garbled name, the terminal may not recognize, how to do?

Don't worry, here's how find solves problems elegantly.

$ls-I

138957 a.txt 138959 T.txt 132395 txt

$find. -inum 132395-exec rm {}\

In the command,-inum specifies the inode number of the file, which is the unique number corresponding to each file in the system. After the find is found by the number, the delete operation is performed.

11. Get your public network IP address on Linux

In the office or home environment, our virtual machine or server is usually configured with a private network IP address. How do we know what our public network exit IP is when communicating with the public network?

This is very simple on Linux. It's done with one command.

$curl ip.sb

$curl ifconfig.me

Both of the above commands are fine.

twelve。 How to download web resources in bulk

Sometimes, colleagues will share file download links in the form of web pages, and on Linux systems, they can be easily downloaded through the wget command without having to write scripts or crawlers

$wget-r-nd-np-- accept=pdf http://fast.dpdk.org/doc/pdf-guides/

#-accept: option to specify the resource type format pdf

13. Techniques for using historical commands

Sharing tips for using several historical commands can improve your productivity.

!!: repeat the previous command;! n: repeat the N command in the history history, N can be viewed through history;! pw: repeat the most recent history command, starting with pw, which is very useful, and the editor uses it very frequently;! $: represents the last argument of the last command

Guess that most students have not used it! $, here is a simple example to let you feel its efficient use.

$vim / root/sniffer/src/main.c

Mv! $! $.bak

# equivalent to

$mv / root/sniffer/src/main.c / root/sniffer/src/main.c.bak

The current working directory is root. I want to change main.c to main.c.bak. Normally you may need to type the long parameter containing main.c twice, of course, you may choose to copy and paste directly.

And I can easily and elegantly change my name by using the! $variable, isn't it very hacker?

14. Quick search history command

We often type a lot of commands under Linux. How can we find and execute historical commands quickly?

Through the arrow keys to flip through the history command, No No No, you can search by executing Ctrl + r, and then typing the command keywords you want to search, and enter can be executed, which is very efficient.

At this point, I believe you have a deeper understanding of "what are the practical skills of Linux?" 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

Development

Wechat

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

12
Report