how to get only filename in a recursively find command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to get only filename in a recursively find command
# 1  
Old 04-03-2011
how to get only filename in a recursively find command

Hi i would like to ask on how to accomplish the FF:

I want to execute a find command recursively and only get the filename something like i want only the last field set if is used ever the fieldvset as an redirection from the output of the find command

For example:

dir1/dir2/filename1
dir1/filename2
dir1/dir2/dir3/filename3
and so on
...
....

Output
filename1
filename2
filename3
filename...
....
....
# 2  
Old 04-03-2011
basename

Code:
 find -type f -exec basename {} \;

# 3  
Old 04-03-2011
Ruby(1.9+)
Code:
$ ruby -e 'Dir["**/*"].each{|x| puts File.basename(x)}'

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Find command with Metacharacter (*) Should match exact filename

Hi, Below is list of files in my directory. -rw-rw-r--. 1 Roots Roots 0 Dec 26 06:58 12345_kms_report.csv -rw-rw-r--. 1 Roots Roots 0 Dec 26 06:59 12346_kms_report.csv -rw-rw-r--. 1 Roots Roots 0 Dec 26 06:59 12347_kms_report.csv -rw-rw-r--. 1 Roots Roots 0 Dec 26 06:59... (2 Replies)
Discussion started by: Balraj
2 Replies

2. Shell Programming and Scripting

How can I use find command to search string/pattern in a file recursively?

Hi, How can I use find command to search string/pattern in a file recursively? What I tried: find . -type f -exec cat {} | grep "make" \; Output: grep: find: ;: No such file or directory missing argument to `-exec' And this: find . -type f -exec cat {} \; -exec grep "make" {} \;... (12 Replies)
Discussion started by: cola
12 Replies

3. Shell Programming and Scripting

Print filename/dir name while executing aclput using find command

Running below command , but unable to print the filename , is there way to print filename/dirname using -print option find . -type f -exec aclput -i fileacl.template {} \; (5 Replies)
Discussion started by: lalitpct
5 Replies

4. Shell Programming and Scripting

Find command error having space in filename

Hi, I am working in solaris.I am using below script to copy the files from /usr/tmp to /usr/gm But while running this it is not considering the files list after the filename having space in them. Example:- compile_custom_pll.sh conv_data_sqlload.sh conv_sqlload.sh Copy of... (5 Replies)
Discussion started by: millan
5 Replies

5. UNIX for Dummies Questions & Answers

Find command not searching recursively

I'm searching for particular scripts that contain pattern "BASIS" so I used the following command: find . -type f -print | xargs grep "BASIS" or find . -type f -exec grep "BASIS" {} \; However, I found out that the find command in the UNIX box that I'm working on doesn't find files... (6 Replies)
Discussion started by: The Gamemaster
6 Replies

6. Shell Programming and Scripting

Recursively cat files in a directory with filename printed first.

I want to recursively cat the content of files in a directory e.g. find /etc -type f -exec cat {} \; But I want it to print the file name first and then the content. For example let's say /etc/statetab and /etc/colord.conf will be printed first then I want the output to look something like; ... (6 Replies)
Discussion started by: lewk
6 Replies

7. Shell Programming and Scripting

Only filename from find command

Hi All When we use find command command in Unix we get the result as /home/user/folder/filename1 /home/user/folder/filename2 /home/user/folder/filename3 Is it possible that i only get the file name The expected output when using find command is filename1 filename2 filename3 I am... (13 Replies)
Discussion started by: parthmittal2007
13 Replies

8. Shell Programming and Scripting

Howto get only filename from find command in Linux?

Hi every body! I would like to get only filename in the result of find command in Linux but I don't know howto. Tks so much for your helps. (5 Replies)
Discussion started by: nguyendu0102
5 Replies

9. Shell Programming and Scripting

remove special characters from filename recursively

hi: i have several thousand files from users and of course they use all kind of characters on filenames. I have things like: My special report (1999 ) Lisa & Jack's work.doc crazy. How do I remove all this characters in the current dir and subdirs too? Thanks. (3 Replies)
Discussion started by: jason7
3 Replies

10. UNIX for Dummies Questions & Answers

search for hardlinks based on filename via find command

I am using command substitution into a find command in a script where I have built a menu to do a bunch of tasks within my unix account. When I choose the options for to find a file/files that have the same inode of the entered filename, ie hardlinks, nothing shows up. When I choose the appropiate... (2 Replies)
Discussion started by: hunternjb
2 Replies
Login or Register to Ask a Question