27

To launch Windows lnk shortcut on Linux, one can use wine start qqq.lnk.

But do I view the information (command line, current directory) about it? strings is not enough.

4
  • lnk files are text, open them with a text editor (deleted comment) -> It looks like a binary file, with a lot of zero bytes and some UTF-16le fragments.
    – Vi.
    Jul 12, 2014 at 1:16
  • 2
    See also: python-based solution
    – dreftymac
    Nov 15, 2017 at 19:54
  • There are two types of lnk files, the text files are URL files, that were named lnk in the past, currently they are named with a url suffix.
    – Didi Kohen
    Jul 20, 2022 at 11:17
  • FWIW, exiftool also supports this format.
    – Ruslan
    Oct 16, 2022 at 0:08

3 Answers 3

14

It seems there aren't a lot of programs to do this...I found two Perl scripts that kinda work.

lslnk.pl and lnk-parse

Use them like this: <whicheverscript> Name.lnk

2
  • 1
    lnk-parse-1.0.pl seem to work better than lslnk.pl.
    – Vi.
    Jul 12, 2014 at 11:08
  • I'd say lnk-parse more than kinda works. It works great! Dec 29, 2018 at 17:53
24

You can use the lnkinfo tool from liblnk (liblnk-utils package in Debian):

lnkinfo <file.lnk>

Example usage in scripts:

LOCAL_PATH=$(lnkinfo "$1" | grep 'Local path' | cut -d':' -f2-)
ARGS=$(lnkinfo "$1" | grep 'Command line arguments' | cut -d':' -f2-)

Example output:

$ lnkinfo 'Program Files - Shortcut.lnk'
lnkinfo 20171101

Windows Shortcut information:
        Contains a link target identifier
        Contains a relative path string

Link information:
        Creation time           : Jul 14, 2009 03:20:08.555426400 UTC
        Modification time       : Apr 23, 2019 21:36:46.017274100 UTC
        Access time         : Apr 23, 2019 21:36:46.017274100 UTC
        File size           : 12288 bytes
        Icon index          : 0
        Show Window value       : 0x00003000
        Hot Key value           : 12288
        File attribute flags        : 0x00000011
                Is read-only (FILE_ATTRIBUTE_READ_ONLY)
                Is directory (FILE_ATTRIBUTE_DIRECTORY)
        Drive type          : Fixed (3)
        Drive serial number     : 0x0e1909c6
        Volume label            : Local Disk
        Local path          : C:\Program Files
        Relative path           : ..\..\..\Program Files

Link target identifier:
        Shell item list
                Number of items     : 3

        Shell item: 1
                Item type       : Root folder
                Class type indicator    : 0x1f (Root folder)
                Shell folder identifier : 20d04fe0-3aea-1069-a2d8-08002b30309d
                Shell folder name   : My Computer

        Shell item: 2
                Item type       : Volume
                Class type indicator    : 0x2f (Volume)
                Volume name     : C:\

        Shell item: 3
                Item type       : File entry
                Class type indicator    : 0x31 (File entry: Directory)
                Name            : PROGRA~1
                Modification time   : Apr 23, 2019 21:36:48
                File attribute flags    : 0x00000011
                        Is read-only (FILE_ATTRIBUTE_READ_ONLY)
                        Is directory (FILE_ATTRIBUTE_DIRECTORY)
        Extension block: 1
                Signature       : 0xbeef0004 (File entry extension)
                Long name       : Program Files
                Localized name      : @shell32.dll,-21781
                Creation time       : Jul 14, 2009 03:20:10
                Access time     : Apr 23, 2019 21:36:48
                NTFS file reference : MFT entry: 878, sequence: 1



Distributed link tracking data:
        Machine identifier      : <snip>
        Droid volume identifier     : b2638d5e-f5b8-480c-bda0-fdb25ab91131
        Droid file identifier       : 968b84a2-a646-11e9-a124-0021cc6948e3
        Birth droid volume identifier   : b2638d5e-f5b8-480c-bda0-fdb25ab91131
        Birth droid file identifier : 968b84a2-a646-11e9-a124-0021cc6948e3
1

The question doesn't say you using cygwin, but if so, I would suggest readshortcut that comes with the Cygutils package

Note: I have found some shortcuts that it doesn't display, so I also suggest the brute force

strings -el

or even

hexdump -c

READSHORTCUT(1) Cygutils
READSHORTCUT(1)

NAME readshortcut - read data from a windows shortcut (.lnk) file

SYNOPSIS readshortcut [OPTION]* SHORTCUT

DESCRIPTION readshortcut is a command-line tool for reading Windows shortcut files (also known as OLE links). The most practical use is to resolve the target that a shortcut points to. It can be easily run from a script or batch file for non-interactive use.

1
  • So cygwin.com/git.html is the Windows port but this question was for running under Linux would it run under Wine?
    – Scott R
    Jun 29, 2022 at 18:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.