LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   List file with path from current working directory (https://www.linuxquestions.org/questions/linux-newbie-8/list-file-with-path-from-current-working-directory-4175431211/)

Stragonian 10-08-2012 04:27 PM

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!

Stragonian 10-08-2012 04:55 PM

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!

unSpawn 10-08-2012 07:18 PM

Quote:

Originally Posted by Stragonian (Post 4800676)
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".

Stragonian 10-09-2012 09:39 AM

Thanks You, your command line works nicely too.


All times are GMT -5. The time now is 04:22 PM.