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 the entr command in linux

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

Share

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

This article is about how to use the entr command in linux. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

Entr is a command-line tool that runs an arbitrary command each time you change any of a specified set of files. You pass it a list of files to monitor in standard input, as follows:

Git ls-files | entr bash my-build-script.sh

Or

Find. -name * .rs | entr cargo test

Or whatever you want.

Quick feedback is great.

Like every programmer in the world, I find it annoying to have to rerun the build / test manually every time I change the code.

Many tools, such as hugo and flask, have a built-in system that automatically rebuilds when a file is changed, which is great!

But usually I write my own custom build process (such as bash build.sh), and entr gives me a magical build experience, and I can get instant feedback with only one line of bash to know if my changes have fixed that strange bug. Hooray!

Restart the server (entr-r)

But what if you are running the server and need to restart the server every time? If you pass-r, then entr will help you.

Git ls-files | entr-r python my-server.py clear screen (entr-c)

Another concise flag is-c, which allows you to clear the screen before rerunning the command so as not to be distracted by the previously built output.

Use with git ls-files

Usually, the fileset I want to track is roughly the same as my list of files in git, so it's natural to pass git ls-files to entr.

I have a project now, and sometimes the files I just created are not in git. So what if you want to include files that are not being tracked? These git command line parameters can be done (I got it from an email from a reader, thank you! ):

Git ls-files-cdmo-- exclude-standard | entr your-build-script

Someone emailed me that they had made a git-entr command that could be executed:

Git ls-files-cdmo-- exclude-standard | entr-d "$@"

I think it's a great idea.

Restart every time a new file is added: entr-d

Another problem with git ls-files is that sometimes I add a new file, but of course it's not in git yet. Entr provides a good feature for this. If you pass-d, then if you add a new file to any directory tracked by entr, it will exit.

I use it with a while loop that will restart entr to include the new files, as shown below:

While truedo {git ls-files; git ls-files. -- exclude-standard-- others;} | how entr-d your-build-scriotdoneentr works on Linux: inotify

In Linux, entr works using inotify, a system that tracks file system events such as file changes. If you trace it with strace, you will see the inotify_add_watch system call for each monitoring file, as follows:

Inotify_add_watch (3, "static/stylesheets/screen.css", IN_ATTRIB | IN_CLOSE_WRITE | IN_CREATE | IN_DELETE_SELF | IN_MOVE_SELF) = 1152 Thank you for reading! This is the end of this article on "how to use entr commands in linux". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!

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