32

How do I tell if I have a symlink, a shortcut of some sort, or a folder in Linux? Please see following screenshot.

symbolic link in linux shell

As you can see, the ls command lists objects where some are colored in dark blue while others are colored light blue (cyan). What are these cyan colored objects? Are these actual symbolic links?

As you can see, I cannot cd to the one called hdd.

root@dm500hd:/# cd hdd
-sh: cd: can't cd to hdd

I think it has to redirect to /media/hdd and I have noticed that the hdd folder is missing.

Is there a way to fix this?

Update: Here are results of the ls -al command.

symbolic link in linux shell 2

As you can see it says hdd -> /media/hdd and it's colored in red. Does this mean that it's broken or that it is automounted, i.e. when a physical hdd is connected?

Update: Here is result of the grep media /etc/auto* command.

symbolic link in linux shell 3

What do these /etc/auto.master:/media/net and /etc/auto.network entries do?

Here are results of ls -Fal /media command.

symbolic link in linux shell 4

Is this of any help?...

Here are results of stat and file commands, as well as listings of /usr and /bin.

symbolic link in linux shell 5

Does this help me in any way?... does it help you help me?...

As a side not, what you should know is that this is a Linux based STB with BusyBox, it's an embedded system. So not all commands might be supported.

Update: Last screenshot, showing files and supported commands in /sbin and /usr/sbin.

symbolic link in linux shell 6

Update: New share added...

I have now removed that old share and recreated one with the same name as before and also added a second share now. So now I have two of them.

SHARES
remote share   local share
mydream        dream1
mydream2       dream2

LOCATIONS
remote        local
C:\mydream    /media/net/dream1
C:\mydream2   /media/net/dream2

The recordings are placed in /media/net/dream1/movie.

Also, for the share dream2 I have chosen not to mount it as a HDD replacement in the Mount Manager, as I suspect that it's not possible to have more than one act as a HDD. Where would it record? To both locations? With double the data rate?... I don't think it's possible.

So for this reason there is no subfolder named movie for the dream2 share. Only the ones that are specified as HDD replacement when created get the movie subfolder.

If I cd to hdd from root it goes to /media/net/dream1. If I cd to .. (parent) it goes back to root (/).

At root ls -al gives hdd -> media/hdd. ls -al hdd gives hdd -> media/hdd. ls -al media gives /media/net/dream1.

Also, if I cd to /media there is another hdd symlink. I have not noticed it before. I think this is created automatically when a share is mounted. And if I cd to this hdd it goes to /media/net/dream1.

A symlink hdd (/hdd) that points to another hdd symlink (/media/hdd), which in turn points to the share folder (/media/net/dream1)?..... I'm getting dizzy...

It was not like this before version 3.2.3 or at least 3.2.0 of the Enigma2 image.

Edit: By settings the second share to act as a HDD replacement it becomes the active share for recording. At the same time the share that was previously set to act as a HDD replacement is no longer active, even if it is still set to "yes" (act as HDD replacement).

If dream1 was first used as HDD replacement ("yes" to act as replacement) and then dream2 is set to act as HDD replacement, it becomes the new share for recording. I can still see and view video files stored in dream1 but I can no longer record to it. If I want to go back to use dream1 for recording I first have to set dream2 to "no" (stop acting as HDD replacement) and then reset dream1 to "yes".

So no, it cannot record to two shares at the same time. One of them has to go. So it's either dream1 or dream2, not both. Although I should mention that it's possible to record more than one service (tv channel) if they are both on the same transponder, if not you get the "no free tuner" message. This is a STB with only one tuner.

7
  • 3
    please don't paste screenshots for text. copy and paste the text instead, and use the pre or code tags or backticks to preserve indentation/formatting. and edit the text down to the minimum required to show whatever it is you're trying to show. BTW, one problem with screenshots is that tiny fonts become even tinier - to the point of unreadable - when viewed on higher resolution screens (e.g. 1920x1200 or 2566x1440)...pixels are fixed, text can be scaled.
    – cas
    Sep 28, 2012 at 1:13
  • @CraigSanders Sanders You're high... on resolution! ;) Seariously, I hear you man! I didn't really think about that aspect of it. Thanks for the tip. I will try using a code block next time.
    – Samir
    Sep 29, 2012 at 19:55
  • What ls -al really does is it shows all the files (-a) in a long (-l) list. Yes, this gives me more information, but does it help me identify a symbolic link? If it has an arrow to the right, is that how I tell if it is a symbolic link? The other identifier is obviously the color code, but some of you suggest that the color is not to be trusted.
    – Samir
    Sep 29, 2012 at 20:01
  • This is no longer an issue. I mounted a Windows CIFS share through the Mount Manager plugin (Dreambox, Enigma 2, release 3.2.3) and I chose to use it as HDD replacement. After doing this the ls -al command showed hdd -> media/hdd. And now it's possible to cd to hdd and the link works. But what's interesting is that ls -al media shows hdd -> /media/net/mydream and this is in fact where it goes when I cd to hdd. The "mydream" is the name of the share. Why do I get different results?
    – Samir
    Sep 29, 2012 at 20:15
  • My guess is that there's some mechanism (possibly a udev rule) to make sure that the /hdd symlink is updated to point at whatever device or share is mounted, so that other programs and scripts can just use /hdd (after testing that the directory it points to is a mounted fs). just out of curiosity, what happens if you mount a second drive or share? Does it make a /hde symlink? or is the dreambox limited to one recording directory?
    – cas
    Sep 29, 2012 at 22:17

4 Answers 4

33

You can use file, stat or ls.

file:

The file command is used to classify files based on their type (symlink, directory, device) or content (text, gzip, image, tar, ..., regardless of their extension):

$ file /dev/stdout
/dev/stdout: symbolic link to `/proc/self/fd/1'
$ file /proc/self/fd/1
/proc/self/fd/1: symbolic link to `/dev/pts/0'
$ file /dev/pts/0
/dev/pts/0: character special (136/0)
$ file /etc/passwd
/etc/passwd: ASCII text

ls:

$ ls -al /dev/stdout
lrwxrwxrwx 1 root root 15 Jan 27 07:55 /dev/stdout -> /proc/self/fd/1

stat:

the stat command prints out file metadata like permissions, size, number of blocks and so on...

$ stat /dev/stdout
  File: ‘/dev/stdout’ -> ‘/proc/self/fd/1’
  Size: 15          Blocks: 0          IO Block: 4096   symbolic link
Device: 5h/5d   Inode: 1212        Links: 1
Access: (0777/lrwxrwxrwx)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2014-01-27 11:22:47.971187828 -0200
Modify: 2014-01-27 07:55:13.996981285 -0200
Change: 2014-01-27 07:55:13.996981285 -0200
 Birth: -
4
  • What does file hdd refer to? I don't get it...
    – Samir
    Sep 27, 2012 at 21:19
  • The stat hdd gives me -sh: stat: not found.
    – Samir
    Sep 27, 2012 at 21:21
  • I think you don't have the stat command ( or it isn't in your $PATH ). Anyway the file command can give you a shot... Oct 3, 2012 at 16:47
  • For bash on the Mac terminal the file command follows symlinks by default. If you want to see if it's a symlink add the -h command. Which doesn't follow symlinks.
    – ClintM
    Feb 17, 2016 at 14:26
8

bash:

if [[ -h dirname ]]; then
    echo "it's a symbolic link"
    if ! stat $(readlink dirname) &>/dev/null; then
        echo "link target does not exist"
    fi
fi
3

The easiest way to see what kind of entity a given file is would be to use the file command. It has clear, sane output without requireing you to remember what the ls classifier marks are, or relying on colored output which can vary from user to user and machine to machine. For example:

mail ~ # file /test
/test: broken symbolic link to `/nonexist'
mail ~ # file /dev
/dev: directory
mail ~ # file /dev/fd
/dev/fd: symbolic link to `/proc/self/fd'

If you find yourself on a system without file you can use the stat command which will tell you what kind of a file entry it is and where it points. To find out if a link is broken you'll need to then run stat -L to dereference links, which will give an error if the link is broken.

As to the second part of your question, the media directory is often managed by automounters of some sort. The /media/hdd entry may be used by your system for USB mass storage devices or might even be waiting for the right kind of hard drive (ATA vs SCSI vs Xen block device). Broken links won't hurt anything unless a program tries to use them, and the media links are really for your convenience. You can safely leave the /hdd link or remove it as you please.

11
  • You are right, looks like file is not a command here, it says -sh: file: not found when I do file and enter.
    – Samir
    Sep 27, 2012 at 21:32
  • Sounds kind of like your $PATH is a bit restricted. Try executing it directly instead: /usr/bin/file
    – joruffin
    Sep 27, 2012 at 21:38
  • I see from your other comment that you're on a set top box. That may not have anything other than Busybox installed, and Busybox does not emulate the file command, but does have support for the stat command if it was compiled in. It still may be outside your $PATH, or living somewhere obscure like /sbin/stat or /usr/sbin/stat.
    – joruffin
    Sep 27, 2012 at 21:48
  • It doesn't look like it has support for either file or stat. I checked in the paths you mention (see screenshot above). Anyway... what you're saying is that in an ideal Linux system, the file command, followed by the search path of the target file or folder would reveal to me what kind of entity it is?
    – Samir
    Sep 27, 2012 at 22:10
  • 3
    As for the supported commands in Busybox you can run /usr/bin/busybox and it will show you all the commands it has support for, even if the commands aren't installed. To use a busybox command you can run /usr/bin/busybox <command> <parameters>. So if it says it supports the stat command you could run /usr/bin/busybox stat /hdd. For easy use you can create symlinks for Busybox with the name of the command to invoke. If it supports the stat command you could make it easy to run with ln -s /usr/bin/busybox /usr/bin/stat.
    – joruffin
    Sep 27, 2012 at 22:54
1
  1. Yes cyan are symbolic links
  2. To see where they are pointing to: ls -Fal
  3. Output ls -Fal /media

This is propably an automount-point of some kind.

grep media /etc/auto* might produce a hit.

2
  • What is an automount-point? You mean like... when I plug in a physical SATA disk drive it gets mounted to this point?... this is a Linux STB and it has no built-in HDD, but it does feature an eSATA port on the back. This might be dedicated for this purpose.
    – Samir
    Sep 27, 2012 at 21:30
  • @Sammy Yes /media is the standard mountpoint for PnP-devices.
    – Nils
    Sep 30, 2012 at 21:10

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.