Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Goal: I'm trying to create a PHONY target inside my Makefile so that when I run the command "make backup", It will move all the files that end in "~" into the specified backup folder.

Here is my code currently, and I'll explain the problem after: C++ Syntax (Toggle Plain Text)

.PHONY: backup
backup:
@mkdir -p ./backup/include #make folder (don't complain if it already exists)
@mkdir -p ./backup/src #make folder (don't complain if it already exists)
@mv -fu *.h~ ./backup/include #move header file backups into desired folder
@mv -fu *.cpp~ ./backup/src #move source file backups into desired folder

Problem: This works great, BUT ONLY if a file ".h~" and ".cpp~" file already exist in Makefile's current directory. I would like this target to move the files if it can, and just be quiet if there are no files to move..

Error Message: mv: cannot stat `*.h~': No such file or directory

*I'm on linux(ubuntu) and so my shell is "bash"

Appreciate the help, I’ve been stuck on this all night trying all kinds of commands from if statements to the "find" command. Just thought I’d finally ask for some assistance

share|improve this question
add comment

1 Answer

Try this:

.PHONY: backup
backup:
@mkdir -p ./backup/include #make folder (don't complain if it already exists)
@mkdir -p ./backup/src #make folder (don't complain if it already exists)
@mv -fu *.h~ ./backup/include &> /dev/null #move header file backups into desired folder
@mv -fu *.cpp~ ./backup/src &> /dev/null #move source file backups into desired folder

The &>/dev/null should redirect all the output from the mv command to /dev/null, which just gets rid of it.

share|improve this answer
    
just what i needed! thanks for that :) –  Xploit Aug 16 '11 at 0:20
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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