Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to only get file name with Linux 'find'?

Tags:

linux

find

shell

I'm using find to all files in directory, so I get a list of paths. However, I need only file names. i.e. I get ./dir1/dir2/file.txt and I want to get file.txt

like image 475
marverix Avatar asked Mar 28 '11 07:03

marverix


People also ask

How do I return only file names from the find command?

Normally find command will retrieve the filename and its path as one string. If you want to display only the filename, you can use basename command. find infa/bdm/server/source/path -type f -iname "source_fname_*. txt"

How do I list filenames only in Linux?

How to make ls display only filenames and file sizes in output. If you want the ls command output to only contain file/directory names and their respective sizes, then you can do that using the -h option in combination with -l/-s command line option.

How do I grep only filenames?

The standard option grep -l (that is a lowercase L) could do this. From the Unix standard: -l (The letter ell.) Write only the names of files containing selected lines to standard output.


1 Answers

In GNU find you can use -printf parameter for that, e.g.:

find /dir1 -type f -printf "%f\n" 
like image 179
SiegeX Avatar answered Oct 06 '22 00:10

SiegeX