總網頁檢視次數

星期五, 12月 20, 2019

How to sftp files automatically

sshpass -p YOUR_PASSWORD sftp -oBatchMode=no -b YOUR_COMMAND_FILE_PATH USER@HOST


sftp login@host < /path/to/command/list



To do this safer put export SSHPASS='your_password' to ~/.bashrc and run with -e flag. I have used this cmd in some project like this: echo 'ls -t upload/*.xml' | sshpass -e sftp -oBatchMode=no -b - user@example.com | grep -v "sftp>" | head -n1

星期五, 12月 13, 2019

How to rename multiple files with linux script

To rename all files starting with detail and replace it with test


for f in detail* ; do mv "${f}" "${f/detail/test}"; done
 
 
(for j in *.bak; do mv -v -- "$j" "${j%.bak}.txt"; done)

Before

detail-1.txt
detail-2.txt

After

test-1.txt
test-2.txt