LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 05-14-2008, 06:37 AM   #1
harsshal
Member
 
Registered: Jul 2006
Location: New York, NY
Distribution: redhat,ubuntu,RHEL,fedora,centOS
Posts: 105

Rep: Reputation: 15
Unhappy recursive ls


Hi,
i want to use -b feature os ls,but the problem is i need ALL the files(even from subdirs).is there any command for that?

commands like tree/find give me the files but not -b feature(append escape character)of ls
 
Old 05-14-2008, 06:50 AM   #2
hro
LQ Newbie
 
Registered: Jan 2008
Distribution: OpenSuse 10.3, SLED 10 SP2, Ubuntu 8.04 and 9.04
Posts: 23

Rep: Reputation: 15
try: ls -bR
 
Old 05-15-2008, 12:07 AM   #3
harsshal
Member
 
Registered: Jul 2006
Location: New York, NY
Distribution: redhat,ubuntu,RHEL,fedora,centOS
Posts: 105

Original Poster
Rep: Reputation: 15
thanks.but the problem is i am supposed to pass that output to a command.So i need just files.like how i can get in tree -i.
 
Old 05-15-2008, 12:28 AM   #4
DaF101
LQ Newbie
 
Registered: May 2008
Location: Australia
Distribution: Ubuntu Studio 8.04 & RH9
Posts: 23

Rep: Reputation: 15
Unhappy Re: ls command

Sorry mate but all of the ls commands that I know only show what is in your Present working directory. So I'm not to sure if there is one that exsists. but however correct me if I'm wrong.

Last edited by DaF101; 05-15-2008 at 12:29 AM. Reason: Forgot to say "Correct me if I'm wrong"
 
Old 05-15-2008, 01:14 AM   #5
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,241

Rep: Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325
As per Hro, the -R flag means recursive.
 
Old 05-15-2008, 06:40 AM   #6
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
You can parse and modify the output of ls -R before passing the output to other commands. For example, first strip out blank lines, then read the name of each directory and prepend it to any file entry. From the command below you will get a list of files with their full path, ready to be processed by other commands:
Code:
ls -1Rb | sed /^$/d | gawk '/:$/{dir=substr($0,1,length($0)-1)} !/:$/{printf "%s/%s\n",dir,$0}'
This assumes that no filename terminates with a colon, but I doubtfully believe you have such file names.
 
Old 05-15-2008, 08:58 AM   #7
hro
LQ Newbie
 
Registered: Jan 2008
Distribution: OpenSuse 10.3, SLED 10 SP2, Ubuntu 8.04 and 9.04
Posts: 23

Rep: Reputation: 15
It may be also like this
Code:
find [path...] -type f -ls | awk '{ print($11) }'
from man find
Quote:
"-ls, -fls
Unusual characters are always escaped. White space, backslash, and double quote characters are printed using C-style escaping (for example '\f', '\"'). Other unusual characters are printed using an octal escape. Other printable characters (for -ls and -fls these are the characters between octal 041 and 0176) are printed as-is."
Code:
~> ls -bR1 xDocs/test
xDocs/test:
.txt
.txt
~> find xDocs/test -type f -ls | awk '{ print($11) }'
xDocs/test/\303\266\303\244\303\245.txt
xDocs/test/\303\204\303\226\303\234.txt
Edit: There is difference in output
ls -b -> print octal escapes for nongraphic characters.
find -ls -> Unusual characters are always escaped

Last edited by hro; 05-15-2008 at 09:16 AM. Reason: Noted difference in man pages
 
Old 05-15-2008, 09:03 AM   #8
H_TeXMeX_H
LQ Guru
 
Registered: Oct 2005
Location: $RANDOM
Distribution: slackware64
Posts: 12,928
Blog Entries: 2

Rep: Reputation: 1285Reputation: 1285Reputation: 1285Reputation: 1285Reputation: 1285Reputation: 1285Reputation: 1285Reputation: 1285Reputation: 1285
Not sure if this is what you're after but if you want to list all files in the current directory recursively, try:

Code:
find -type f -printf '%f\n'
If this is not what you want, it would really help if you give us an example of what you want ...
 
Old 05-16-2008, 05:00 AM   #9
harsshal
Member
 
Registered: Jul 2006
Location: New York, NY
Distribution: redhat,ubuntu,RHEL,fedora,centOS
Posts: 105

Original Poster
Rep: Reputation: 15
ok.here is an example.

i created a file named "123!@#.pl" on Desktop.If i go on Desktop and say "vim 123tab" it auto completes it as "123/!/@#.txt".This is the kind of output i'm interested in(with escape characters).Now when i run a script on a folder it should give me all files with bad characters escaped so that i can directly pass that output to other command.
 
Old 05-16-2008, 05:05 AM   #10
harsshal
Member
 
Registered: Jul 2006
Location: New York, NY
Distribution: redhat,ubuntu,RHEL,fedora,centOS
Posts: 105

Original Poster
Rep: Reputation: 15
find [path...] -type f -ls | awk '{ print($11) }'

this gives me the closest of the answers but it fails to most annoying character of the world ' '(space).

instead of using $11 can we do something like "$11 and all following like $12,$13... if they exist"?

Last edited by harsshal; 05-16-2008 at 05:07 AM.
 
Old 05-16-2008, 05:41 AM   #11
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
Why don't you simply do the translation explicitly, using sed?
Code:
find . -type f | sed 's/[!@\ "()]/\\&/g'
this prepend the backslash to any unusual character. Complete the list of characters inside square brackets in the sed command and the trick is done.

Quote:
this gives me the closest of the answers but it fails to most annoying character of the world ' '(space).

instead of using $11 can we do something like "$11 and all following like $12,$13... if they exist"?
You don't need this, since you escape the blank space with the command above, but you can try the action -print0 to let find print fields separated by a null character instead of blank space. This is used in conjunction with the -0 option of xargs to manage files containing blank spaces in their name:
Code:
find . -type f -print0 | xargs -0 ls -l
 
  


Reply


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
recursive move stefaandk Linux - Newbie 7 10-09-2012 09:36 PM
Recursive Copy fizgig10 Linux - Newbie 1 07-17-2005 12:58 AM
Recursive compilation Genjix Programming 1 12-07-2004 08:23 AM
rm -r what is recursive wogga Linux - Software 3 05-28-2004 03:29 PM
chmod.....recursive help stateq2 Linux - General 3 03-28-2004 08:28 PM


All times are GMT -5. The time now is 10:48 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration