0

I have got script like that:

#!/bin/sh
cd /home/gamesimport/
ls -t games*.xml | tail -n+2 | xargs rm
mv games*.xml games_ok.xml

It's just deleting old games*.xml files, renaming the lastest games.xml file but I would like also to change name if games.xml file is larger then 1 MB. How would I do that?

2 Answers 2

2
FILESIZE=$(stat -c%s games_ok.xml) 
MAX=1048576
if [ $FILESIZE -ge $MAX ]; then
#do something else
fi

should work

Sign up to request clarification or add additional context in comments.

1 Comment

No spaces in MAX=1048576 otherwise MAX: command not found.
2

Simply, use find:

find some/where -name games\*.xml -size +1M -exec mv {} {}.big \;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.