Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

As part of the product, there were several scripts which was provided.

In one of the scripts, I've found the following line which seems not to work properly

find . -name *.old -type f -mtime +7 | xargs compress -f

when executing the file command on one of the *.old files I get the following result: ASCII text, with very long lines

Do you have any suggestion what could be done?

share|improve this question

closed as not a real question by Gilles, slm, vonbrand, jasonwryan, Renan Apr 28 '13 at 22:24

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

    
“which seems not to work properly”: so what did you expect it to do, and what did it do instead? And how is this related to the file command? What are you trying to do? –  Gilles Apr 28 '13 at 19:31

1 Answer 1

The output of the file command is kind of irrelevant with regards to why the file command sequence would fail.

Apart from the output from the orignal find command, what is most interesting is what is the output from:

find . -name *.old -type f -mtime +7

if there are no file names echoed, then compress will be called without arguments, therefore waiting for stdin. If there are spaces in the file names of the files found, then xargs will have problems handing this over to compress as well.

You should at least try to change this into:

find . -name "*.old" -type f -mtime +7 -print0 | xargs -0 --no-run-if-empty compress -f

Updated based on the OP comment this would be:

find . -name "$FILE" -type f $ACTION_TYPE +$PARAM -print0 | xargs -0 --no-run-if-empty compress -f 

The -print0 for find with the -0 make sure filenames with spaces get properly passed to compress.
The --no-run-if-empty prevents xargs from running compress if no file is found at all.

share|improve this answer
1  
Quoting "*.old" would also be a good idea. –  Sukminder Apr 28 '13 at 7:43
    
@Sukminder you are absolutely right, I will update my answer for that. –  Anthon Apr 28 '13 at 7:44
    
OK. actually the command is: find . -name "$FILE" -type f $ACTION_TYPE +$PARAM | xargs compress -f when the $FILE=*.old How to change the script? –  user1977050 Apr 28 '13 at 9:12
    
I have extended the answer.If this solves the issue, make sure to update the title of your question, which has probably little to do with the file type. –  Anthon Apr 28 '13 at 9:50
    
Anthon, you didn't got my point. Even though the script seems to be OK, the quotations mark wasn't parsed to the command –  user1977050 Apr 28 '13 at 10:38

Not the answer you're looking for? Browse other questions tagged or ask your own question.