Differences
This shows you the differences between the selected revisions of the page.
custom_commands 2017-02-09 | custom_commands 2024-10-08 (current) | ||
Line 4: | Line 4: | ||
===== [[archiving]] Archiving ===== | ===== [[archiving]] Archiving ===== | ||
+ | |||
+ | ==== Extensions ==== | ||
+ | |||
+ | * [[library_example_zip_and_upload|*]] | ||
+ | * [[extension_archive_and_download|*]] | ||
==== Tar/Gzip ==== | ==== Tar/Gzip ==== | ||
- | ··tar -xvzf --directory="!?&Extract to which directory:?.!" "!" | + | <code custom-command-remote> |
+ | tar -xvzf --directory="!?&Extract to which directory:?.!" "!" | ||
+ | </code> | ||
+ | |||
+ | <code custom-command-remote> | ||
+ | tar -czvf "!?&Enter an Archive Name:?archive.tgz!" | ||
+ | --exclude="!?&Exclude files matching pattern:?*.exe!" | ||
+ | !& | ||
+ | </code> | ||
+ | |||
+ | ==== [[gzip]] Gzip ==== | ||
+ | |||
+ | <code custom-command-remote> | ||
+ | gzip -f "!" | ||
+ | </code> | ||
- | tar -czvf "!?&Enter an Archive Name:?archive.tgz!" | + | <code custom-command-remote> |
- | ····--exclude="!?&Exclude files matching pattern:?*.exe!" | + | gunzip -f "!" |
- | ····!& | + | </code> |
- | ==== Zip ==== | + | ==== [[zip]] Zip ==== |
To unpack to the current directory: | To unpack to the current directory: | ||
- | ··unzip "!" | + | <code custom-command-remote> |
+ | unzip -o "!" | ||
+ | </code> | ||
To unpack to an alternate directory: | To unpack to an alternate directory: | ||
- | ··unzip -d "!?&Extract to directory:?.!" "!" | + | <code custom-command-remote> |
+ | unzip -o -d "!?&Extract to directory:?.!" "!" | ||
+ | </code> | ||
To create an archive: | To create an archive: | ||
- | ··zip -r "!?&Enter an Archive Name:?archive.zip!" !& | + | <code custom-command-remote> |
+ | zip -r "!?&Enter an Archive Name:?archive.zip!" !& | ||
+ | </code> | ||
- | ==== Rar ==== | + | ==== [[rar]] Rar ==== |
- | ··rar a -ep "!?&Enter an Archive Name:?archive.rar!" !& | + | <code custom-command-remote> |
+ | rar a -ep "!?&Enter an Archive Name:?archive.rar!" !& | ||
+ | </code> | ||
===== [[delete]] Quick Deleting ===== | ===== [[delete]] Quick Deleting ===== | ||
Line 34: | Line 61: | ||
Use following command to quickly delete large directory structures: | Use following command to quickly delete large directory structures: | ||
- | <code>rm -f -r "!"</code> | + | <code custom-command-remote> |
+ | rm -f -r "!" | ||
+ | </code> | ||
The same command can ask for confirmation before deleting: | The same command can ask for confirmation before deleting: | ||
- | <code>test "!?Do you really want to delete ?no!" == "yes" && rm -rf !&</code> | + | <code custom-command-remote> |
+ | test "!?Do you really want to delete ?no!" == "yes" && rm -rf !& | ||
+ | </code> | ||
+ | |||
+ | Both above solutions require a shell access. If you do not have it, use the following solution. | ||
===== [[delete_background]] Deleting on Background ===== | ===== [[delete_background]] Deleting on Background ===== | ||
Line 44: | Line 77: | ||
Use the following command to delete a large directory structure in a separate process: | Use the following command to delete a large directory structure in a separate process: | ||
- | <code>cmd.exe /c start "" cmd /c ""C:\Program Files (x86)\WinSCP\WinSCP.com" /command "open !S" "cd !/" "rm !&" "exit" & "C:\Program Files (x86)\WinSCP\WinSCP.exe" "!S" /refresh "!/""</code> | + | <code custom-command-local> |
+ | cmd /C start "" cmd /C ""%WINSCP_PATH%\WinSCP.com" /command "open !E" "cd !/" "rm !&" "exit" & "%WINSCP_PATH%\WinSCP.exe" "!E" /refresh "!/"" | ||
+ | </code> &winpath | ||
Check custom command options //Local command//, //Apply to directories// and //Use remote files//. | Check custom command options //Local command//, //Apply to directories// and //Use remote files//. | ||
Line 52: | Line 87: | ||
Use following command if current [[protocols|protocol]] does not allow changing ownership: | Use following command if current [[protocols|protocol]] does not allow changing ownership: | ||
- | <code>chown "!?New owner:?!" !&</code> | + | <code custom-command-remote> |
+ | chown "!?New owner:?!" !& | ||
+ | </code> | ||
To change group use ''chgrp'' instead of ''chown''. Or use following command: | To change group use ''chgrp'' instead of ''chown''. Or use following command: | ||
- | <code>chown "!?New owner (and group: user:group):!" !&</code> | + | <code custom-command-remote> |
+ | chown "!?New owner (and group: user:group):!" !& | ||
+ | </code> | ||
or with two separate prompts: | or with two separate prompts: | ||
- | <code>chown -R "!?New owner:?!":"!?New group:?!" !&</code> | + | <code custom-command-remote> |
+ | chown -R "!?New owner:?!":"!?New group:?!" !& | ||
+ | </code> | ||
+ | ===== [[time]] Changing Modification Date/Time ===== | ||
- | ===== [[url]] URL Address of Selected File ===== | + | <code custom-command-remote> |
- | ==== Using Local Command ==== | + | touch -d "!?Date:!" !& |
- | Example shows how to use local custom command that maps file path to URL. | + | </code> |
- | <code>!`cmd.exe /c echo @echo off > %TEMP%\url.bat & | + | ===== [[chmod]] Recursively Changing Permissions of Files or Folders only ===== |
- | echo set FILE_PATH=%1 >> %TEMP%\url.bat & | + | For changing directory permissions: |
- | echo echo https://www.example.com%FILE_PATH:home/user/public_html=~user% >> %TEMP%\url.bat` | + | <code custom-command-remote> |
- | cmd.exe /c %TEMP%\url.bat !/! & pause</code> | + | find ! -type d -exec chmod !?&Permissions:?755! {} \; |
+ | </code> | ||
+ | For changing file permissions: | ||
+ | <code custom-command-remote> | ||
+ | find ! -type f -exec chmod !?&Permissions:?644! {} \; | ||
+ | </code> | ||
+ | Check custom command options //Remote command// and //Apply to directories//. | ||
- | Hints: | + | ===== Templates ===== |
- | ··* Note that the above should be entered as one line! | + | <code custom-command-remote> |
- | * Check custom command options //Local command// and //Use remote files//. | + | cp /path/to/template.html "!?&New HTML file:?!" |
- | ··* If you want to copy the %%URL%% to clipboard instead of displaying it, replace the trailing ''& pause'' with ''| clip''. | + | </code> |
- | * For your particular use, just replace ''%%https://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). | + | |
- | ==== Using Remote PHP Code ==== | + | ===== [[tail]] Viewing End of a File (log) ===== |
- | Example shows how to launch simple PHP script that maps file path to URL. | + | |
- | <code>echo '<?="https://www.example.com".str_replace("home/user/public_html", "~user", "'`pwd`'")."/!\n"?>' | php -q</code> | + | ==== In Console Window ==== |
- | Hints: | + | <code custom-command-remote> |
+ | tail "!" | ||
+ | </code> | ||
- | * Note that the above should be entered as one line! | + | You may specify further how much to transfer, e.g. |
- | * 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 ''%%https://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`'%%''. | + | |
- | ==== Using Remote Shell Code ==== | + | <code custom-command-remote> |
+ | tail --lines 2000 "!" | ||
+ | </code> | ||
- | Another example using shell commands only, in case PHP is not available: | + | Check custom command option //Show results in terminal//. |
- | <code>echo 'https://www.example.com'`pwd`'/!' | sed s#home/user/public_html#~user#</code> | + | ==== Continuously in Separate Window ==== |
+ | <code custom-command-local> | ||
+ | cmd /C start "!@:!/!" "%ProgramFiles%\PuTTY\plink.exe" -P !# !U@!@ tail -f "!/!" | ||
+ | </code> | ||
- | ===== Templates ===== | + | Check custom command options //Local command// and //Use remote files//.· |
- | + | ||
- | cp /path/to/template.html "!?&New HTML file:?!" | + | |
- | + | ||
- | ===== [[tail]] Viewing End of a File (log) ===== | + | |
- | + | ||
- | tail "!" | + | |
- | + | ||
- | You may specify further how much to transfer, e.g. | + | |
- | + | ||
- | tail --lines 2000 "!" | + | |
- | + | ||
- | Check custom command option //Show results in terminal//. | + | |
===== [[search_file]] Searching for a File ===== | ===== [[search_file]] Searching for a File ===== | ||
- | ··find . -name "!?Search for files:?!" | + | <code custom-command-remote> |
+ | find . -name "!?Search for files:?!" | ||
+ | </code> | ||
Check custom command option //Show results in terminal//. | Check custom command option //Show results in terminal//. | ||
- | |||
- | |||
===== [[search_text]] Searching for a text/string within a directory ===== | ===== [[search_text]] Searching for a text/string within a directory ===== | ||
- | ··grep -H -r "!?Search for text:?!" * | cut -d: -f1 | + | <code custom-command-remote> |
+ | grep -H -r "!?Search for text:?!" * | cut -d: -f1 | ||
+ | </code> | ||
Check custom command option //Show results in terminal//. | Check custom command option //Show results in terminal//. | ||
Line 129: | Line 169: | ||
==== Backup a File with Current Date and Time ==== | ==== Backup a File with Current Date and Time ==== | ||
- | ··cp ! $(echo "!" | sed "s/\..*$//").$(date '+%Y-%m-%d_%H-%M').$(echo ! | awk -F"." '{ print $NF }') | + | <code custom-command-remote> |
+ | cp ! $(echo "!" | sed "s/\.[^.]*$//").$(date '+%Y-%m-%d_%H-%M').$(echo ! | awk -F"." '{ print $NF }') | ||
+ | </code> | ||
==== Rename a File with Current Date and Time ==== | ==== Rename a File with Current Date and Time ==== | ||
- | ··mv ! $(echo "!" | sed "s/\..*$//").$(date '+%Y-%m-%d_%H-%M').$(echo ! | awk -F"." '{ print $NF }') | + | <code custom-command-remote> |
+ | mv ! $(echo "!" | sed "s/\.[^.]*$//").$(date '+%Y-%m-%d_%H-%M').$(echo ! | awk -F"." '{ print $NF }') | ||
+ | </code> | ||
===== [[fxp]] Remote Transfer (FXP) ===== | ===== [[fxp]] Remote Transfer (FXP) ===== | ||
Line 138: | Line 182: | ||
Use following remote custom command to transfer selected remote files to an another server: | Use following remote custom command to transfer selected remote files to an another server: | ||
- | ··scp -p -r !& !?Username:?!@!?Host:?!:!?Destination path:?! | + | <code custom-command-remote> |
+ | scp -p -r !& !?Username:?!@!?Host:?!:!?Destination path:?! | ||
+ | </code> | ||
You may want to hard-code the //Username// and //Host//, if you work with one destination server only. Or you can use a single prompt for both (possibly even for //Destination Path//) to keep the flexibility, yet to reduce number of prompts: | You may want to hard-code the //Username// and //Host//, if you work with one destination server only. Or you can use a single prompt for both (possibly even for //Destination Path//) to keep the flexibility, yet to reduce number of prompts: | ||
- | ··scp -p -r !& !?Username@Host:?!:!?Destination path:?! | + | <code custom-command-remote> |
+ | scp -p -r !& !?Username@Host:?!:!?Destination path:?! | ||
+ | </code> | ||
Note that you need to ensure you can connect and authenticate to the destination server without any prompts: | Note that you need to ensure you can connect and authenticate to the destination server without any prompts: | ||
* Connect at least once from an interactive terminal (such as [[&url(putty)|PuTTY SSH client]]) to verify the destination server host key. | * Connect at least once from an interactive terminal (such as [[&url(putty)|PuTTY SSH client]]) to verify the destination server host key. | ||
* Use for example [[ui_login_authentication#forwarding|Agent forwarding]] to forward your private key to the destination server for authentication. | * Use for example [[ui_login_authentication#forwarding|Agent forwarding]] to forward your private key to the destination server for authentication. | ||
- | * Another less-secure method of authentication is use of ''[[https://sourceforge.net/projects/sshpass/|sshpass]]'' tool (see its [[&man_ref(1,sshpass)|man page]]). | + | * Another less-secure method of authentication is use of ''[[https://sourceforge.net/projects/sshpass/|sshpass]]'' tool (see its [[https://www.mankier.com/1/sshpass|man page]]). |
===== [[compare]] File Compare ===== | ===== [[compare]] File Compare ===== | ||
+ | |||
+ | Note that WinMerge and other major diff tools are supported by official [[extension_compare_files|*]]. The following is just an example how to use other diff tools. | ||
==== WinMerge ==== | ==== WinMerge ==== | ||
Line 155: | Line 205: | ||
Select //Local command// [[custom_command#types|type]]. | Select //Local command// [[custom_command#types|type]]. | ||
- | ··"C:\Program Files (x86)\WinMerge\WinMergeU.exe" /e /x /u "!" "!^!" | + | <code custom-command-local> |
+ | "C:\Program Files (x86)\WinMerge\WinMergeU.exe" /e /x /u "!" "!^!" | ||
+ | </code> | ||
Replace ''C:\Program Files (x86)'' with ''C:\Program Files'' on 32-bit system. &winpath &win32 &win64 | Replace ''C:\Program Files (x86)'' with ''C:\Program Files'' on 32-bit system. &winpath &win32 &win64 | ||
Line 161: | Line 213: | ||
Arguments: | Arguments: | ||
- | * ''/e'' - Enables you to close WinMerge with a single ''Esc'' key press; | + | * ''/e'' -- Enables you to close WinMerge with a single ''Esc'' key press; |
- | * ''/x'' - Closes WinMerge (after displaying an information dialog) when you start a comparison of identical files; | + | * ''/x'' -- Closes WinMerge (after displaying an information dialog) when you start a comparison of identical files; |
- | * ''/u'' - Prevents WinMerge from adding either path (left or right) to the Most Recently Used (MRU) list. | + | * ''/u'' -- Prevents WinMerge from adding either path (left or right) to the Most Recently Used (MRU) list. |
===== [[errors]] Suppressing Errors ===== | ===== [[errors]] Suppressing Errors ===== | ||
Line 173: | Line 225: | ||
* Redirect error output to ''/dev/null'', to discard it: \\ <code> | * Redirect error output to ''/dev/null'', to discard it: \\ <code> | ||
command_that_prints_non_interesting_progress_on_error_output > /dev/null</code> | command_that_prints_non_interesting_progress_on_error_output > /dev/null</code> | ||
- | * Redirect error output to standard output, to see it in terminal, but avoid error message: \\ <code> | + | * Redirect error output to standard output, to see it in terminal, but avoid error message: \\ <code custom-command-remote> |
command_that_prints_interesting_info_on_error_output 2>&1</code> | command_that_prints_interesting_info_on_error_output 2>&1</code> | ||
- | * Use ''|| true'' to discard exit code: \\ <code> | + | * Use ''|| true'' to discard exit code: \\ <code custom-command-remote> |
command_that_returns_255_code || true</code> | command_that_returns_255_code || true</code> | ||
- | * Or combine these together: <code> | + | * Or combine these together: <code custom-command-remote> |
command_that_prints_interesting_info_on_error_output_and_returns_255_code 2>&1 || true</code> | command_that_prints_interesting_info_on_error_output_and_returns_255_code 2>&1 || true</code> |