4 ms·
> I'm quite careful writing command lines A safety measure I picked up from a sysadmin while watching over their shoulder: start writing nifty command lines by
by groestl 8y ago
> I'm quite careful writing command lines
A safety measure I picked up from a sysadmin while watching over their shoulder: start writing nifty command lines by prefixing them with # first, to prevent havoc when fat fingering the [enter].
- mixmastamyk 8y agoYes, though I prefer: echo ... The reason is that you'll see expanded variables and wildcards before commiting to them.
- rcthompson 8y agoBut prefixing with echo only disables the first command in a pipeline, while commenting it disables the whole thing.
- groestl 8y agoIt also executes command and process substitutions, opens files etc. But granted, it's a useful trick in some cases, after passing the fat-fingering stage.
- mixmastamyk 8y agoYou can move the echo to the part you are currently working on.
- jxy 8y ago`fc` helps. Setting `FCEDIT=ed` helps a lot.
- no_news_is 8y agoThis command can be dangerous itself. For those who don't know... "The fc utility lists or edits and reexecutes, commands previously entered to an interactive sh."
- androidgirl 8y agoThanks for the tip, I'll definitely be using this. Fear of accidental rm -rf * keeps me up sometimes.
- samstave 8y agoLooks like you need to know about the 'sleep' command...
- yesbabyyes 8y agounzip; strip; touch; finger; grep; mount; fsck; more; yes; fsck; fsck; umount; sleep
- yread 8y agoIt's a pity you can't do something similar to SQL: when writing UPDATE/DELETE always write the WHERE clause first
- rmetzler 8y agoSomething I learned early on when writing possible dangerous SQL selects: CREATE TABLE mytable_backup AS SELECT * FROM mytable; SELECT * FROM mytable WHERE condition; DELETE FROM mytable WHERE condition;
- traviscj 8y agoOr just let the DB work for you with BEGIN; + (select/update/delete) + COMMIT; or ROLLBACK;
- jolmg 8y agoWhat I like about SQL is that it's got the double safety of ";". To accidentally run a SQL statement before it's ready in a command line, you'd have to both add the ";" AND hit Enter, or have the bad practice of adding ";" before the statement is ready, or use a bad SQL command line that sees the ";" as optional.
- groestl 8y agoI always start a session with BEGIN, write UPDATEs/DELETEs as SELECTs first and (if possible) use a staging database until I'm fine with the result.
- amalcon 8y agoIn SQL, you can at least wrap the whole thing in a transaction. Then, just roll the whole thing back if anything came out wrong.
- inopinatus 8y agoI usually SELECT COUNT(*) WHERE ..., and only subsequently overwrite with DELETE.