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