This is an old revision of the document!

Useful Custom Commands

This is list of custom commands that users of WinSCP found useful. You are encouraged to add your own. Also check the built-in examples.

Advertisement

Backup & Deleting

Backup a File with current Date & Time

cp ! $(echo "!" | sed "s/\..*$//").$(date '+%Y-%m-%d_%H-%M').$(echo ! | awk -F"." '{ print $NF }')
-----------------
submitted by Flak

Rename a File with current Date & Time

mv ! $(echo "!" | sed "s/\..*$//").$(date '+%Y-%m-%d_%H-%M').$(echo ! | awk -F"." '{ print $NF }')
-----------------
submitted by Flak

Backup a File with it’s Last Modified Date & Time

mv ! $(echo "!" | sed "s/\..*$//").$(date '+%Y-%m-%d_%H-%M').$(echo ! | awk -F"." '{ print $NF }')
-----------------
submitted by Flak

Advertisement

Rename a File with it’s Last Modified Date & Time

mv ! $(echo "!" | sed "s/\..*$//").$(date '+%Y-%m-%d_%H-%M').$(echo ! | awk -F"." '{ print $NF }')
-----------------
submitted by Flak

Archiving

Tar/Gzip

tar -xvzf --directory="!?&Extract to which directory:?.!" "!"
tar -czvf "!?&Enter an Archive Name:?archive.tgz!"
  --exclude="!?&Exclude files matching pattern:?*.exe!" 
  "!?&Specify directory or file to compress:?!"

Zip

unzip "!"

Rar

rar a -ep "!?&Enter an Archive Name:?archive.rar!" "!&"

Quick Deleting

Use following command to quickly delete large directory structures:

rm -f -r "!"

The same command can ask for confirmation before deleting:

test "!?Do you really want to delete ?no!" == "yes" && rm -rf !&

Advertisement

Changing Ownership

Use following command if current protocol does not allow changing ownership:

chown "!?New owner:?!" !&

To change group use chgrp instead of chown.

URL Address of Selected File

Example shows how to launch simple PHP script that maps file path to URL.

echo '<?="http://www.example.com".
str_replace("home/user/public_html", "~user", "'`pwd`'").
"/!\n"?>' | php -q

Hints:

  • Note that the above should be entered as one line!
  • Do not forget to check custom command option Show results in terminal or Copy results to clipboard, otherwise you will not get the results. You may also want to use the command for directories, check Apply to directories too.
  • For your particular use, just replace http://www.example.com with right URL prefix, home/user/public_html with right path prefix and ~user with right URL replacement (it can even be empty in some cases).
  • If you do mapping like above, i.e. for server containing multiple user’s homepages, you can make it universal by replacing user with '`whoami`'.

Another example using shell commands only, in case PHP is unavailable.

echo 'http://www.example.com'`pwd`'!' | sed s#home/lgtngstk/public_html#~user#

Templates

cp /path/to/template.html "!?&New HTML file:?!"

Viewing End of a File (log)

tail "!"

You may specify further how much to transfer, e.g.

Advertisement

tail --lines 2000 "!"

Check custom command option Show results in terminal.

find . -name "!?Search for files:?!"

Check custom command option Show results in terminal.

Searching for a text/string within a directory

grep -H -r "!?Search for text:?!" *  | cut -d: -f1

Check custom command option Show results in terminal.

Last modified: by flak