Unix/Linux Go Back    


Shell Programming and Scripting Unix shell scripting - KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and shell scripts and shell scripting languages here.

What's the difference between print and printf in command?

Shell Programming and Scripting


Closed    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 04-13-2012
Henryyy Henryyy is offline
Registered User
 
Join Date: Nov 2011
Last Activity: 21 June 2012, 7:05 AM EDT
Posts: 26
Thanks: 8
Thanked 1 Time in 1 Post
What's the difference between print and printf in command?

For example, in this command:


Code:
ls /etc/rc0.d/ -print
ls /etc/rc0.d/ -printf

The outputs are quite different, why?

Last edited by methyl; 04-13-2012 at 07:28 PM.. Reason: please use code tags
Sponsored Links
    #2  
Old Unix and Linux 04-13-2012
CarloM CarloM is offline Forum Advisor  
Registered User
 
Join Date: Oct 2011
Last Activity: 27 July 2016, 7:41 AM EDT
Location: London, UK
Posts: 1,108
Thanks: 125
Thanked 258 Times in 242 Posts
Because you supplied different arguments Linux.

print is probably misleading in this case - those are individual parameters 'p', 'r', etc. You should check the man page for ls to find out what each parameter actually does.
Sponsored Links
    #3  
Old Unix and Linux 04-13-2012
Henryyy Henryyy is offline
Registered User
 
Join Date: Nov 2011
Last Activity: 21 June 2012, 7:05 AM EDT
Posts: 26
Thanks: 8
Thanked 1 Time in 1 Post
Sorry, I didn't get what you mean?
    #4  
Old Unix and Linux 04-13-2012
Scrutinizer's Unix or Linux Image
Scrutinizer Scrutinizer is offline Forum Staff  
Moderator
 
Join Date: Nov 2008
Last Activity: 29 July 2016, 4:55 PM EDT
Location: Amsterdam
Posts: 10,940
Thanks: 419
Thanked 3,008 Times in 2,674 Posts
What CarloM means, is that they are not a single "-print" or "-printf" options, but rather 5 of 6 individual option flags, equivalent to:


Code:
ls -p -r -i -n -t /etc/rc0.d/


Code:
ls -p -r -i -n -t -f /etc/rc0.d/


Last edited by Scrutinizer; 04-13-2012 at 07:34 PM..
Sponsored Links
    #5  
Old Unix and Linux 04-13-2012
Henryyy Henryyy is offline
Registered User
 
Join Date: Nov 2011
Last Activity: 21 June 2012, 7:05 AM EDT
Posts: 26
Thanks: 8
Thanked 1 Time in 1 Post
Ok, I see, actually I think the difference should happen for the f. But what I got is as follows, a lot of difference:

Code:
Henry@^_^> ls /etc/rc0.d/ -printf
263966 S30urandom       263974 S90halt                 263969 S40umountfs
270822 README           263964 S10unattended-upgrades  263965 S20sendsigs
263967 S31umountnfs.sh  262250 ./                      263962 K74bluetooth
262145 ../              263961 K20speech-dispatcher
263968 S35networking    263972 S60umountroot


Code:
Henry@^_^> ls /etc/rc0.d/ -print
total 4
263965 lrwxrwxrwx 1 0 0  18 2011-09-22 00:33 S20sendsigs -> ../init.d/sendsigs
263964 lrwxrwxrwx 1 0 0  29 2011-09-22 00:33 S10unattended-upgrades -> ../init.d/unattended-upgrades
263962 lrwxrwxrwx 1 0 0  19 2011-09-22 00:33 K74bluetooth -> ../init.d/bluetooth
263961 lrwxrwxrwx 1 0 0  27 2011-09-22 00:33 K20speech-dispatcher -> ../init.d/speech-dispatcher
263974 lrwxrwxrwx 1 0 0  14 2011-09-22 00:33 S90halt -> ../init.d/halt
263972 lrwxrwxrwx 1 0 0  20 2011-09-22 00:33 S60umountroot -> ../init.d/umountroot
263969 lrwxrwxrwx 1 0 0  18 2011-09-22 00:33 S40umountfs -> ../init.d/umountfs
263967 lrwxrwxrwx 1 0 0  22 2011-09-22 00:33 S31umountnfs.sh -> ../init.d/umountnfs.sh
263966 lrwxrwxrwx 1 0 0  17 2011-09-22 00:33 S30urandom -> ../init.d/urandom
263968 lrwxrwxrwx 1 0 0  20 2011-10-16 09:47 S35networking -> ../init.d/networking
270822 -rw-r--r-- 1 0 0 353 2011-12-15 14:40 README

Moderator's Comments:
What's the difference between print and printf in command? How to use code tags

Last edited by Scrutinizer; 04-13-2012 at 07:20 PM..
Sponsored Links
    #6  
Old Unix and Linux 04-13-2012
methyl methyl is offline Forum Advisor  
Advisor
 
Join Date: Mar 2008
Last Activity: 8 June 2016, 9:58 PM EDT
Posts: 6,402
Thanks: 288
Thanked 676 Times in 645 Posts
From one example of man ls , a man page which you may wish to read on your system.

Code:
           -f   Interpret each argument as a directory and list the name
                found in each slot.  This option disables -l (ell), -r, -s,
                and -t, and enables -a; the order is the order in which
                entries appear in the directory.



Your correct command should probably be just:

Code:
ls -la /etc/rc0.d

The Following User Says Thank You to methyl For This Useful Post:
Henryyy (04-13-2012)
Sponsored Links
    #7  
Old Unix and Linux 04-13-2012
Henryyy Henryyy is offline
Registered User
 
Join Date: Nov 2011
Last Activity: 21 June 2012, 7:05 AM EDT
Posts: 26
Thanks: 8
Thanked 1 Time in 1 Post
Oh, I should really read the man page carefully...
Thanks a lot!
The Following User Says Thank You to Henryyy For This Useful Post:
methyl (04-13-2012)
Sponsored Links
Closed

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Printf command koti_rama Shell Programming and Scripting 3 04-07-2011 12:41 PM
How to print a string using printf? enigmatrix Shell Programming and Scripting 4 06-16-2010 06:59 AM
Print the difference cdfd123 Shell Programming and Scripting 3 02-15-2010 02:09 PM
How to print a % within a printf() function using awk Awanka Shell Programming and Scripting 1 04-13-2007 06:11 PM
need help with printf command nymus7 Shell Programming and Scripting 1 04-21-2005 07:05 PM



All times are GMT -4. The time now is 05:40 PM.