Latest LQ Deal: Linux Power User Bundle
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 08-07-2011, 09:57 PM   #1
Registered: Jan 2010
Posts: 189

Rep: Reputation: 15
get rid of '/' in the ls -d */ command

I want to grep all directory name in the current folder into a file.
I use ls -d */ >file.txt

It will append the "/" at the end of the directory name.
Is there a way to get rid of this?
Old 08-07-2011, 10:04 PM   #2
LQ Veteran
Registered: Nov 2005
Location: London
Distribution: Slackware64-current
Posts: 5,833
Blog Entries: 1

Rep: Reputation: 1229Reputation: 1229Reputation: 1229Reputation: 1229Reputation: 1229Reputation: 1229Reputation: 1229Reputation: 1229Reputation: 1229
You could do:
ls -d */ | sed 's/\///g'
1 members found this post helpful.
Old 08-07-2011, 10:10 PM   #3
Registered: Jul 2007
Location: Chicago Illinois
Distribution: SLES 10 SP2/SP3, SLES 11 SP1, OpenSUSE, Sabayon, Gentoo, Fedora 14, RHEL 3/4/5/6
Posts: 98
Blog Entries: 3

Rep: Reputation: 23
Try this out:
ls -d */ | tr -d '\/'
It will remove the '/' at the end. This command string will put each directory on it's own line, which may or may not be what you want.

Although I think someone got this thread first with a sed command, which basically does the same thing. 'Toe mato' vs 'to ma to'.

1 members found this post helpful.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
how to get rid of grub, from grub command line preferably slow_footed_Buffalo Linux - Software 10 03-14-2011 04:45 AM
Getting Rid Of Xp ihatewindows Linux - Software 1 01-24-2007 07:59 PM
What can I get rid of? NKYG Linux - Software 6 06-17-2004 03:19 PM
Getting rid of "\" before spaces in filenames when using the ls command Locura Linux - Distributions 8 07-05-2003 11:19 PM
Getting a rid of X AnyoneEB Linux - Software 4 09-24-2002 07:41 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:50 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration