LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-10-2006, 01:11 PM   #1
hawkmauk
LQ Newbie
 
Registered: Mar 2005
Location: Lincolnshire
Distribution: Ubuntu
Posts: 14

Rep: Reputation: 0
absolute path results with ls


I would like to use the command ls -R to search for files in various directories but I need an absolute path so as I can use the results in additional script.
I've had a look through the man pages but can't find anything on the subject, could anyone shed some light on this one for a newbie?
 
Old 01-10-2006, 01:30 PM   #2
allelopath
Member
 
Registered: Jan 2003
Location: New Mexico
Distribution: Ubuntu 18.04.3 LTS
Posts: 539

Rep: Reputation: 30
Could you do a 'pwd' and append the path from ls -R to it?
 
Old 01-10-2006, 01:46 PM   #3
puffinman
Member
 
Registered: Jan 2005
Location: Atlanta, GA
Distribution: Gentoo, Slackware
Posts: 217

Rep: Reputation: 31
You might try locate for faster results and absolute paths.
 
Old 01-10-2006, 01:59 PM   #4
hawkmauk
LQ Newbie
 
Registered: Mar 2005
Location: Lincolnshire
Distribution: Ubuntu
Posts: 14

Original Poster
Rep: Reputation: 0
the files im searching for are in subdirectories of the pwd and the results are being used with grep as in
Code:
ls -R | grep "001.jpg"
for more info on the main application im working on see the thread 'Populating array in a "for .. in .." loop' lower down on this page - (sorry I can't link until I've posted 5 times)
 
Old 01-10-2006, 02:07 PM   #5
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
you'll want to use find.

# man find
# find . | grep "001.jpg"
 
Old 01-10-2006, 02:28 PM   #6
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
find -name "001.jpg"



Cheers,
Tink
 
Old 01-10-2006, 02:33 PM   #7
hawkmauk
LQ Newbie
 
Registered: Mar 2005
Location: Lincolnshire
Distribution: Ubuntu
Posts: 14

Original Poster
Rep: Reputation: 0
Thanks thats a lot quicker and I didn't realise that the pipe could go both ways until you showed me that bit of code!
 
Old 01-10-2006, 05:53 PM   #8
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
Quote:
Originally Posted by hawkmauk
[..] I didn't realise that the pipe could go both ways [..]
That's not what happens.

If you want the full path, try this:
Code:
find $PWD -name '*001.jpg'
 
Old 01-12-2006, 05:21 AM   #9
hawkmauk
LQ Newbie
 
Registered: Mar 2005
Location: Lincolnshire
Distribution: Ubuntu
Posts: 14

Original Poster
Rep: Reputation: 0
Thanks for all the feedback, the script works great with your help. But now im thinking of trying to recreate it using C, would anyone consider this to be better than using BASH?

It does call a java program to combine PDFs, would this cause a problem?

Code:
#!/bin/bash/
# This program combines multiple PDFs into a single multipage pdf

filedir=~/Desktop/Process/;		#text input files here
workdir=~/Desktop/OnlinePDF/;		#single pdf pages here
workfile=$1;				#name of text file passed at command
filename="$workfile"_`date +%h%d_%H%M`;	#name of output file

cd $workdir;
myfiles=( $(cat $filedir$workfile | while read part; do find . | grep $part; done ) );

#java program to combine pdf pages
joinPDF $filename.pdf ${myfiles[*]};

exit 0
 
Old 01-12-2006, 11:22 AM   #10
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
It wouldn't cause a problem... but does it really make sense,
considering that most of the CPU cycles are going to be spent
on Java, anyway? I don't think you'd gain much performance,
since the majority of the actual processing in the bash-script
won't be the loop but a) the highly optimized find & grep (I
doubt that you'll write more efficient C code) and b) the chubby
java ... ;}


Cheers,
Tink
 
Old 01-12-2006, 01:15 PM   #11
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
i'd say as an excersize to sharpen your c is worth it.

off the top of my head, i would system(find) then strcmp(filename) //is there a function that does what find would do?

but like what tin said, not many mips you can buy.

in my college days i had a lab to create a 'my-ls', but i lost the source code...

Last edited by schneidz; 01-12-2006 at 01:17 PM.
 
Old 01-16-2006, 12:49 PM   #12
hawkmauk
LQ Newbie
 
Registered: Mar 2005
Location: Lincolnshire
Distribution: Ubuntu
Posts: 14

Original Poster
Rep: Reputation: 0
Thanks for the tips, I am only getting to grips with c and am treating the program as an exercise (although it does do an important job of saving me precious time at work!). My main reasoning for using c is to build in error checking and a user interface for my collegues who are command line shy and only use GUI's.
 
Old 01-16-2006, 09:33 PM   #13
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,358

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
Good idea to implement it completely in C then, as calling system() means creating a new process env each time. Big overhead if you are calling within a loop.
 
  


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
Absolute path qspares Linux - Software 6 10-02-2007 03:11 AM
Image Path reference in Linux (Absolute path) javabuddy Linux - General 7 06-05-2006 07:45 AM
HTML + href absolute path does not work blizunt7 Programming 3 11-21-2005 04:59 PM
how to get absolute path of current executing C/C++ prog? Thinking Programming 2 10-10-2005 10:27 AM
absolute path to qmail in sme 5.6? dopper Linux - Software 0 10-28-2003 01:48 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:06 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