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


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting What's the difference between print and printf in command?
# 1  
Old 04-13-2012
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 08:28 PM.. Reason: please use code tags
# 2  
Old 04-13-2012
Because you supplied different arguments Smilie.

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.
# 3  
Old 04-13-2012
Sorry, I didn't get what you mean?
# 4  
Old 04-13-2012
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 08:34 PM..
# 5  
Old 04-13-2012
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:
Mod Comment How to use code tags

Last edited by Scrutinizer; 04-13-2012 at 08:20 PM..
# 6  
Old 04-13-2012
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

This User Gave Thanks to methyl For This Post:
# 7  
Old 04-13-2012
Oh, I should really read the man page carefully...
Thanks a lot!
This User Gave Thanks to Henryyy 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

Simple awk command to compare two files and print first difference

Hello, I have two text files, each with a single column, file 1: 124152970 123899868 123476854 54258288 123117283 file 2: 124152970 123899868 54258288 123117283 122108330 (5 Replies)
Discussion started by: LMHmedchem
5 Replies

2. Shell Programming and Scripting

Combining awk printf and print strftime command

I have a lines like below, captured from rrdtool fetch command, 1395295200 2.0629986254e+06 7.4634784967e+05 1395297000 2.0198121616e+06 6.8658888903e+05 1395298800 1.8787141122e+06 6.7482866452e+05 1395300600 1.7586118678e+06 6.7867977653e+05 1395302400 1.8222762151e+06 7.1301678859e+05I'm... (3 Replies)
Discussion started by: rk4k
3 Replies

3. Programming

[Perl] Different printf formating for different print options

Hi, Struggling with single quotes, double quotes, etc. I want to print a header line, followed by lines with actual values, based on a print option. In real life it is going to be something like 15 print options and 50 values. Output will be 1 header and several value lines. In this example... (5 Replies)
Discussion started by: ejdv
5 Replies

4. Programming

What is the difference between printf and putchar() or scanf and getchar() ?

Im a newbie to programming language, i found tat there r these function called printf and putchar() as well as scanf and getchar(), im curious abt why do dey hav these 2 different function although dey r doing the same instruction? :confused: (13 Replies)
Discussion started by: kris26
13 Replies

5. Shell Programming and Scripting

How to combine print and printf on awk

# cat t.txt 2,3,4,5,A,2012-01-01 00:00:28 2,6,4,5,A,2012-01-02 00:00:28 2,7,4,5,A,2012-01-02 02:00:28 # awk -F"," '{OFS=",";print $2,"";printf("%s", strftime("%m%d%y",$6));printf("%s", strftime("%H%M%S \n",$6));print ("",$1)}' t.txt 3, 010170073332 ,2 6, 010170073332 ,2 7,... (3 Replies)
Discussion started by: before4
3 Replies

6. Shell Programming and Scripting

AWK Too many open streams to print/printf

hallow all i need your advice about this script i have script like this: INDEX=/zpool1/NFS/INDEX/${1} SCRIPT=/zpool1/NFS/script/${1} LIST=SAMPLE cd ${SCRIPT} for i in `cat ${LIST}` do GETDATE=`echo ${i}|awk '{print substr($1,9,8)}'` /usr/xpg4/bin/awk -F ":" '{close(f);f=$4}{print >>... (4 Replies)
Discussion started by: zvtral
4 Replies

7. Shell Programming and Scripting

Printf command

Hi, I a sequance number from 1-999 and i want asing the value like 001,002..999 Exp: file_001 file_002 file_003... file_999 How can i disaplay the sequnace number as mention above. (3 Replies)
Discussion started by: koti_rama
3 Replies

8. Shell Programming and Scripting

How to print a string using printf?

I want to print a string say "str1 str2 str3 str4" using printf. If I try printing it using printf it is printing as follows. output ------- str1 str2 str3 str4 btw I'm working in AIX. This is my first post in this forum :) regards, rakesh (4 Replies)
Discussion started by: enigmatrix
4 Replies

9. Shell Programming and Scripting

How to print a % within a printf() function using awk

Here is the code I'm using { printf("%11d %4.2f\% %4.2f\%\n", $1,$2,$3); } I want the output to look something like 1235415234 12.24% 52.46% Instead it looks something like 319203842 42.27\%4.2f\% How do I just print a "%" without awk or printf thinking I'm trying to do... (1 Reply)
Discussion started by: Awanka
1 Replies

10. Shell Programming and Scripting

the printf command

hello, Im at another part of the program i am writing. Where i think i'm going to need to use the printf command. If anyone can help me figure out the printf layout i would greatly appreicate it. thanks (4 Replies)
Discussion started by: bebop1111116
4 Replies
Login or Register to Ask a Question