Results 1 to 5 of 5

Thread: ls -r returns no results

  1. #1
    Join Date
    Feb 2012
    Beans
    15

    ls -r returns no results

    Hi,

    Im using ubuntu 11.04 server edition and when i run the command "ls -r" as a root user after jsut calling "cd" it simply returns nothing, if i call "cd /etc" then "ls -r" it returns all the files and folders in the etc directory, i tried a restart, what is going on???

    Nat

  2. #2
    Join Date
    Feb 2010
    Location
    U.K.
    Beans
    782
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: ls -r returns no results

    If you are genuinely logging in as root or su'ing on Ubuntu then your current directory will be changed to root's home directory which is /root.

    There are no files in that directory that will show up in a normal ls result. Try using ls -ar to show hidden files/directories also.

    This should give you an idea:

    Code:
    crypto@ubuserver:~$ sudo su -    ## take an interactive root session
    
    root@ubuserver:~# ls             ## N.B. dir is now ~ (home) for user root
    
    root@ubuserver:~# pwd            ## Where is root's home?
    /root
    
    root@ubuserver:~# ls -ar         ## no output from the above ls use -a with ls to include hidden
    .VirtualBox  .profile  .debtags  .bashrc  .bash_history  .aptitude  ..  .
    
    root@ubuserver:~# ls -r /etc     ## ls /etc without cd'ing there first without -a
    zsh_command_not_found  popularity-contest.conf  hosts.allow
    xml                    pm                       hosts
    X11                    perl                     hostname
    wpa_supplicant         passwd-                  host.conf
    wgetrc                 passwd                   hdparm.conf
    w3m                    pam.d                    gshadow-
    vim                    pam.conf                 gshadow
    vbox                   opt                      grub.d
    .......... <snipped>
    You don't need to cd to a directory to ls it.
    Last edited by cryptotheslow; July 5th, 2012 at 05:13 AM.

  3. #3
    Join Date
    Feb 2012
    Beans
    15

    Re: ls -r returns no results

    sorry if that message was a little confusing, i know that if i am in the root directory( / ) of the server there should be a list of directories (Eg: etc, home, etc.) and files yet running the ls command returns nothing even though i know it should return something. Why is this the main problem here is i cant look up a directory that i know exists (/Shares/web) but i know it does exits because my web servers files are in that directory and my websites come up fine.

  4. #4
    Join Date
    Feb 2010
    Location
    U.K.
    Beans
    782
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: ls -r returns no results

    But what directory are you in when you try the initial cd and ls ? The cd command with no arguments does nothing - it's like saying "change directory nowhere" so you go nowhere - remain where you are.

    If you just logged in or su'd to root then you are in /root not the root directory of the filesystem /

    Use the pwd command to work out where you are or:
    Code:
    cd / && ls -r
    or

    Code:
    ls -r /
    Remember the user "root" has their home directory in /root not in the root of the filesystem which is /

  5. #5
    Join Date
    Apr 2011
    Location
    Maryland
    Beans
    1,461
    Distro
    Kubuntu 12.04 Precise Pangolin

    Re: ls -r returns no results

    Quote Originally Posted by cryptotheslow View Post
    But what directory are you in when you try the initial cd and ls ? The cd command with no arguments does nothing - it's like saying "change directory nowhere" so you go nowhere - remain where you are.

    If you just logged in or su'd to root then you are in /root not the root directory of the filesystem /

    Use the pwd command to work out where you are or:
    Code:
    cd / && ls -r
    or

    Code:
    ls -r /
    Remember the user "root" has their home directory in /root not in the root of the filesystem which is /
    Actually, if you just type 'cd', it's a shortcut to the user's home directory, which in the case of root would be /root. So, if you're running:

    Code:
    1.  cd
    2.  ls -r
    you'll probably not see anything (unless of course you put something in root's home directory).

    cryptotheslow is correct in saying that '/root' is not at all the same as '/', and if you are trying to list the contents of '/' in this way, you can either run:

    Code:
    ls -r /
    or if you really need to change directory, then run this before you run your 'ls -r' command:

    Code:
    cd /
    Again, as cryptotheslow says, verify where you are by running 'pwd'. That will help you clear up confusion in terms of where you are in the file system when you're running these commands.

Bookmarks

Posting Permissions

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