Find the answer to your Linux question:
Results 1 to 2 of 2
Hello! I'm new to Linux and I'm trying to get some little scripts working (Kornshell). First of all, I have a problem with ls -L . In my opinion, this ...
  1. #1
    Just Joined!
    Join Date
    Jun 2010
    Posts
    1

    Problem with ls -L and a question concerning recursion

    Hello!

    I'm new to Linux and I'm trying to get some little scripts working (Kornshell).

    First of all, I have a problem with ls -L. In my opinion, this command should return some information about the file a given softlink refers to. But that doesn't work.

    My test run:

    Home Directory: contains a file named file1 and a directory, named directory1.

    1. I created a soflink in the same directory with ln -s file1 file2
    2. I created a softlink in the subdir (directory1) with ln -s file1 directory1/file2
    3. ls -L file2 in the home dir returns only the name "file2".
    4. cd directory1; ls -L file2 returns something like "ls: cannot access file2: No such file or directory"

    What is going wrong?

    Outstanding: SSH shows several colours per file.
    File1 is green (like all normal files), File2 is turquoise and directory1/file2 is red/orange on a black background ?!


    My second problem is this script which should walk through directories, recursive.

    Code:
    #!/usr/bin/ksh
    
    function walk_recursive
    {
    typeset list=$(ls $1)
    
    for k in $list
    do
            path=$1/$k
    
            if test -d $path
            then
                    print "found dir: $path"
                    walk_recursive $path
            fi
    
            if test -f $path
            then
                    print "found file: $path"
            fi
    done
    }
    All in all, it works. But: in a subdirectory, the last file is shown twice. Example: i take the directory-structure from above and i get:

    found file: /xxx/bash/file1
    found file: /xxx/bash/file2
    found dir: /xxx/bash/directory1/
    found file: /xxx/bash/directory1/file2
    found file: /xxx/bash/directory1/file2


    When i add a new file to the subdirectory, it is:

    found file: /xxx/bash/file1
    found file: /xxx/bash/file2
    found dir: /xxx/bash/directory1/
    found file: /xxx/bash/directory1/file2
    found file: /xxx/bash/directory1/file3
    found file: /xxx/bash/directory1/file3

    Why?



    Sorry for my bad english.
    Thank you!

  2. #2
    Trusted Penguin Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,230
    So your "ls" problems. "ls -L" only affects file information, not the file name. So you need to print out the long listing:
    Code:
    ls -lL file2
    This will print out the name "file2", but the permissions, size, etc. of file1.

    For the subdirectory link, "ln -s <target> <link>" creates <link> that links to exactly the file <target>. So if you run the command:
    Code:
    ln -s file1 directory/file2
    Then a link "file2" is created in the subdirectory for a file called "file1" THAT ALSO EXISTS IN THE SUBDIRECTORY. This is why you should always use absolute paths for the target of a symbolic link.

    I'm not sure about the scripting problem: I will think about this a bit.
    DISTRO=Arch
    Registered Linux User #388732

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...