Remove leading dot and slash on relative paths with find


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Remove leading dot and slash on relative paths with find
# 1  
Old 12-21-2014
Remove leading dot and slash on relative paths with find

When I specify a directory by name the leading ./ is not shown:
Code:
$ find somedir/
somedir/a.bin
somedir/target/out.bin

But when I specify current dir it adds the ./ to the beginning of each result:
Code:
$ find . | grep somedir
./somedir/a.bin
./somedir/target/out.bin

Is there any particular reason why find behaves like that and how to fix?

---------- Post updated at 03:21 PM ---------- Previous update was at 02:39 PM ----------

I answer to myself:

Code:
find . | sed -e "s/^\.\///g"

I don't use bash asterisk wildcard expansion because of ARG_MAX limit on some systems:
Code:
find * -type f

The maximum length of arguments for a new process
# 2  
Old 12-22-2014
Hello Tribe,

Could you please try following and let us know if this helps, for me it works well(I am using bash).
Code:
find -type f -printf '%P\n'

You can check it in man find as follows too.
Quote:
%P File's name with the name of the command line argument under which it was found removed.
Thanks,
R. Singh
# 3  
Old 12-22-2014
Quote:
Originally Posted by RavinderSingh13
Hello Tribe,

Could you please try following and let us know if this helps, for me it works well(I am using bash).
Code:
find -type f -printf '%P\n'

You can check it in man find as follows too.


Thanks,
R. Singh
printf is not available on android, os x or freebsd so isn't really portable. I'll stick with the sed option.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Remove prefixes before dot

Shell : Bash shell I have a text file with entries like below srv.sr_num sr_number, atvx.ATTRIB_37 Product_Name, ktx.X_ATTRIB_52 Product_Type, mkx.created sr_created_date, nbv.sr_cat_type_cd sr_type, bkrx.sr_area sr_category, .. frx.order_id, des.stats_name , fpxg.current_id_name, ...... .... (3 Replies)
Discussion started by: John K
3 Replies

2. Shell Programming and Scripting

Show only the filenames under a directory without relative and absolute paths.

I am able to list all the filenames under a directory & its sub-directories except blent.tar on Linux find "/tmp/" -type f | grep -v blent.tar | rev | cut -d '/' -f1 | rev Desired Output: THIRDPARTYLICENSEREADME.txt javaws libjavaplugin_oji.so libjavaplugin_oji.so... (3 Replies)
Discussion started by: mohtashims
3 Replies

3. UNIX for Dummies Questions & Answers

Inspecting leading char in string for slash

In a SCO Unix shop, I am working on the following script to move any file to its same location on the target machine (called 'othersy' here): pwd=`pwd` for i in "$@" do echo " $i " if ; then echo 1; else echo 0; fi rcp -p $i othersy:$pwd/$i echo "Finished with ^ If I find a file... (4 Replies)
Discussion started by: wbport
4 Replies

4. Shell Programming and Scripting

Substitution to remove tailing slash?

Heyas I am trying to remove a tailing space, with substitution. Already tried some multiple escapes with no luck, is that even possible? echo $CHROOT || \ CHROOT="${CHROOT/\/$}" echo $CHROOT return And all i get is: :) paths $ CHROOT=/usr/local/ + paths $ . * /usr/local/ /usr/local/... (2 Replies)
Discussion started by: sea
2 Replies

5. Shell Programming and Scripting

Need to remove slash

I got stuck in problem i need to remove slash but it is not working. current output /usr/sbin/httpd expected output usr sbin httpd (4 Replies)
Discussion started by: learnbash
4 Replies

6. Shell Programming and Scripting

how to remove a variable starting with dot using sed command

Hi, I want to remove a variable starting with dot(.) in a file using sed command. aaa sss .abc s/^\.abc/d I tried this but it didnt worked. (5 Replies)
Discussion started by: vdhingra123
5 Replies

7. Shell Programming and Scripting

tar and relative paths

HOw can I create a tar file with relative paths find . -depth -print | xargs tar -cvf /tmp/file.tar ? Thanks to all who answer (1 Reply)
Discussion started by: BeefStu
1 Replies

8. UNIX for Dummies Questions & Answers

Absolute and Relative Paths?

Can someone cofirm that I have got the paths correct here? :confused: $PATH_TO_TMP_DIR='/tmp'; #$PATH_TO_TMP_DIR='home/tmp'; $PATH_TO_YOUR_IMG_DIR = '/temp_images'; #$PATH_TO_YOUR_IMG_DIR = 'home/public_html/Midwich/temp_images'; Thanks (1 Reply)
Discussion started by: stubie
1 Replies

9. Shell Programming and Scripting

Not able to remove leading spaces

Hi Experts, In a file tht i copied from the web , i am not able to remove the leading white spaces. I tried the below , none of them working . I opened the file through vi to check for the special characters if any , but no such characters found. Your advice will be greatly appreciated. sed... (5 Replies)
Discussion started by: panyam
5 Replies

10. UNIX for Dummies Questions & Answers

get cygpath to leave relative paths as relative?

If I execute mypath=`cygpath -w ../` echo $mypath I get d:\unix\nextVersion\script OK, d:\unix\nextVersion\script is the correct windows version of the path, but it is in absolute form. I would prefer it if cygpath left it in relative form, i.e. echo $mypath should output ..\ ... (0 Replies)
Discussion started by: fabulous2
0 Replies
Login or Register to Ask a Question