Odds and Ends: Optimizing SSHFS, moving files into subdirectories, and getting placeholder images

And to start up this week of various little scripts and tweaks, we’re going to collect some SSHFS tweaks and two single-use-but-damn-when-you-need-it-you-need-it scripts I wrote.

First, the subdirectory moving script: It takes every file in a directory, creates a subdirectory the same name as the filename without extension, and moves the file into that subdirectory. So, for example,  ~/bob/example.txt becomes ~/bob/example/example.txt, and ~/bob/examples becomes ~/bob/examples/examples. It’s one of those things that looks like it should be a one-liner, but in order to do proper error checking (thanks for training me well, Mom!), it’s about 30 lines. It’s a gist over at http://bit.ly/2b7qVWX.

The second script is for getting placeholder images in BASH. Need a 300×300 image for some reason? Boom. There’s a node.js script that does the same sort of thing, but I wanted something simple and only requiring curl. Snag it at https://github.com/uriel1998/simple_placeholder_images.

The final thing is optimizing SSHFS. What’s nice about it is that you can mount a separate filesystem (or even parts of one) like it exists on your own hard drive without too much difficulty, and pretty transparently. I’ve been moving stuff between my main computer and the old laptop that runs Kodi pretty easily, as well as a Mac, and I’m about to set up a CHIP and a USB drive as a simple NAS without having to use OwnCloud or anything.  (There’s lots of guides on how to install SSHFS at varying levels of technical difficulty and for different OS’s.)

The thing is, SSHFS can be slow. It’s meant to be secure and to compress data, but those strategies don’t make sense when you’re moving things around inside a LAN. Between this post from Admin Magazine and this one from Benjamin I discovered that this series of command line switches made a huge difference in both transfer speeds and CPU power:

sshfs -o cache=yes -o kernel_cache -o large_read -o Ciphers=arcfour -o Compression=no -o ServerAliveCountMax=3 -o ServerAliveInterval=15 -o reconnect -C -o workaround=all -o idmap=user remoteuser@server:/remote/directory/ /media/mountpoint

Which is a hell of a lot to keep retyping, which is why I highly recommend you make the mount and unmount commands into bash aliases.  🙂

Note: If you get “connection reset by peer” after this, follow the instructions at https://mgalgs.github.io/2014/10/22/enable-arcfour-and-other-fast-ciphers-on-recent-versions-of-openssh.html to make it work.

Popular posts:

  • HOWTO Make Your Hamburger Helper Better
  • The Songs That Chronicle Our Lives
  • Word Porn Quotes
  • I am not a number; I am a free man, OR, why you should never rely on social media
  • It's not being "Awkward", and the difference between Excuses and Explanations
  • If there's one Nazi (or a racist) at the table...
  • I really like you, but I have to break up with you before I don't.

2 Comments

  1. Fabien
    April 24, 2018

    Hello,

    I don’t understand one point.
    Why did you use -o Compression=no option, and after you precise -C (=Compression=yes) ?

    Which option is used ?

    • April 24, 2018

      Simple; I made a mistake. 🙂 I’d experiment with both to see if the difference is noticeable. Honestly, the encryption was the biggest issue, and since I was just transferring data within the LAN, I didn’t care about that. I’ve since started to use NFS for most of my intra-LAN operations.

Comments are closed.