Providing options as an argument vs editing a config file

Why don’t you use the config file instead? I set all of these settings in my config file.

It’s easier with docker run on Synology. I don’t have to log into DSM, download config, modify config, upload config, each time I change something.

SSH to the host, open shell in container, and edit the config file directly. You can even avoid the second step and access the file through the filesystem on the host…

Edit: In fact, Synology allows you to open shell into container right in the UI.

I know both variants, but… I’m not confortable with linux text editors, on Synology I found vim, no nano, and I don’t want to save credentials on a pc.

I would highly recommend spending few hours learning it. Your productivity will skyrocket and you would not want to go back to those other editors that only have insert mode.

Credentials to what? SSH? You still use some kind of credentials to login to web interface. Some password managers support ssh credentials or you can enable key-based auth.

Either way this sounds like excuses for no good reason. Generally, you wan to pass environment-specific data through command line but service configuration itself shall be in the config file.

This will just makes things less error prone. Of course, nothing wrong with doing what you are doing — but you yourself noticed how ridiculous it quickly becomes :slight_smile:


There is a cheat sheet available for vim:

It is just 2 pages. It is amazing how much you can do with vim and a 2 page cheat sheet. Everyone should try it.


There’s another advantage of using run instead of config; you can check quickly what you modified, instead of scaning an entire file.

Turn learning vim into a game!


Vim is what prevented me from using Linux for a while (there was a time when even my router was Windows), because I dreaded the time that I would need to edit a text file. I then figured out how to share the entire drive over smb (with root access), so I could edit a text file with Notepad from my Windows PC.
At the time I did not know that nano exists or that I could use scp to copy the file, edit it and then copy it back.
Simple edit - nano, writing a bigger script - notepad++ with scp plugin. I guess vim would be somewhere in the middle, too complicated for simple stuff, no support for mouse for more complicated stuff.

1 Like

it’s funny, on some linux OSes nano is the default editor and it completely disorients me. I then manage to to figure out how to exit it without saving, and google how to set vim default :slight_smile: (the most annoying bit is the very first thing you do is sudo visido and bam — it opens nano. Vi is in the name, duh!)

I strongly encourage you to take some time and learn vim: I promise, you won’t regret spending that time, it will more than pay off by the amount of time you save. In other words — face the challenges, not be intimidated by them. There is some learning curve but end result it worth the effort.

Another useful thing to learn is awk. Sounds intimidating and examples look mysterious, but it’s a small language in itself and is perfect for one-liners. Will save you a lot of time analyzing logs and generally looking at system behaviour.

Then, next step, if you want to know more about what is the system doing, analyze performance, and find bottlenecks (which is relevant to storage node operators directly) — dtrace (and whatever similar thing Linux has) is your friend. Syntax is somewhat similar and power is pretty much unlimited. Google “dtrace one-liners”.

This will cover a lot of your day to day use.

Then you can venture to Perl or Python if you want more power, regular expressions to make life easier parsing logs. And that’s pretty much it.

You can use all those tools even on windows via WSL/WSL2. No more gui tools and learning weird shortcuts.

(I was a developer on windows for 10+ years (both apps and drivers) in the past and I’m not looking back. Unix is way way more flexible and allows to be significant more productive )

1 Like

I know this is off topic, sorry, mods.

Good thing about nano is that it has the keys listed right at the bottom.

As for vim, I have looked at the cheat sheet (link in one of the previous posts) and it looks to me that vim not only requires learning the commands (which don’t always have anything in common with what it does), but it also requires a different mindset. I am used to editing text files with notepad (or notepad++), in the past I used or the Turbo Pascal editor (for writing TP programs) or the editor in Norton Commander. They all are very similar and I am used to positioning the cursor with the arrow keys or the mouse and not going “2 words forward”. I do not need a separate command for “new line above cursor”, I can press home,enter,up. Or click with the mouse and press enter.

OK, it may be somewhat slower, but most of the time I am not limited by the speed at which I can edit a file, I am usually limited by the speed at which I can think of what to edit in that file. On the other hand, I can see how you may miss being able to go “3 words forward” with a simple command instead of having to click with a mouse or hold the arrow key to move the cursor if that is what you have always done. Just like me and being able to click with a mouse, select text from arbitrary place to arbitrary place and do Crtl+X and Ctrl+V.

Awk is useful, I cannot do complicated things with it alone, but I usually create a long chain of awk, cut and grep to get what I want. Or write a bash script.

dtrace looks interesting. I sometimes use strace to see what the program is doing.

For scripts I prefer bash and PHP, I can do simple stuff with C and Perl too. I dislike Python because of its reliance on whitespace to indicate where a block begins and ends.

On Windows I have Borland Dephi, I used to write a lot of small programs (what could be considered scripts) with it, I don’t use it much anymore, usually using bash or php for the same thing.

I understand what you mean, but let me advance my point further and illustrate with examples. @Alexey will need to split the topic because we wandered way into the boonies.

Yeah, and wasting three lines of text that can be used with something more useful. And does not show how to do search, the most useful thing.

I get it, it’s designed for occasional use, e.g. for a grandma to be able to edit a file over the phone with tech support. Not for everyday use where it will just slow you down.

Yes, unlike most other editors, that only have “insert mode” – where all you type goes directly to document – VIM has “control mode”, where keypresses are commands to do things. You can switch between insert and control mode at will. So this is the only difference in mindset.

And they are absolutely logical. Again, there is a learning curve. You need to invest time to get returns.

For example, to get to the end of file in normal editors, you have to either spam page down button, or move scroll bar with a mouse. And if the file is long it will take some time. In vim – you go to command mode (press Esc) and then press G. Done, you are at the end of file.

To go to a specific line number, eg 42, you type :42<enter>. Done. Want to go the first line? :0 or gg.

To search for Wolf you type /Wolf<enter>.

Or if you want to replace sheep with wolf in the entire file – :%s/sheep/wolf/g.
here % is a range – the whole file. You could specify something else, for example, .,$ – here . is current line, and $ is last line. Comma creates a range. So this will apply your replace command from cursor till the end. s is search. g means all occurrences, not just the first.

Of course you don’t. But those little things significantly improve experience over long time.

You can still do the same in VIM – arrows work, home and enter work. But I feel typing 2dd is faster than pressing a bunch of keys to move to the beginning of the one line, then select till the end of the second line, and cut to clipboard. Let alone aiming and dragging with a mouse.

So even the simple commands are much faster in vim. But the ultimate power comes with chaining the commands together.

Let’s take storj specific example: imagine you want to change the storage path in the config file. it’s specified as storage.path: /mnt/storagenode. and you want it to be storage.path: /some/other/thing

You already know what you need to do in nano – a bunch of page downs, then visually searching for the right setting, then a bunch of arrows and delete buttons to replace the string, to not overshoot and delete the end of line symbols merging two lines accidentally,…

In vim:

  1. /storage\.path<enter> takes you to the storage.path line. Or you can do just /age.path – it’s unique enough.
  2. t/ takes you to the / symbol in the line. Two keystrokes, no need to spam →
  3. c$ deletes everything from cursor to the end of line, and goes into insert mode, so you can type your new path directly. Again, no controlled “del del del del del del…ah, overshoot, dangit”
  4. to return to command mode
  5. :wq – write out the file and quit vim.

Looks complicated but it’s much fewer keystrokes, does not involve a mouse (not all terminals support it) and it becomes seconds nature so you don’t even think about it. In fact, you will start getting annoyed when you have to press the same button multiple times in other editors, as you mentioned:

Right. Except mouse is inherently slow, if at all supported. Yes, you can get very good at using it, and attain some fast performance, but if you not use it, you would be able to achieve much better performance. I try to avoid using mouse if at all possible. For anything. I’d rather spend 5 minutes looking or configuring a shortcut than needing to move my hand away from the keyboard to “aim at pixels with my palm(!)”. what is that, a video game?!

But those are not concurrent processes. You can’t think about what to write while navigating in the file. At least I can’t. I would think first, and now I know what to do, and so I now need to quickly do it. Not being able to zoom right into correct place will be very frustrating.

See – this is another example. Usually, one invocation of awk is enough. It supports arrays and aggregators, there should be no need to invoke it multiple time. Especially with massive storj log files, it can save a lot of time. The benefit of awk is that is a very small language, it’s easy to learn, but it provides enough power to accelerate most of work. The next step would be perl – but this is entirely different beast.

Heh. I hated it too, then I had to maintain a python side project, and actually figure it out. Now I love it. :smiley: It has a side effect of me not putting ; anymore in a normal programming languages: in-spite of having used python for only 4 months, it derailed my decades of C/C++ muscle memory. It’s magnificent.

Edit. I think I understand the difference now. It’s a matter of assurance of being able to accomplish something in the fixed amount of time. I know that if I search and replace as I described I will do that in the fixed amount of time, guaranteed. With holding arrow keys and scrolling – not so much. It’s probably the same reason I never launch apps on my phone by tapping their icon. I have no idea where the icons are and search visually may take some time. Instead, I pull down and search. I know for a fact that after few keystrokes the app I want will appear. I guess it’s the same thing here. in VIM you can do things deterministically fast, exactly as you want, without relying on sight or dexterity.

Maybe with 25 lines the 3 lines are annoying, but I usually have more lines than that and the 3 lines with quick reference are much better than having to google the command I forgot, because I use it rarely.

As for the search, what do you mean?

^G Get Help              ^O WriteOut              ^R Read File             ^Y Prev Page             ^K Cut Text              ^C Cur Pos
^X Exit                  ^J Justify               ^W Where Is              ^V Next Page             ^U UnCut Text            ^T To Spell

Ctrl+W is search (I admit the choice of the combination is not that great, because doing it inside a browser (say, using IPMI or VM console) closes the browser tab).

Anyway, pressing that you get:

^G Get Help              ^Y First Line            ^T Go To Line            ^W Beg of Par            M-J FullJstify           M-B Backwards
^C Cancel                ^V Last Line             ^R Replace               ^O End of Par            M-C Case Sens            M-R Regexp

nano: Ctrl+W, Ctrl+V
On GUI editors, I move the scroll bar with my mouse.

Ctrl+W, Ctrl+T, “42”, enter

Ctrl+W, “Wolf”, enter

nano: entire file: Ctrl+W, Ctrl+R, “sheep”, enter,“wolf”,enter,a
For partial replacements, do this:
Ctrl+W, Ctrl+R, “sheep”, enter,“wolf”,enter
a match is selected, if I want to replace it, I press y and if I want to skip it I press n

Ctrl+W, “storage.path:” OR “/mnt/storagenode” (whichever I remember, whichever is easiest), enter. This puts me on the relevant line. I can then edit it the way I want.
If I want to delete everything from the cursor to the end of the line (and the line is very long) I usually do this:
move cursor to the first unwanted character, enter, Ctrl+K.
Ctrl+K cuts the entire line, so this moves the unwanted portion to a new line, then cuts that line.

To each his own, for me, using the mouse to select a portion of the text is much easier and faster than trying to count the number of words I need to select etc.

Let’s say I have to think for a minute to come up with what I want to change in the file. Then, using nano, it takes me 5 seconds to change it, but if I used vim, I could do that in 2 seconds. The total time is 65 vs 62 seconds, which is not a significant difference. This is what I meant.

I know, the problem is that I do not need to use it often, which means I forget. Even if I googled all the functions and was able to write the correct single invocation, then next time I would need it, I would have to google it again, because that next time would be in a month or later.
Actually, this is similar with PHP (and in some cases bash). I have written some php scripts that access a mysql database, but pretty much every time I need to write a new one, I either have to google how to access a database from php or I copy paste from one of my old scripts. This is because I need it once in a few months and the few months are enough for me to forget the specifics. Similar with, say, bash. I use the date command quite frequently, and yet, pretty much every time I need it, I read the help to remember the format (other than “%s”, I remember that one).

This is probably the main reason why I like the simpler things (ones that require less memory) - even if I did learn the useful vim commands, by the next time I would need them, I would have to google them again. The 2 “wasted” lines of nano are extremely useful in this case for me.

The worst part of that is not just the requirement for “neat” code (I still somewhat dislike php and C because the variable and function names are case sensitive, Pascal/Delphi do not have that particular annoyance), but that the code may look OK, but not work (or run). The reason? One line is “space space space space” and another line is “tab space”. The indentations look exactly the same, but the code does not work.

1 Like

Lol. I looked like three times, and did not see it. But I was looking for “search”… who calls search “Where is” :smiley:

This closes window on most OSes :slight_smile:

Mouse :slight_smile: Nope.

But you can also press Control+End, but I, for example, don’t have Ins/Del/Home/End/PgUp/PgDn block on my keyboard.

See, you still have to read manual and learn it; might as well learn vim. Also, control is a very bad modifier – it is not portable, and some combinations close windows and do other nasty stuff on the host. It’s mind boggling why it was chosen as default. Even Alt/Option would be better. Shift is OK, but it’s already used for changing case… This is where vim comes in (again)

Then nano is perfect! I for some reason assumed you do that often. Not sure why specifically.

I agree. But to my defense – I don’t count numbers. I either eyeball it – like when checking time on the clock — you don’t actually read 4:34, you kind of look and know what time is it, or just switch to visual mode – with V and highlight the block I want to replace. Again, without removing hands from keyboard. Very important. Especially with age, when dexterity diminishes, aiming with a mouse is a … what is the right word… annoying task. It’s also bad for ergonomics, if you have full size keyboard – the hand stretches too far to the right. This is why every (decent) UI can be fully operated by the keyboard. Some users lack ability to use mouse in the first place. But either way – pressing buttons is inherently faster than moving the analog controller.

Ok. I’m not saying nano is unusable garbage and vim is the absolute truth. I’m saying that in vim you can accomplish things faster and easier, after initial leaning curve. But if you do this seldom – then it may not be worth the time investment. No argument here: Spending 2 hours to save 3 seconds 5 times is silly. But if you do it daily, those five seconds easily exceed 2 hours multiple times.

I would suggest using stuff like black, pylint, mypy, and flake8 before every commit (e.g. as a git hook or part of CI). This will re-format your code correctly and find these kind of pesky elusive bugs (including wrong amount of indentations that looks but works incorrectly; akin wrong nesting of {}in other languages. This is however a consequence of too long functions – this better be addressed first)

In fact, even some compiled languages made automatic code formatting as part of compilation – for example: go. This completely eliminates those silly mistakes and code looks consistent across developers and that means – easier to read. Also, all editors should be configured to replace tabs with spaces… Except for Makefiles – where the difference is significant. (What?! yeah… I don’t enjoy editing makefiles…)

It’s right there on the bottom two lines. ^W Where Is ^T Go To Line
If I forget, I can just look there.

The combinations themselves are a bit weird, I’d much prefer Ctrl+S for save, Ctrl+F for find etc (because now using notepad after using nano for an hour is a bit annoying fora while).
Alt is worse though (for me), since Windows programs usually highlight the menu bar when Alt is pressed.

I use nano and edit text files frequently, but I need the special functions (go to line number etc) not as frequently. For example, there’s Alt+A to select text and Alt+6 to copy it (instead of Ctrl+K to cut) and I always forget them, so I usually do the same thing in a different way.

I don’t really have a problem aiming with the mouse. I sometimes miss, but I also sometimes miss with the keyboard (I don’t know how many times I have typed grpe instead of grep, I probably should create an alias).

If I knew how to use git other than “git clone” :slight_smile:
I also do not write or edit Makefiles (maybe once did a search and replace for something).

1 Like

Yes, what I meant was that I could not find it until you told me what to look for. Then, of course, it’s right there. Not a big deal. Nobody said that nano does not have a learning curve.

This is a great observation: it reinforces that the purpose of nano is to be simple to use for most casual users. And the largest group of those are of course (still) represented by windows GUI users. The Ctrl choice now makes perfect sense.

I mean, of course, mouse works for most people. It’s just inherently slower for most people other than pro e-sports crowd. They can probably type with a mouse faster than on a keyboard :slight_smile:

I highly suggest trying the_silver_searcher (ag) as a drop-in replacement for grep. It’s like grep written for people who actually use it. And it’s faster. Also, you won’t need an alias, since it’s already short.

On the aliases – if I lose my ~/.zshrc file my productivity will seriously tank… I religiously back it up.

I use git for everything. Even for config files. Including storj. If I change something, I create a revision, so I can go back if I want, or review differences. Why not? It’s free, and fast. And yes, my .zhsrc, .zprofile, etc, are all under git.

It was more of a rant than anything, but yes, Makefiles can be quite scary. I worked on a project once that the makefile was doing so much acrobatics with renaming and substituting that I could not figure out what’s going on just by looking for it, I had to reverse engineer results and understand what it did, in spite of having “source” in front of me.

On learning different layouts – I constantly switch between Xcode, bbedit, vim, and pycharm, and every single one has it’s own shortcuts that takes getting used to. I don’t want to remap them, because then I wont’ be able to work on any other by my machine. Eventually all sets of shortcuts got associated with the editor view in muscle memory and I’ve ended up switching between then painlessly. But it took months!

Once, as an experiment, I tried to start a finish a hobby electronics microcontroller project on raspberry pi, including editing, debugging, and tracing the code in a multiple tmux window in vim. It was painful first 10 minutes, but after googling shortcuts – I forgot that I was debugging a complex multithreaded project via ssh in a terminal. It was perfect. Of course, nano can also be used – but vim provides some interesting features like running the external executables, and interfacing with other apps, this made is quite fun. best thing - never touched the mouse :slight_smile:

It’s a skill like the others I guess. If I needed the fastest speed, I guess I could either learn to move the mouse very fast or type very fast (and remember all the shortcuts). Normally, I do not need the super speed and my memory does not hold the shortcuts if I don’t use them for a while, so I would have to constantly look them up.

Thanks for the suggestion. ag letters are close enough that I may have better luck not mixing them up, compared to ep of grep.

Cool. It looks complicated to me, much more so than “file.php”, “file.php.bak”, “file.old.php” “” and similar.

Yeah, looks complicated to me. Thankfully my stuff is usually one file = one executable and maybe a bash script for compiling them, because the command may ave something like -lpthreads or specify some old C version (older version of gcc compiled my code ok, new version shows an error, so I find a way for new version to act like the old version).

I just use multiple tabs with ssh or multiple windows. By default there is a limit of 10 open sessions and I sometimes hit it.
Speaking on different layouts - different Windows ssh clients use different shortcuts for the simple stuff, it is super annoying. For example, by default, putty pastes on right click (and I usually start cursing). It can be easily changed, but forget to do that and I’m in for a surprise. Also, by default, with putty the numpad does not work on nano.

By the way, I quite often use te mouse to select, copy and paste text in an ssh window. For example, history | grep some_command, I find it, then select, copy, paste to run it again. Another example is when I use a script to generate commands, then copy+paste some of them to test if the commands work before running the whole generated file.

Most frequently people mix up ls and sl. and get “command not found”. So, kind folks wrote an app “sl” that you can install for an occasional much needed comic relief :). (hint: sl stands for Steam Locomotive). Try it :). I install it as part of my bare necessities on every host I use., project.very-final, project.final_for_sure, project.smal_correction …

It’s 10 connections vs 10 shells in one connection. With the added benefit that if ssh connection breaks whatever was running in the session keeps running. You can later ssh again and attach to the same session. Because otherwise it’ impossible to do anything long-running.

This is because and earlier versions in windows did that, and putty just provides continuity, so it’s actually somewhat justified. It was possible to turn off in cmd (enable Edit mode); so maybe it’s also possible to configure putty. Also, GUI app for shell access is ridiculous :slight_smile: Isn’t there a command line version?

If I have to use shell on windows – I can’t stand cmd and/or powershell, I just start WSL and then use familiar and compliant tools.

This is very difficult way to accomplish command recall. Instead, press Control+r, and start typing whatever you would put in grep. Most shells support search in history this way.

It becomes second nature. Change something, and run git commit -am "short description of what changed" instead of renaming. Then you have a history, that you can cherrypick changes from, if needed. It’s yet another thing that is worth trying. because zoo of files gets unmanageable very quickly.

Yeah, I have it on one PC for fun. However, for me, the most common way I mistype ls is ls- la, sometimes multiple times in a row.

It’s usually two or 3 versions. The “production” one, the “test” one I am currently messing with and then “prod” becomes “backup” and “test” becomes “prod”.
I usually deal with small files or small changes in big files, so commenting out stuff is simpler for me.

I use screen for that. Sometimes I (ab)use it to get a script running as a background service.
Still, switching between sessions using different windows or tabs is easier for me. There is another reason too. Scrollback. Normally I can scroll back to the previous outputs, but if there is screen (tmux would be the same) and I started switching between sessions inside it, the scrollback would be messed up. Maybe I can use screen function to scroll back, but screen does not have a scrollbar or support for mouse wheel.

And wouldn’t the command line version still run inside a GUI (the terminal)? I mean I can use ‘ssh’ from my Linux PC, but it still runs inside “Konsole” GUI app :). But while Konsole has tabs, I cannot just clone the ssh connection into them and have multiple sessions.

I tried it, at least initially it looks less convenient, because it shows one line at a time, unlike history | grep. It also seems to be able to only search for a contiguous block, unlike, say, history | grep dd | grep sda.

I can agree with you here, Windows cmd sucks and somehow powershell commands are all half a page long. I do not like writing bat files, if it’s something else than just a chain of commands, I’d rather fire up Delphi and write a program to do the thing I want.

I don’t keep many old files. Basically, for my small files, it’s easier to comment stuff out. Also, I do not really need a history of changes. When I change something, if it fixes the problem - cool, if nothing else breaks - even better. But if something does break, I find that out immediately or after a couple of days at most, so I still remember what I did (and have the backup file). I don’t think I ever needed to go multiple versions back, it’s either the “new” or the “before I screwed up” version.

I understand that this would be bad for a 200kB php file where some changes affect stuff that runs once a month and you may make multiple changes in the meantime and only later find out that version 5 definitely worked, version 15 doesn’t so now you need to find which version broke the thing.

And that’s where the aliases come in. I have an alias ll that does ls -alt

Until you need to undo the change you did last month, and only that change, because you just discovered it does not work right in some circumstances. I.e. there is no downside in using version control even for simple things, there is no need to reinvent the wheel only to end up with a worse subset of functionality.

And code loooks cleaner — there is no graveyard of commented out dead code all over the place.

Yep. It’s a subset of functionality and indeed it’s intended for different purpose but I know a lot of people who use it as poor man’s tmux :slight_smile:

Each pane in tmux had its own scroll back buffer.

I’m pretty sure it can be configured but I would not know… I have a … complicated relationship with a mouse, if you haven’t yet noticed :slight_smile:

Checkmate. Good point!

On the other hand, this removes useful usecases where ssh is a part of a more complex chain of commands — for example, zfs send /zfs receive piped over the ssh. SSH being a GUI app is not the same as a bunch of CLI tools running in a single gui terminal. Does not putty come with CLI helper though?

This brings memories. Is Delphi still a thing today? I remember decades ago we tried to make an UI app in Delphi, then migrated to Borland C++ Builder, and then threw in a tower and rewrote everything in MSVC, because Borland stuff would hit a wall and fall apart for more or less complex usecases. For simple stuff and quick prototyping it was ok. Today we use Python for that.

I often find issues months later, and I don’t just need to go back few revisions but revert that specific change only. Source control tools were made for this purpose — so why not use them, even if you may never need their full power? But if you do — then it would save a day. Overkill solutions for everything can be a good thing in the long run.