0

When I ls it, it's a directory with a bunch of files in it. But when I ls -l it, it's a symlink to something that's NOT a directory. What's going on — how is it possible?

$ ls /sys/class/net/enp0s20u1/device/driver/module   

coresize  holders   initstate  refcnt    srcversion  uevent
drivers   initsize  notes      sections  taint  
$    
$  ls -l /sys/class/net/enp0s20u1/device/driver/module  

lrwxrwxrwx 1 root root 0 Jun 13 05:24 /sys/class/net/enp0s20u1/device/driver/module -> ../../../../module/cdc_ether   
$  
$ readlink  /sys/class/net/enp0s20u1/device/driver/module  

../../../../module/cdc_ether  
$  
$  ls `readlink  /sys/class/net/enp0s20u1/device/driver/module`  

ls: cannot access '../../../../module/cdc_ether': No such file or directory  
  • Please post the contents as text rather than a screenshot. – l0b0 Jun 13 at 3:49
  • What's impossible about it? ls dereferences the symlink by default, and doesn't for ls -l. – muru Jun 13 at 4:05
  • @muru shouldn't deferencing show me "../../../../module/cdc_ether" as the "readlink" command subsequently shows ? ls follows the link to a directory while readlink follows it to something else ? – explorest Jun 13 at 4:09
  • readlink doesn't do any following (I think you need -f for that), it just printed the target of the link. The last ls just gets a relative path, and you're in the wrong directory for it. – muru Jun 13 at 4:26
  • Oh ok --- now I got it -- I was confused about a couple of things-- 1. I thought "cdc_ether" was a file. And /sys/class/net/enp0s20u1/device/driver/module a symlink to it. Its not, its actually a directory. 2. I didn't know that "../../../../module/cdc_ether" is actually relative to the location of the symlink and not my present working directory. Which made it difficult to find "cdc_ether". Now everything solved. Thanks for the comments :) – explorest Jun 13 at 4:48
1

The link is relative, so you need to change to its parent directory for your last command to work:

cd /sys/class/net/enp0s20u1/device/driver
ls `readlink module`

Alternatively, you can ask readlink to canonicalise the link:

ls `readlink -e /sys/class/net/enp0s20u1/device/driver/module`
  • Oh ok --- now I got it -- I was confused about a couple of things -- (1) I thought "cdc_ether" was a file. And /sys/class/net/enp0s20u1/device/driver/module a symlink to it. Its not, its actually a directory. (2). I didn't know that "../../../../module/cdc_ether" is actually relative to the location of the symlink and not my present working directory. Which made it difficult to find "cdc_ether". Now everything solved. Thanks for the comments :) – – explorest Jun 13 at 4:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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