find and "-print" switch


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting find and "-print" switch
# 8  
Old 09-04-2008
In this case, the only diff it would make is when you append > /dev/null to the end of your find stmt.. Smilie Tell me if Im wrong now.. Smilie
# 9  
Old 09-04-2008
u-pl27:~/ZKOUSKOVE/TEZSI_PRIKLADY$ find ~/ZKOUSKOVE/CVS -type f -print | xargs grep -i '.cvs' >/dev/null
u-pl27:~/ZKOUSKOVE/TEZSI_PRIKLADY$ find ~/ZKOUSKOVE/CVS -type f | xargs grep -i '.cvs' >/dev/null

So that output is <nothing> in both cases :-[
# 10  
Old 09-04-2008
I see that being oblique is confusing you. YOU DO NOT NEED TO USE -print.
The man page is confusing. Here is a more detailed answer.

There are standards for UNIX utilities - POSIX is the name used. From POSIX
Code:
STDOUT
The -print primary shall cause the current pathnames to be written to standard output. The format shall be:

"%s\n", <path>

The "funny" thing is that the standards do not say explicitly what happens to output if -print is omitted.

This means - Developer at company A is a nice guy. So he puts a printf() statement in his C code. Why? Because what use is find without output?

Meanwhile the Developer for Company B decides to follow the implicit standard: no -print equals no output.

This means that if you use find on one machine you get a situation where -print is required, but on another machine from another company (different UNIX tools) -print IS required.

I haven't seen the B version for long time, So I don't know which versions of find, if any, do the "B" thing.

With GNU tools you have to aware that they sometimes do not follow POSIX, or expand the functionality a lot. The GNU date command is like that. You have to know what OS a poster has before you can recommend something that may be part of GNU find but is not a POSIX thing - because it will not work on a non-GNU version.

Clearer?
# 11  
Old 09-04-2008
absolutely, thank you! Smilie
(I'm sorry but it's part of my personality I always want to know how things exactly work O:-) )
# 12  
Old 09-04-2008
I recall actually using a platform where find did nothing (i.e. nothing useful in the very simplest usage scenario; your speculations about when omitting it might be useful are pretty clueful!) if you didn't include the -print -- unfortunately my memory is hazy, probably SunOS or OSF/1.
# 13  
Old 09-04-2008
Sometimes you may need to write a code like this:

Code:
% find
.
./unwanted_dir
./unwanted_dir/unwanted_file
./wanted_dir
./wanted_dir/wanted_file
% find -name unwanted_dir -prune -o -print
.
./wanted_dir
./wanted_dir/wanted_file

# 14  
Old 09-04-2008
Originally, find would produce no output unless you told it to with -print. This was a source of confusion for newbies, so when posix came out, it specified that the -print was assumed. (Didn't help much with the confusion, did it?) Now you only need -print in relatively complex commands.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies

2. Shell Programming and Scripting

Why awk print is strange when I set FS = " " instead of FS = "\t"?

Look at the following data file(cou.data) which has four fields separated by tab. Four fields are country name, land area, population, continent where it belongs. As for country name or continent name which has two words, two words are separated by space. (Data are not accurately... (1 Reply)
Discussion started by: chihuyu
1 Replies

3. Shell Programming and Scripting

find . -path "*_nobackup*" -prune -iname "*.PDF" \( ! -name "*_nobackup.*" \)

These three finds worked as expected: $ find . -iname "*.PDF" $ find . -iname "*.PDF" \( ! -name "*_nobackup.*" \) $ find . -path "*_nobackup*" -prune -iname "*.PDF" They all returned the match: ./folder/file.pdf :b: This find returned no matches: $ find . -path "*_nobackup*" -prune... (3 Replies)
Discussion started by: wolfv
3 Replies

4. Shell Programming and Scripting

Find lines with "A" then change "E" to "X" same line

I have a bunch of random character lines like ABCEDFG. I want to find all lines with "A" and then change any "E" to "X" in the same line. ALL lines with "A" will have an "X" somewhere in it. I have tried sed awk and vi editor. I get close, not quite there. I know someone has already solved this... (10 Replies)
Discussion started by: nightwatchrenba
10 Replies

5. Shell Programming and Scripting

Awk find in columns with "if then" statement and print results

I have a file1.txt file1.txt F-120009210","Felix","U-M-F-F-F-","white","yes","no","U-M-F-F-F-","Bristol","RI","true" F-120009213","Fluffy","U-F-","white","yes","no","M-F-","Warwick","RI","true" U-120009217","Lity","U-M-","grey","yes","yes","","Fall River","MA","true"... (4 Replies)
Discussion started by: charles33
4 Replies

6. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

7. Solaris

How to check "faulty" or "stalled" print queues - SAP systems?

Hi all, First off, sorry for a long post but I think I have no other option if I need to explain properly what I need help for. I need some advise on how best to check for "faulty" or "stalled/jammed' print queues. At the moment, I have three (3) application servers which also acts as print... (0 Replies)
Discussion started by: newbie_01
0 Replies

8. Shell Programming and Scripting

cat $como_file | awk /^~/'{print $1","$2","$3","$4}' | sed -e 's/~//g'

hi All, cat file_name | awk /^~/'{print $1","$2","$3","$4}' | sed -e 's/~//g' Can this be done by using sed or awk alone (4 Replies)
Discussion started by: harshakusam
4 Replies

9. Shell Programming and Scripting

"find command" to find the files in the current directories but not in the "subdir"

Dear friends, please tell me how to find the files which are existing in the current directory, but it sholud not search in the sub directories.. it is like this, current directory contains file1, file2, file3, dir1, dir2 and dir1 conatins file4, file5 and dir2 contains file6,... (9 Replies)
Discussion started by: swamymns
9 Replies

10. UNIX for Dummies Questions & Answers

Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`"

Hi Friends, Can any of you explain me about the below line of code? mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'` Im not able to understand, what exactly it is doing :confused: Any help would be useful for me. Lokesha (4 Replies)
Discussion started by: Lokesha
4 Replies
Login or Register to Ask a Question