Adventures in /usr/bin and the likes
ablagoev.github.io
ablagoev.github.io
Can't believe I've been running Linux for 16 years and I didn't know about that one.
It appears to be provided by the following packages:
mysql-server-5.7
mariadb-server-10.0
percona-server-server-5.6
percona-xtradb-cluster-server-5.6
I downloaded mysql to check, and it appears that the replace provided is as described in the article; I assume the others are as well.Unfortunately it seems to pull in some MySQL/MariaDB specific code - https://github.com/MariaDB/server/blob/bb2c1a52c61706dde8c52...
I don't know its status in MariaDB.
[0] https://dev.mysql.com/doc/refman/5.7/en/replace-utility.html
But I'm glad I looked at the list first, because I found this wonder: `lstopo --of txt`. I'm going to use this in class next week, I can't believe I've never seen that before.
Edit: It looks like I agree with you; `replace` only solves trivial problems that can easily be done with `sed`.
If you haven't taken the time, I'd say it's well worth learning exactly how the shell escapes work. It's surprisingly simple and natural once you get used to it.
Even with single quotes, sed still requires escaping parentheses, + operators, and other operators that would otherwise be interpreted literally (but not all operators should be escaped). In the languages that I learned regexes this wasn't required.
sed -e 's_https://www\.example\.com/_/_g'
I think it's nicer than: sed -e 's/https:\/\/www\.example\.com\//\//g'My issue is remembering how to invoke the command - whether it edits in place by default, what the order of arguments is, etc. To be fair, that's not necessarily that much easier with a dedicated replace command either.
This name clash makes that the perl module cannot be easily used on CentOS, since the CentOS utility is required for building RPM packages.
You'd have to edit Makefile.PL of the Perl module before installation, to avoid that clash. (I'd prefer to keep the name as "rename.pl", in this case; though file-rename, as on Windows, would work too.)
?!
banner "Shutdown"|wall; banner "in 5 mins"|wall
I found out "write" command and setup a hacky little one-to-one chat script - it was terrible and geeky but I really liked it.
I'm probably forgetting some more obscure commands that I enjoyed :)
PS: forgot to mention that when I told my boss about the "write" based scripts, he gloated that he had setup a quiz program which supported multiple participants using named pipes. Awesome guy :)
$ cd /usr/bin ; man
(and repeat for other bindirs)
You will be amazed at what you've forgotten, and what your system can do.
$ cd /usr/bin ; man
What manual page do you want?
Is there a command to get all the man pages? I tried `man *` and the internal help, but no luck.Edit: q then Return did it. D'oh. The obvious follow-up question is how do I go back to the _previous_ man page?
man $(man -s 1 -k . | cut -d' ' -f 1 | sort | tr '\n' ' ')
cd /usr/bin ; man * :'<,'>!commandAnother useful one is `%!jq .` to pretty print a json file.
$ printf "\x00\x01\x02\x03" | xxd
0000000: 0001 0203
$ printf "\x00\x01\x02\x03" | xxd -g1
0000000: 00 01 02 03
While editing binary files in Vim, one needs to be careful about setting the binary option before editing a binary file or opening the binary file with `-b` option.For example,
printf "\x00\x01\x02\x03" > a.bin
vim a.bin
:%!xxd -g1
would display 0000000: 00 01 02 03 0a .....
(The `printf` and `vim` commands are entered in the shell. The `:%!xxd` command is entered in Vim.)In the above example, a newline has been added by Vim where none existed in the binary file. In fact, if you then run `%!xxd -r` followed by `:w`, this additional newline would be written back to the file. Here is the right way to preserve the binary data in a binary file.
printf "\x00\x01\x02\x03" > a.bin
vim -b a.bin
:%!xxd -g1
would display 0000000: 00 01 02 03 ....
Only the four bytes in the file appear now. Alternatively, one may enter `:set bin` in Vim before editing a binary file.Check out:
- Russ Cox' tour: https://www.youtube.com/watch?v=dP1xVpMPn8M
Then i wrote a bunch of Python scripts to do things like recalculating command id's for wxWidgets, generating the registration, header and body parts from event definitions (which i cut/pasted later, but it was much faster than doing that by hand), aligning some declarations to fit with the code style, etc.
The extension would also scan a folder inside My Documents and register any executable, python script, bash script and tcl script to a menu in the IDE. Many people in the studio knew Python and some new Bash (i think i was the only one who used Tcl though, i mainly used it to quickly search the filenames for the project and open a file in VS or Vim. I made it to search as i type and since we had a more or less 1-to-1 mapping between objects and files, i could search for object definitions faster than using VS's search functionality - especially when VS was busy building or doing stuff).
Also, I noticed you can rewrite this function:
# Copy an ip address from a domain
# Usage cip domain.com
function cip() {
ip=$(resolveip -s $1)
echo $ip | xsel -b
echo $ip
}
as a oneliner without needing process substitution or echo: function cip() {
resolveip -s $1 | tee /dev/fd/2 | xsel -b
} function cip() {
resolveip -s $1 1>&2 | xsel -b
}
Since this'll copy stdout to stderr, and then stdout will get eaten by xsel # echo "foo" 1>&2 | sed 's/foo/bar/'
foo
bar
Edit: I've done some more testing, and discovered that the above works on zsh, but not in bash2nd Edit: Ahha! http://www.cs.elte.hu/zsh-manual/zsh_7.html . So this is because zsh w/ the stock config (MULTIOS option enabled) will open as many outputs as you give it. So it can both copy FD 1's contents to FD 2 and to the pipe'd command.
$ lsof -d 0,1,2 -a -p $$
That will show you what files correspond to what file descriptors for your current shell process. You can then experiment with redirects. To see how a pipe works we can do something similar: $ sleep 1 | lsof -d 0,1,2 -a -p $(sh -c 'echo $PPID')
Anyway, thinking of `>` and `<` as just FD setters made things a lot clearer for me personally. They just set the file descriptor on the left to file on the right and `&n` can be used to "dereference" a FD to its corresponding file. The only real difference between `>` and `<` is that the former opens the file with write permission while the latter opens it with read. Well, and the default FDs are different.Incidentally, this makes it clear why the following doesn't work as expected:
$ curl 'https://kernel.org/' >/dev/null 2>&1 | tee curl.errs
Since FDs get set in the order they are specified, 1 gets set to /dev/null and then 2 gets set to whatever 1 is, i.e /dev/null. So it's clear that we probably intended the following: $ curl 'https://kernel.org/' 2>&1 >/dev/null | tee curl.errs
Which lets us ignore stdin and maybe pipe stdout to some other command.Now I hope Linus doesn't hate on me for abusing kernel.org :P
resolveip -s $1 | tee >(xsel -b)
(which I prefer)You may want to use "getent ahosts" instead:
$ getent ahosts en.wikipedia.org
91.198.174.192 STREAM en.wikipedia.org
91.198.174.192 DGRAM
91.198.174.192 RAWI usually use drill(1) (from unbound, which is part of base on FreeBSD), or dig(1) on Linux boxes that don't have unbound.
Also turns out that that replace command is also part of MySQL. LOL WTF MYSQL?!
$ netstat --numeric-ports -elp46 | sort
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State User Inode PID/Program name
tcp 0 0 0.0.0.0:22223 0.0.0.0:* LISTEN root 12159 3370/sshd
tcp 0 0 0.0.0.0:3000 0.0.0.0:* LISTEN root 781140 4940/nginx -g daemo
tcp 0 0 0.0.0.0:4000 0.0.0.0:* LISTEN postgres 780857 4916/postgrest
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN root 13126 3537/master
tcp 0 0 127.0.0.1:5432 0.0.0.0:* LISTEN postgres 12526 3406/postgres
tcp6 0 0 ::1:5432 :::* LISTEN postgres 12525 3406/postgres
tcp6 0 0 :::22223 :::* LISTEN root 12168 3370/sshd
udp 0 0 0.0.0.0:123 0.0.0.0:* root 12479 3400/ntpd
udp 0 0 127.0.0.1:123 0.0.0.0:* root 12485 3400/ntpd
udp6 0 0 ::1:123 :::* root 12487 3400/ntpd
udp6 0 0 :::123 :::* root 12480 3400/ntpdI actually used `taskset -c` just recently, when I was running lots of sidekiq processes and wanted to make sure they all used different cores. It helped me get full utilization out of the box, whereas before I would frequently see some sidekiqs competing for a core while other cores sat idle.
Also I can't figure out what pgrap is. Do you mean pgrep? I think you must mean something else, because I don't see what pgrep has to do with priority inversion. But it shares a manpage with pkill. . . .
I don't do real-time work, but I've always been curious to know more about it. And priority inversion seems like an interesting and challenging problem.
Sorry meant pgrep.
> I don't see what pgrep has to do with priority inversion.
Grepping processes doesn't have anything to do with priority inversions and locking your system. But grepping processes then setting them to realtime priority sched_fifo 99 or could wreck havok
> I don't do real-time work, but I've always been curious to know more about it. And priority inversion seems like an interesting and challenging problem.
It can be fun. It is kind of a separate world on its own. Interestingly most of the popular OS-es by default are tuned for throughput not low latency. So configuring and getting everything just right is an interesting challenge (sometimes involving applying kernel patches, although lately that might not be necessary as some have been mainlined).
history | awk '{print $1 "__-__" $2}' | sort | uniq -c | sort -rn | head -30 | awk '{gsub("__-__", " ", $2); $2} !max{max=$1;}{r="";i=s=100*$1/max;while(i-->0)r=r"#";printf "%50s %5d %s %s", $2, $1, r, "\n";}'
It produces a histogram of the 30 most frequent used commands.Unsurprisingly for me, `git commit` was first. Kinda surprisingly, `apt-get` was third.
Caveat: I convert spaces to the symbol sequence: __-__ and back. If your command includes that symbol sequence, it'll break something.
The eventual solution using SetNamedPipeHandleState isn't really supported: https://msdn.microsoft.com/en-us/library/windows/desktop/aa3... "Note that nonblocking mode is supported for compatibility with Microsoft LAN Manager version 2.0 and should not be used to achieve asynchronous input and output (I/O) with named pipes."
I think one might be able to successfully argue that NIX-like systems and the programs executed on them are distinctively* biased towards pipes.
Regardless, as you said, the point is moot.
well that's not guaranteed on all systems :D On FreeBSD:
> at is implemented through the cron(8) daemon by calling atrun(8) every five minutes
But generally what kind of attacks /tmp folder enables ?
ln -s /etc/passwd /tmp/test_at.log
which any unprivileged user can quietly do, before running its examples for at, will ruin the system administrator's day just after 21:26.This is the basis for many of the problems with files in /tmp : predictable filenames written-to without care by privileged processes. It is a widespread disease that is the reason that the systemd people arrange to run many programs with PrivateTmp=true .
In this particular case, root's own home directory would have made a much better private playground for the test_at.log file.