Skip to content

Instantly share code, notes, and snippets.

@ronsims2
Created May 31, 2019 19:52
Show Gist options
  • Save ronsims2/ba404c24dfc0736f61840224deccdfed to your computer and use it in GitHub Desktop.
Save ronsims2/ba404c24dfc0736f61840224deccdfed to your computer and use it in GitHub Desktop.
Move files using Bash and SFTP
# create a heredoc of the command you want to run, run and assign outout to a variable
getfiles=`sftp [email protected] <<GETF
ls
bye
GETF`
# Execute command and filter output, quote output to preserve new lines, this assumes all files desired are prefixed foobar_
filelist=`echo "$getfiles"|grep 'foobar_'`
(
for file in $filelist; do
echo rename $file old/$file
done
echo bye
) | sftp [email protected]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment