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

How to use commands to find files in Linux

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

Share

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

This article mainly introduces how to use commands to find files in Linux. It is very detailed and has a certain reference value. Friends who are interested must finish reading it.

Use simple commands to quickly find files based on type, content, etc., under Linux.

If you are a non-experienced user of Windows or OSX, you may use GUI to find files. You may also find the interface limited, frustrating, or both, and learn to organize files and remember their exact order. You can also do this in Linux-but you don't have to.

One of the benefits of Linux is that it provides a variety of ways to handle it. You can open any file manager or press Ctrl+F, or you can use the program to open the file manually, or you can start typing letters, which will filter the current directory list.

Use Ctrl+F to find screenshots of files in Linux

But what if you don't know where your files are and you don't want to search the entire disk? Linux is appropriate for this and a variety of other situations.

Find the program location by command name

If you are used to putting files at will, the Linux file system can look daunting. One of the hardest things for me to get used to is finding out where the program is.

For example, which bash usually returns / bin/bash, but if you download a program and it doesn't appear in your menu, then the which command is a good tool.

A similar tool is the locate command, which I find useful for finding configuration files. I don't like typing program names because simple programs like locate php usually provide a lot of results that need to be further filtered.

For more information about locate and which, see the man page:

Man which

Man locate

Find

The find tool provides more advanced features. The following is an example of a script I installed on many servers to ensure that files for a particular mode (also known as glob) only exist for five days and that all files earlier than this will be deleted. (scores have been used to retain deviations of up to 240 minutes since the last revision)

Find. / backup/core-files*.tar.gz-mtime + 4.9-exec rm {}\

The find tool has many advanced uses, but the most common is to execute commands on the results rather than chaining to filter files by type, creation date, and modification date.

Another interesting use of find is to find all files with executable permissions. This helps ensure that no one installs bitcoin mining programs or botnets on your expensive server.

Find /-perm / + x

For more information about find, use the man find reference man page.

Grep

Want to find files in the content? Linux has been implemented. You can use many Linux tools to efficiently search for files that match the pattern, but grep is the tool I often use.

Suppose you have a program that publishes error messages for code references and stack traces. You need to find these in the journal. Grep is not always a * * method, but I often use grep-R if the file is a given value.

More and more IDE are implementing lookup, but if you are accessing a remote system or do not have GUI for any reason, or if you want to find it recursively in the current directory, use: grep-R {searchterm} or on systems that support egrep aliases, simply add the-e flag to the command egrep-r {regex-pattern}.

I used this technique when patching dhcpcd5 in Raspbian last year so that I could continue to operate the network access point when the raspberry pie foundation released a new Debian.

The above is all the contents of the article "how to use commands to find files 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

Servers

Wechat

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

12
Report