{ } Snippets { } Snippets

{ } Snippets

Dmitry Machulo Dmitry Machulo

Snippets are saved commands that you can:

โ„น๏ธ Snippets are a premium feature.

The Team plan lets people with specific roles in a team share snippets with other team members. Sharing snippets is possible for team editors and admins.

Shared snippets appear among personal (not shared) snippets. Snippets can be filtered by type on the Snippets screen: all snippets, personal snippets ('my snippers'), and team's ('shared') snippets.

Add a snippet

  1. Open the Snippets screen.
  2. Click + New at the top.
  3. In the Label field, specify an optional name for the snippet.
  4. In the Script field, add a command(s) that will be executed.
  5. (For team editors and admins) choose one of the following:
    1. To create a shared snippet, choose Team snippets next to 'Create in'.
    2. To create a personal snippet, choose My snippets next to 'Create in'.
  6. Click Save. The snippet will appear on the Snippets screen.

Create_S.png

  1. Open the Snippets screen.
  2. Tap + at the top and choose New Shell Snippet.
  3. In the Name field, specify an optional name for the snippet.
  4. In the Script field, add a command(s) that will be executed.
  5. (For team editors and admins) choose one of the following:
    1. To create a shared snippet, choose Team next to 'Create in'.
    2. To create a personal snippet, choose Personal next to 'Create in'.
  6. Tap Save. The snippet will appear on the Snippets screen.

โ„น๏ธ Do not use \n in a snippet as it will not have an effect. It will be treated as two separate characters and not an escape sequence. For specifying several commands in a snippet, add each one of them on a new line.

๐Ÿ’ก If itโ€™s Bash that runs on the remote host, you can use && or ; to specify more than one command on a new line.

Run a snippet

  1. In the terminal, press Cmd + S (Mac OS) or Ctrl + S to open the snippet picker panel.
  2. Choose one of the following:
    1. To run a snippet, click Run next to it.
    2. To insert a snippet, but not run, click Paste next to it.

โ˜๏ธ You can resize the snippets panel by dragging its edge to the left.
snippets_upd.png

  1. In the terminal, tap {} above the keyboard.
  2. If you donโ€™t want run the snippet, but rather insert its contents into the terminal, uncheck Run snippet immediately.
  3. Tap a snippet you would like to execute.
    snippets_more.gif

Run on startup

To make a snippet automatically run when you connect to a host, specify the snippet as Startup Snippet in the properties of your host.

Run on multiple hosts

  1. Open the Snippets screen.
  2. Tap a snippet.
  3. Choose one of the following:
    1. To run the snippet on hosts that are not currently running:
      1. Select the hosts.
      2. If youโ€™d like to disconnect from the host once the snippet is executed, uncheck Close sessions after running.
      3. Tap Run <snippet name>.
    2. To run the snippet on hosts that are currently running:
      1. Switch to the Terminals tab.
      2. Select the hosts (terminals).
      3. Tap Run <snippet name>.
        runs.gif

Share a snippet

Right-click a snippet and choose Share with the team or create a shared snippet (see 'Add a snippet').

zoomed_snippet_sharing_n.gif

Tap and hold the snippet and tap Share or create a shared snippet (see 'Add a snippet').

Frame_6-1.png

Tap and hold the snippet, then tap โ‹ฎ and Share or create a shared snippet (see 'Add a snippet').

Snippet_And_copy_4.png

Example snippets

Snippets are powerful. There are many commands that you may run on a day-to-day basis that are either cumbersome to type (especially on a mobile device) or require command line switches you may not remember. Instead of constantly searching or referencing a sheet for these things, snippets allow you to store this knowledge and save time in your daily server tasks.

To help get you started, we've created a few for you to use:

Find all files created or modified within 30 days

find -type f -mtime -30

Find all files created or modified within 30 days and run a command

find -type f -mtime -30 -exec

The -exec at the end allows you to specify a command. This snippet is intended to be run without pressing enter so that you can type the command to run on those matching files.

Obtain disk usage and free space statistics

du -ch

List listening ports and owning processes

netstat -tolpn

Display kernel log

sudo dmesg

List all running processes

ps auxw

Search for a Running Process

ps aux | grep

This snippet is meant to be run without pressing enter. After using the snippet, type the name of the program you are searching for (i.e. "apache2"), and the process list will be searched for this name.

Add comment

Please sign in to leave a comment.