get file name from find command


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users get file name from find command
# 1  
Old 03-04-2008
get file name from find command

how can i get the find command to display the filename without the path.

example:

find /tmp/test

/tmp/test1
/tmp/test2
/tmp/test3

should return

test1
test2
test3

i'm using bash.

also, whats the best way to ignore the . and .. directories?

thanks!
# 2  
Old 03-04-2008
find . -name "test*" |awk -F/ '{print $NF}'
# 3  
Old 03-04-2008
hi,

i hope the below will work for you,

basename `find .....`

basename ---> diplays only the file name.
# 4  
Old 03-04-2008
Quote:
Originally Posted by pooga17
find . -name "test*" |awk -F/ '{print $NF}'
thanks this worked great!

any good ideas on an easy way to filter out the . and .. ?
# 5  
Old 07-18-2008
Question

Hi Thanks it is working .... I have doubt

I want to list the files in a particular directory having *.dat without displaying the pathnames.


Ex: /home/usr/local/data
in this directory I have 5 dat files

I want to list the files of this directory with out displaying the path from home directory ..

Plz help me
# 6  
Old 07-18-2008
@madankumar
Please check your original thread:
https://www.unix.com/unix-dummies-que...tory-path.html

No need to hijack this one Smilie

Quote:
Hi Thanks it is working .... I have doubt
pooga17's solution works, so where is the doubt... you just have to modify the starting path and the name you are looking for...
This User Gave Thanks to zaxxon For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

wanted to find both link file and ordinary file using single find command

find . -type fl o/p is only the ordinary file. where in it wont give the link files. (2 Replies)
Discussion started by: nikhil jain
2 Replies

2. Shell Programming and Scripting

find specific file names and execute a command depending on file's name

Hi, As a newbie, I'm desperate ro make my shell script work. I'd like a script which checks all the files in a directory, check the file name, if the file name ends with "extracted", store it in a variable, if it has a suffix of ".roi" stores in another variable. I'm going to use these two... (3 Replies)
Discussion started by: armando110
3 Replies

3. Shell Programming and Scripting

Find multiple string in one file using find command

Hi, I want find multiple string in one file using find coomand. And keeping it in one variable.grep is not working. (5 Replies)
Discussion started by: vivek1489
5 Replies

4. Shell Programming and Scripting

How to use grep & find command to find references to a particular file

Hi all , I'm new to unix I have a checked project , there exists a file called xxx.config . now my task is to find all the files in the checked out project which references to this xxx.config file. how do i use grep or find command . (2 Replies)
Discussion started by: Gangam
2 Replies

5. Linux

Simplified find command to find multiple file types

Hi, I'm using the following command to find the multiple requierd file types and its working fine find . -name "*.pl" -o -name "*.pm" -o -name "*.sql" -o -name "*.so" -o -name "*.sh" -o -name "*.java" -o -name "*.class" -o -name "*.jar" -o -name "*.gz" -o -name "*.Z" -type f Though... (2 Replies)
Discussion started by: vickramshetty
2 Replies

6. Shell Programming and Scripting

Find command - First file only

How can I use the find command to list only first file that matches the name for example dir/dir1/file1 dir/dir2/file1 dir/dir3/dir4/file1 find dir -name file1 I just want to print dir/dir1/file1 Thanks (3 Replies)
Discussion started by: neeto
3 Replies

7. Shell Programming and Scripting

how to use find command to get latest file

Is there a way to use find command to get the latest file and cp it into a certain dir at the same try. example find the latest file and cp to a diff dir. (5 Replies)
Discussion started by: shehzad_m
5 Replies

8. UNIX for Dummies Questions & Answers

how to find a file named vijay in a directory using find command

I need to find whether there is a file named vijay is there or not in folder named "opt" .I tried "ls *|grep vijay" but it showed permission problem. so i need to use find command (6 Replies)
Discussion started by: amirthraj_12
6 Replies

9. UNIX for Advanced & Expert Users

How to use the command Tar to find a file

Hello, I am just using the command Tar to find if a file was backuped on my tape. Can you help me with that command. I am using the command : tar -tvf /dev/rmt/4m /kcc_dms/AC7/c15a* > toto.txt to find all files c15a* in these subdirectories on my tape. But it doesn't work correctly. Can... (2 Replies)
Discussion started by: steiner
2 Replies

10. Shell Programming and Scripting

how to find a file in UNIX without find command?

given a start directory,a filename,how to find it? (3 Replies)
Discussion started by: bluo
3 Replies
Login or Register to Ask a Question