tags:

views:

74

answers:

4
find . -type f -print

prints out

./file1
./file2
./file3

Any way to make it print

file1
file2
file3

?

+2  A: 

If they're only in the current directory

find * -type f -print

Is that what you want?

Tim Green
I knew it could be done with sed, but this is a much better solution. Thanks!
breadjesus
nice, never thought about that
Lie Ryan
This will miss files with names that start with a period.
Sean
Bad, depending on a shell settings * may not evaluate to "hidden" files/directories -- those which begins with dot (.) Try to run this command in your home dir, then just "find -type f" and see the difference.
Ilia K.
While, overall, this is a good point, I don't think it applies to this context. If anything, it just makes it more useful. Nothing more annoying then listen your root and getting files like bashrc, htaccess and bash_history.
Tim Green
A more relevant concern is that '*' is evaluated by the shell. You effectively have a type of malicious code injection situation. It would be trivial to create a file named ' --exec rm ' and another named 'zzzz ;'. Goodbye files.
CWF
A: 

Use sed

find . | sed "s|^\./||"
Lie Ryan
A: 

it can be shorter

find * -type f
ghostdog74
A: 

Find only regular files under current directory, and print them without "./" prefix:

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

From man find, description of -printf format:

%P File's name with the name of the command line argument under which it was found removed.

Ilia K.