DEV.MD / Developer Network
Search:     Advanced search
Browse by category:
Glossary | Contact Us

Remove path from find result in Bash

Add comment
Views: 623
Votes: 0
Comments: 0
Posted: 16 Apr, 2010
by: Zavadschi S.
Updated: 16 Apr, 2010
by: Zavadschi S.
Find all .sh files from current directory.

$ find . -name "*.sh"

./als.sh
./engine/a.sh
./engine/mysc.sh
./tools/new/slv.sh
./tools/instant-parse/iparse.sh

Now if we need to remove the path part from the above find command output:

$ find . -name "*.sh" -exec basename {} \;

als.sh
a.sh
mysc.sh
slv.sh
iparse.sh


Same as

$ find . -name "*.sh" | xargs -i basename {}

And using sed:

$ find . -name "*.sh" | sed 's!.*/!!'

i.e. replace all characters until last / by nothing (here ! is used as the sed delimiter instead of the usual /)
Others in this Category
document Remove Empty Lines and Comments
document Lab Exam and sample solutions
document Detach a working copy from SVN or CVS
document Standard Input and Output Redirection



RSS