LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
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 10-08-2012, 04:27 PM   #1
Stragonian
Member
 
Registered: Dec 2003
Location: Indiana
Distribution: Slackware & PassionX
Posts: 61

Rep: Reputation: 23
Smile List file with path from current working directory


I was looking for a command that could quickly locate a file within a newly mounted device, i.e. ... a dvd, or thumb drive. I could not find one so I wrote one. I placed it in my /bin directory.

I call it lsp ( List w/ Path ) if it finds the file it will list the path from the current working directory.

Code:
#!/bin/bash
# Simple list file with path from CWD

FILE=$1
find . -print | grep "$FILE" | sed -e 's/^\.\///g'
Usage:

Code:
$ lsp file-name
Usage Example:

Code:
$ cd /var/log
$ lsp sip
packages/sip-4.13.2-x86_64-2
I find it useful!

Last edited by Stragonian; 10-09-2012 at 09:35 AM.
 
Old 10-08-2012, 04:55 PM   #2
Stragonian
Member
 
Registered: Dec 2003
Location: Indiana
Distribution: Slackware & PassionX
Posts: 61

Original Poster
Rep: Reputation: 23
Oh, and my list absolute path

Looking on the internet a lot more people seem to be looking for an absolute path.
lap ( List Absolute Path ) from the current working directory.

Code:
#!/bin/bash
# Simple list absolute path

FILE=$1
CWD=$( pwd )

find . -print | grep "$FILE" | sed "s:^\.:$CWD:g"
Hope it works for you!

Last edited by Stragonian; 10-08-2012 at 05:03 PM.
 
Old 10-08-2012, 07:18 PM   #3
unSpawn
Moderator
 
Registered: May 2001
Posts: 27,132
Blog Entries: 54

Rep: Reputation: 2790Reputation: 2790Reputation: 2790Reputation: 2790Reputation: 2790Reputation: 2790Reputation: 2790Reputation: 2790Reputation: 2790Reputation: 2790Reputation: 2790
Quote:
Originally Posted by Stragonian View Post
Code:
find . -print | grep "$FILE" | sed -e 's/\.\///g'
Shouldn't this just do?
Code:
find . -type f -iname \*$1\* -printf "%h/%f\n"
It saves you a grep, can find partial names and the "./" at the start of the output is cosmetic in that "stat ./packages/sip-4.13.2-x86_64-2" shows its equals to "stat packages/sip-4.13.2-x86_64-2".
 
Old 10-09-2012, 09:39 AM   #4
Stragonian
Member
 
Registered: Dec 2003
Location: Indiana
Distribution: Slackware & PassionX
Posts: 61

Original Poster
Rep: Reputation: 23
Thanks You, your command line works nicely too.
 
  


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
[SOLVED] How to get the absolute path of the running executable file and current work path ? 915086731 Programming 3 11-01-2011 09:28 AM
List file names in a directory WITHOUT the path dexus Linux - Newbie 13 06-13-2009 07:22 PM
edit path environment variable to include current working directory alb1954 Linux - Newbie 8 07-11-2004 11:26 PM
How to change the path of the current directory ? ndha Linux - General 7 12-03-2003 11:05 AM


All times are GMT -5. The time now is 02:41 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration