In my environment, we'll be receiving files from clients into our Sftp server. Sftp processes the files, and moves it to another tool, by appending the file size at the end of the file name. For example, samplefile.20150706 of size 1024 would be created as samplefile.20150706.1024.

If file size and name (the last part after .) matches, our tool will pick the file and send it to ETL. If the file stays in that place for more than an hour (not processed due to unmatched size and name), the tool will send us alerts, as files are over an one hour old.

I'm looking for commands, which will extract the last part of the file name and compare it with file size, and eventually delete the file.

2 Answers 2


Get the file size:

size="$(stat --printf="%s" "$path")"

Get the path without the last extension:


Compare the two:

[ "${path_without_extension}.${size}" = "$path" ]

ls -l | awk '{print $5}' gives your file size
echo file_name | awk -F"." '{print $3}' gives you file size extracted from name.

a=`ls -l | awk '{print $5}'` b=`echo file_name | awk -F"." '{print $3}'` if [ $a -eq $b ] then echo "you can do your processing here" fi


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .