LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


Reply
  Search this Thread
Old 06-15-2011, 05:46 PM   #1
AndrewJS
LQ Newbie
 
Registered: Dec 2010
Posts: 16

Rep: Reputation: 0
the ins and outs of "ls"


First off, I should say that I posted a similar query about pathnames (specifically how to remove them) on linuxquestions quite recently and it was helpfully answered. The following question is a little different....:

I am have trouble getting the ls command to work exactly how I want, for example, sometimes I want to list the contents of a directory into a text file by command:
Code:
ls directory > list.txt
(assume the only objects the directory contains are files with extension .dat eg file1.dat, file2.dat, ...)sometimes I want the relative path of the files prepended to them in my text file eg:

path/file1.dat
path/file2.dat
path/file3.dat
etc....

other times I want just the file name and not the path, eg.:

file1.dat
file2.dat
file3.dat
etc.

It feels like ls is unpredictable in this regard - sometimes it prepends the path and sometimes it doesn't and sometimes it adds both entries (with and without the path prepended into the text file)....How can better control the way ls works?
 
Old 06-15-2011, 05:58 PM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,362

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
'ls' is not what you want for the dir prefix; try 'find'.
See the docs http://linux.die.net/man/1/ls http://linux.die.net/man/1/find
Another option is to write a short script, possibly based on 'ls -R'
 
Old 06-15-2011, 06:00 PM   #3
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
I agree: with "-printf" its output is configurable in ways 'ls' can't provide you with.
 
  


Reply



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
What distro is best for learning the ins and outs? adunamia Linux - General 8 12-18-2009 06:28 PM
LXer: The ins and outs of picking the best XML Parser LXer Syndicated Linux News 0 01-14-2007 02:33 PM
New to ubuntu, can someone give me the ins and outs of apt? enigma_0Z Ubuntu 2 05-25-2005 11:19 AM
"opt/openoffice.org/program/instdb.ins"can not be read?? masterguardian Linux - Software 1 08-07-2004 12:02 PM
Linux expert needed that knows INS & OUTS! Milkman00 Slackware 16 08-09-2002 05:03 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:29 AM.

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