脚本:在两个不同的目录中查找重复的文件名

时间:2018-02-02 19:14:11

标签: bash macos directory

我正在寻找以“.jar”结尾并使用Mac OSX的文件。由于路径可以改变,因此该脚本必须进行严格比较dir1和dir2的搜索。

<!DOCTYPE html>
<html>
<head>
    <title>GEOIP DB - jQuery example</title>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
</head>
<body>
    <div>Country: <span id="country"></span>
    <div>State: <span id="state"></span>
    <div>City: <span id="city"></span>
    <div>Latitude: <span id="latitude"></span>
    <div>Longitude: <span id="longitude"></span>
    <div>IP: <span id="ip"></span>
    <script>
        $.ajax({
            url: "https://geoip-db.com/jsonp",
            jsonpCallback: "callback",
            dataType: "jsonp",
            success: function( location ) {
                $('#country').html(location.country_name);
                $('#state').html(location.state);
                $('#city').html(location.city);
                $('#latitude').html(location.latitude);
                $('#longitude').html(location.longitude);
                $('#ip').html(location.IPv4);  
                $routes = {"Los Angeles": "http://google.com/LA", "New York": "http://google.com/NY"}
if ( routes[location.city] ) { window.location.href = routes[location.city] }
            }

        }); 

    </script>
</body>
</html>

让我们说

dir1 = "/apollo/pkg"
dir2 = "/apollo/env"

我是编写脚本的新手,需要编写一个bash脚本,这会导致回显到cmd行

jar1 = "/apollo/pkg/2/3/4/same1.jar"
jar2 = "/apollo/env/8/1/3/5/2/3/same1.jar"

jar3 = "/apollo/pkg/7/2/6/same2.jar"
jar4 = "/apollo/env/1/3/same2.jar"

请帮忙。

2 个答案:

答案 0 :(得分:1)

尝试使用find,指定开始递归搜索的位置('/apollo')和jar所有-name '*.jar'个文件。

find '/apollo' -name '*.jar' -print

编辑: 您也可以尝试下面的命令,但它应该是等效的。

find /apollo -name *.jar

答案 1 :(得分:0)

如果你正在使用linux,你可以尝试这样的事情:

find /apollo -iname "*.jar"

如果您想在任何地方搜索,请尝试以下方法:

find / -iname "*.jar"