How to display only particular file location?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers How to display only particular file location?
# 1  
Old 09-12-2014
Oracle How to display only particular file location?

Hi Folks,

I tried to find a file from / directory and received big list of output like below.
Code:
$find / -name merge.txt
find: cannot read dir /var/sadm/pkg/SUNWcsmauth/save: Permission denied
find: cannot read dir /var/sadm/pkg/SUNWjpg/save: Permission denied
find: cannot read dir /var/sadm/pkg/SUNWslpr/save: Permission denied
find: cannot read dir /var/sadm/pkg/SUNWmysqlu/save: Permission denied
find: cannot read dir /var/sadm/pkg/SUNWxwcft/save: Permission denied
find: cannot read dir /var/sadm/pkg/SUNWsmagt/save: Permission denied
find: cannot read dir /var/sadm/pkg/SUNWsshu/save: Permission denied
find: cannot read dir /var/sadm/pkg/SUNWapchr/save: Permission denied
find: cannot read dir /var/sadm/pkg/SUNWopensp/save: Permission denied
find: cannot read dir /var/sadm/pkg/SUNWlibm/save: Permission denied
find: cannot read dir /var/sadm/pkg/SUNWpostgr-82-docs/save: Permission denied
find: cannot read dir /var/sadm/pkg/SUNWgcc/save: Permission denied
find: cannot read dir /var/sadm/pkg/SUNWperl-xml-parser/save: Permission denied
find: cannot read dir /var/sadm/pkg/SUNWwbapi/save: Permission denied
find: cannot read dir /var/sadm/pkg/SUNWsamr/save: Permission denied
find: cannot read dir /var/sadm/pkg/SUNWmdbr/save: Permission denied
find: cannot read dir /var/sadm/pkg/SUNWladm/save: Permission denied
find: cannot read dir /var/sadm/pkg/SUNWjai/save: Permission denied
find: cannot read dir /var/sadm/pkg/SUNWipplr/save: Permission denied
find: cannot read dir /var/sadm/pkg/SUNWdttshelp/save: Permission denied
find: cannot read dir /var/sadm/pkg/SUNWhpijs/save: Permission denied
find: cannot read dir /var/sadm/pkg/SUNWgssc/save: Permission denied
find: cannot read dir /var/sadm/pkg/SUNWiqdoc/save: Permission denied
find: cannot read dir /var/sadm/pkg/SUNWfcp/save: Permission denied
find: cannot read dir /var/sadm/pkg/SUNWj5dvx/save: Permission denied
find: cannot read dir /var/sadm/pkg/SUNWgnome-themes/save: Permission denied
find: cannot read dir /var/sadm/pkg/SUNWwbsup/save: Permission denied
find: cannot read dir /var/sadm/pkg/SUNWllc/save: Permission denied
find: cannot read dir /var/sadm/pkg/SUNWxorg-xkb/save: Permission denied
find: cannot read dir /var/sadm/pkg/SUNWgnome-desktop-prefs-share/save: Permission denied
find: cannot read dir /var/sadm/pkg/SUNWgssdh/save: Permission denied
find: cannot read dir /var/sadm/pkg/SUNWpl5v/save: Permission denied
find: cannot read dir /var/sadm/pkg/SUNWxwpmn/save: Permission denied
find: cannot read dir /var/spool/mqueue: Permission denied
find: cannot read dir /var/spool/clientmqueue: Permission denied
find: cannot read dir /var/run/smc898: Permission denied
find: cannot read dir /var/run/sudo: Permission denied
find: cannot read dir /var/fm/fmd/xprt: Permission denied
find: cannot read dir /var/fm/fmd/ckpt: Permission denied
find: cannot read dir /var/fm/fmd/rsrc: Permission denied
.....etc


Its really tough to find the file location from these many output Smilie.

I just wanted to find only the particular file with location like below.
Code:
$find . -name merge.txt
./merge.txt


Would appreciate if there is any better way to get this.

Regards,
Sri


Moderator's Comments:
Mod Comment Please use code tags next time for your code and data. Thanks

Last edited by vbe; 09-12-2014 at 05:29 AM.. Reason: code tags please
# 2  
Old 09-12-2014
Just redirect stderr to /dev/null to get rid of the error messages
Code:
find / -name merge.txt 2>/dev/null

The filename(s) found will still be printed to stdout.
This User Gave Thanks to hergp For This Post:
# 3  
Old 09-12-2014
Thanks hergp,

Great, it works well. could you tell me why we use /dev/null to redirect the stderr.
# 4  
Old 09-12-2014
The file command writes the names of the files found to stdout and error messages, if any, to stderr, so the "useful output" is separate from diagnostic messages. This is standard unix behaviour.

Normally, both outputs go to your terminal. In this case we have redirected the diagnostic output to the dump and keep only the data output connected to the terminal.

Does that help?
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Search a string and display its location on the entire string and make a text file

I want to search a small string in a large string and find the locations of the string. For this I used grep "string" -ob <file name where the large string is stored>. Now this gives me the locations of that string. Now how do I store these locations in a text file. Please use CODE tags as... (7 Replies)
Discussion started by: ANKIT ROY
7 Replies

2. Shell Programming and Scripting

Help with copying the list of files from one location to other location

A) I would like to achive following actions using shell script. can someone help me with writing the shell script 1) Go to some dir ( say /xyz/logs ) and then perform find operation in this dir and list of subdir using find . -name "*" -print | xargs grep -li 1367A49001CP0162 >... (1 Reply)
Discussion started by: GG2
1 Replies

3. Shell Programming and Scripting

How to find a existing file location and directory location in Solaris box?

Hi This is my third past and very impressed with previous post replies Hoping the same for below query How to find a existing file location and directory location in solaris box (1 Reply)
Discussion started by: buzzme
1 Replies

4. Shell Programming and Scripting

How to copy a file from one location to another location?

I have file file1.txt in location 'loc1'. Now i want a copy of this file in location 'loc2' with a new file called test.txt. Please help me how to do this in shell script. (1 Reply)
Discussion started by: vel4ever
1 Replies

5. Shell Programming and Scripting

File created in a different location instead of desired location on using crontab

Hi, I am logging to a linux server through a user "user1" in /home directory. There is a script in a directory in 'root' for which all permissions are available including the directory. This script when executed creates a file in the directory. When the script is added to crontab, on... (1 Reply)
Discussion started by: archana.n
1 Replies

6. Shell Programming and Scripting

Shell Script for Copy files from one location to another location

Create a script that copies files from one specified directory to another specified directory, in the order they were created in the original directory between specified times. Copy the files at a specified interval. (2 Replies)
Discussion started by: allways4u21
2 Replies

7. Shell Programming and Scripting

Put one string from one location to another location in a file

Hi Everyone, I have 1.txt here a b c' funny"yes"; d e The finally output is: here a b c d e' funny"yes"; (1 Reply)
Discussion started by: jimmy_y
1 Replies

8. Shell Programming and Scripting

Bash copy file contents into an existing file at a specific location

Hi all I need to copy the entire contents of one file into an existing file at a specific location. I know the exact line number where I need to put it. It appears I would use either sed or awk to do this, but I have been unsuccessful so far: File A line 1 line 2 line 3 line 4 ... (6 Replies)
Discussion started by: gshepherd7
6 Replies

9. UNIX for Advanced & Expert Users

copy files from one location to similar location

I need help in forming a script to copy files from one location which has a sub directory structure to another location with similar sub directory structure, say location 1, /home/rick/tmp_files/1-12/00-25/ here 1-12 are the number of sub directories under tmp_files and 00-25 are sub... (1 Reply)
Discussion started by: pharos467
1 Replies
Login or Register to Ask a Question