1

In the mixed environment of Linux and Windows machines, there is a lot of links shared via IM, emails etc. They point to the same location, but they have different formats.

For example Windows link \\MACHINE\dir1\dir2\file.xyz is equivalent to Linux' smb://MACHINE/dir1/dir2/file.xyz.

Is there a possibility to translate Windows links transparently in Nautilus or/and shell?

2 Answers 2

1

As you said

in Nautilus or / and shell ?

the shell way:

  1. Using awk

    awk -F'\' '{printf "smb:/"; for(i=2;i<=NF;i++){printf "/%s",$i}; printf "\n"}'<<< "\MACHINE\dir1\dir2\file.xyz"
    

    Output:

    smb://MACHINE/dir1/dir2/file.xyz
    
  2. Or via Perl

    perl -pe 'print "smb:/"; s/\\/\//g' <<< "\MACHINE\dir1\dir2\file.xyz"
    

    Output:

    smb://MACHINE/dir1/dir2/file.xyz
    
0

Shorter awk

awk '{gsub(/\\/,"/");print "smb:/" $0}'

Sample output:

$ printf "%s" '\MACHINE\dir1\dir2\file.xyz' | awk '{gsub(/\\/,"/");print "smb:/" $0}'
smb://MACHINE/dir1/dir2/file.xyz

Java

Very primitive, use with caution. Usage: java translatepath towin[tonix] "/path/to/file"["\path\to\file"]

public class translatepath
{
    public static void main(String[] args)
    {
        System.out.println(args[1]);
        if (args[0].contentEquals("tonix"))
            {
                System.out.println(toNixPath(args[1]));
            }
        else if (args[0].contentEquals("towin"))
            {
                System.out.println(toWinPath(args[1]));
            }
    }

    public static String toNixPath(String path)
    {
        return  path.replace("\\","/");
    }
    public static String toWinPath(String path)
    {
        return path.replace("/","\\");
    }
1
  • Shorter awk? :) cool
    – A.B.
    Sep 13, 2015 at 5:01

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .