How to directly open files found by using locate

Source: Internet
Author: User

In many cases, you need to use locate to locate the file. After finding the file, use the corresponding text editing tool, such as gvim, to open it.

At this time, the most annoying thing is to copy a long string of addresses.

If you can enable the integration of location and open operations, it is best to use pipelines for operations.

Two problems need to be solved when using pipelines: 1. Several files are often found during the locate Locating Process, if only the first target file is output to the pipeline;

2. How to Use gvim in the pipeline to open the file to be transferred.

First, you can use the head command to correct the locate result;

[Email protected]: ~ /Work_zooc/LNX.LA.3.7.3-03110-8939.0 $Locate android_hardware_sensormanager.cpp
/Usr/share/lxr/source/2.6.21/Linux/frameworks/base/CORE/JNI/android_hardware_sensormanager.cpp
/Usr/share/lxr/source/2.6.21/Linux/frameworks/base/CORE/JNI/. SVN/Text-base/android_hardware_SensorManager.cpp.svn-base

This command returns two matched files. If you open the file directly using gvim, two files will be opened.

This requires the head command.

[Email protected]: ~ /Work_zooc/LNX.LA.3.7.3-03110-8939.0 $Locate android_hardware_sensormanager.cpp | head-N 1
/Usr/share/lxr/source/2.6.21/Linux/frameworks/base/CORE/JNI/android_hardware_sensormanager.cpp

This solves the first problem.

But directly use PipelinesLocate android_hardware_sensormanager.cpp | head-N 1 | gvim

The gvim client will be opened directly.

What we need to do is to pass the return value of the previous command as a parameter to the gvim command.

There are several methods, such as ''; $ ();

You can also use the xargs command.

The final command is as follows:

Locate android_hardware_sensormanager.cpp | head-N 1 | xargs gvim

 

How to directly open files found by using locate

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.