Live data from Hacker News

Linux utils that you might not know

shiroyasha.io

111–120 of 159 posts

Re: Linux utils that you might not know

#111
post #101

Anyone here will probably enjoy checking out commandlinefu: http://commandlinefu.com Especially looking down the list of all time greats: http://www.commandlinefu.com/commands/browse/sort-by-votes

Bringing this on a small tangent, but I've never been comfortable with 'sudo !!' and I can't really articulate why aside from wanting to be as explicit as possible. , , type sudo and enter is nearly as quick and much more explicit for me.

If you are a long time "vi" user, put `set -o vi` in "~/.bashrc": the sequence to issue the previous command with sudo prepended will be 0isudo, probably something that is in your muscle memory already.

Re: Linux utils that you might not know

#112
post #101

Earlier quoted context omitted.

Bringing this on a small tangent, but I've never been comfortable with 'sudo !!' and I can't really articulate why aside from wanting to be as explicit as possible. , , type sudo and enter is nearly as quick and much more explicit for me.

If you are a long time "vi" user, put `set -o vi` in "~/.bashrc": the sequence to issue the previous command with sudo prepended will be 0isudo , probably something that is in your muscle memory already.

While I'm a very long time vi user, and I'm completely at home with the keybindings, I could never get into using "set -o vi". For me it falls into the uncanny valley of being quite like vi while not actually being vi.

Re: Linux utils that you might not know

#113
post #76

Earlier quoted context omitted.

Although these tools are great, I'm afraid these are of limited use, as these aren't preinstalled but must be explicitly installed. For personal use these are great. But if you write a shell script to be executed on different machines where you can't install anything, these tools won't be available to you. And if you don't have that requirement, i.e. you can install everything, just install appropriate Perl/Python/Ru…

Why assume python? It's huge compared to bash or perl. Lots of minimal configuration operational systems won't have python. More likely than go/ruby/node though.

You don't need to install go. It has the runtime thing built into the compiled executable.

Re: Linux utils that you might not know

#114

Earlier quoted context omitted.

I'd stick with pushd and popd every time, it's considerably more expressive.

> considerably more expressive is that an advantage? Do you have the time to explain this a bit more? I feel that new users need less expressiveness, to avoid decision overload, and keeping one automatic directory save point is easier to mentally manage than a stack of them. I do recommend using pushd/popd in shell scripts (always) and interactively (if you must), but I think 'cd -' should be the first thing you intr…

Speaking for myself, I'm often using pushd & popd precisely because I expect to potentially be moving around in the new directory too, and cd - will just take me to the previous dir. pushd & popd don't result in me having even a bit of stress about typing another cd command. Your mileage will vary.

That said, I don't disagree that cd - is a good introduction to the idea that there's more to the cd command than meets the eye. (I'm also a big fan of the CDPATH variable, despite its issues.)

Re: Linux utils that you might not know

#115

$ curl -s http://datascienceatthecommandline.com | pup '.sect3 > h3 text{}' | head alias awk aws bash bc bigmler body cat cd chmod

TIL about pup(1) [1], what a fantastic tool to grab some data from an HTML page. Written in Go too, so easy to deploy. That one's going in my toolchest.

[1]: https://github.com/ericchiang/pup

Re: Linux utils that you might not know

#117

Earlier quoted context omitted.

You can, but ssds are internally log structured, you have to overwrite whole free space plus the reserve and then run a TRIM.

You can't overwrite the reserve directly though. You have to write non-zero data to 99% to lock it, then destructively update the last 1% many times to cycle through the reserve. Many disks have a full erase command, which asks the internal controller to do the erase. In general though, I use a hammer.

>In general though, I use a hammer.

.30-06. >:)

Re: Linux utils that you might not know

#118
post #82

Earlier quoted context omitted.

Is that really a problem anymore? Not being able to install things was common in multi-user thin-client type systems, but these days with containerisation and VMs, if you're allowed to execute a script, you're probably allowed to install new packages No?

Sadly, no. It is often possible to install things locally, i.e. not using apt. The idea that everyone has sudo privs is unrealistic. A version of apt that added a per user subset would be very useful.

Nix and Guix allow unprivileged package operations.

I regularly run "one-off" stuff in a `guix environment` that includes all the required packages for that command, without polluting my user (or system) profile.

For example, I recently wanted to transfer a file over HTTP from one machine to another, and did not have the "python" executable in PATH. So I started it in a `guix environment` and "containerized" it (using user namespaces) just for show:

    guix environment --container --network --ad-hoc python -- python3 -m http.server
That starts the HTTP server from the current directory, but the process can not see anything else from the "real" system.

Re: Linux utils that you might not know

#119
post #76
post #68

Just look at anything in the "moreutils" package. Just great stuff. Excerpt: - ifdata: do not parse the output of ifconfig/ip anymore. Just use this tool. - sponge: when you need to overwrite an input file at the end of pipe. sponge will wait for the pipe to end before overwriting, preventing any data loss - vidir: edit a given dir with your EDITOR. Awesome for mass renames/deletes. - ts: add timestamps to a command…

Although these tools are great, I'm afraid these are of limited use, as these aren't preinstalled but must be explicitly installed. For personal use these are great. But if you write a shell script to be executed on different machines where you can't install anything, these tools won't be available to you. And if you don't have that requirement, i.e. you can install everything, just install appropriate Perl/Python/Ru…

[deleted]

Re: Linux utils that you might not know

#120

Earlier quoted context omitted.

One of my favorite moreutils tools is combine[1]. It allows you to compare the contents of text files with boolean operations. For example, want to know what lines are in file1 but not file2? Use: combine file1 not file2 1. http://manpages.ubuntu.com/manpages/zesty/en/man1/combine.1....

You can use comm from coreutils for that too: `comm -1 file1 file2`

The comm manpage[1] says that the files have to be sorted. In combine, they do not.

1. http://manpages.ubuntu.com/manpages/zesty/en/man1/comm.1.htm...

Post reply on HN