Find the answer to your Linux question:
Results 1 to 5 of 5
Hello, I want to print the name of directories only without slash. here what I am doing 1) when I use command ls -ld it show following drwx------ 4 root ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined! milind's Avatar
    Join Date
    Mar 2006
    Posts
    6

    List only directory name


    Hello,

    I want to print the name of directories only without slash. here what I am doing
    1) when I use command ls -ld it show following
    drwx------ 4 root root 4096 Jul 25 20:10 cpeasyapache/
    drwx------ 2 root root 4096 Feb 24 23:21 cprestore/

    if you see all the folder which are listed comes with slash in end cpeasyapache/

    Is it possible to list all the directories without having /

  2. #2
    Penguin of trust elija's Avatar
    Join Date
    Jul 2004
    Location
    Either at home or at work or down the pub
    Posts
    3,488
    You could pipe it through sed

    Code:
    ls -ld | sed s/\/$//
    What do we want?
    Time machines!

    When do we want 'em?
    Doesn't really matter does it!?


    Conkybots: Interactive plugins for your Conkys!

  3. #3
    Just Joined! milind's Avatar
    Join Date
    Mar 2006
    Posts
    6
    Thanks elija for the command it really worked but i gave error

    sed: -e expression #1, char 6: unknown option to `s'


    After searching on google i used quotes after sed and it worked.

    Code:
    ls -l | sed "s/\/$//"
    Thanks again
    Last edited by milind; 08-05-2011 at 07:12 AM.

  4. #4
    Penguin of trust elija's Avatar
    Join Date
    Jul 2004
    Location
    Either at home or at work or down the pub
    Posts
    3,488
    How strange, it worked fine without the quotes on LMDE. Maybe a different version or some kind of funky aliasing going on. Glad you got it sorted out anyway
    What do we want?
    Time machines!

    When do we want 'em?
    Doesn't really matter does it!?


    Conkybots: Interactive plugins for your Conkys!

  5. #5
    Just Joined!
    Join Date
    Aug 2011
    Posts
    7
    You are using the option -F or -p with ls (probably without you knowing it). Because the plain ls -l does not append the slash at the end of directories.

    Maybe there is an alias set for ls. Check by typing:

    Code:
    alias
    See if there is somethink like:

    Code:
    alias ls='ls -hF --color=tty'
    or
    alias ls='ls $LS_OPTIONS'
    You can temporarily get rid of the alias by typing

    Code:
    unalias ls
    If you want the get rid of the alias permanently, you have to find out which start script contains the alias (~/.bashrc or the likes).

Posting Permissions

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