LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Slackware (https://www.linuxquestions.org/questions/slackware-14/)
-   -   Find to File.txt no Path (https://www.linuxquestions.org/questions/slackware-14/find-to-file-txt-no-path-4175586629/)

perfection 08-08-2016 10:35 PM

Find to File.txt no Path
 
I would like to know how to send the result of the find without the path

I Try:
Code:

find * -type f > List1.txt
find * -exec echo "{}" >> List2.txt \;

Results:
x86_64-kde/kdepim/kidentitymanagement-16.04.3-x86_64-1alien.txz
x86_64-kde/kdepim/libksieve-16.04.3-x86_64-1alien.txz
x86_64-kde/kdepim/libgravatar-16.04.3-x86_64-1alien.txz
x86_64-kde/kdepim/kontactinterface-16.04.3-x86_64-1alien.txz
x86_64-kde/kdepim/akonadi-calendar-16.04.3-x86_64-1alien.txz

I would like a result like this:
Code:

kidentitymanagement-16.04.3-x86_64-1alien.txz
libksieve-16.04.3-x86_64-1alien.txz
libgravatar-16.04.3-x86_64-1alien.txz
kontactinterface-16.04.3-x86_64-1alien.txz
akonadi-calendar-16.04.3-x86_64-1alien.txz


chris.willing 08-08-2016 10:44 PM

find * -type f | rev | cut -d '/' -f 1 | rev

perfection 08-08-2016 10:48 PM

Quote:

Originally Posted by chris.willing (Post 5588248)
find * -type f | rev | cut -d '/' -f 1 | rev

WOW! It worked! Thank you so much!

Diantre 08-08-2016 11:27 PM

find * -type f -printf '%f\n'

chris.willing 08-08-2016 11:39 PM

Quote:

Originally Posted by Diantre (Post 5588266)
find * -type f -printf '%f\n'

Yep, more concise and a little bit faster :thumbsup:

perfection 08-09-2016 05:13 AM

Quote:

Originally Posted by Diantre (Post 5588266)
find * -type f -printf '%f\n'

It worked!

kjhambrick 08-09-2016 05:44 AM

Diantre --

Thanks !

That's a keeper.

This
Code:

find . -type f -printf '%f\n'
Is MUCH better than the old-way I USED to do it:

Code:

for File in $(find . -type f -print)
do
  [ ! -z "$File" ] && basename $File || continue
done

Thanks again !

I'll be using your find..printf '%f\n' construct from now on -- there are a LOT of handy printf args for the `find` command in there !

-- kjh( :) gotta remember to review the man pages from time-to-time :) )


All times are GMT -5. The time now is 11:07 AM.