UPD from 2017-03-04: someone completed the
English translation .
Discussion on Hacker News .
In the first part of the article I will list a bunch of UNIX crutches, and generally various shortcomings. In the second - about the "UNIX philosophy". The article was written hastily, I don’t want to further “polish”, say thank you for writing. Therefore, I cite many facts without references.
Crutches in UNIX began to emerge from the moment UNIX appeared, and this was even before the appearance of not only Windows, but even Microsoft DOS (it seems, I’m too lazy to check, check it myself). If you are too lazy to read, at least look through all the items, you will find something interesting. This is not a complete list, these are just the shoals that I wanted to mention.
- At the very beginning, make was a program that one person wrote for himself and several of his acquaintances. Then, without thinking twice, he made the commands accept the lines that start with Tab. That is, Tab was perceived differently from the space, which is extremely ugly and atypical neither for UNIX, nor beyond. He did this because he didn’t think that make someone else would use it other than this small group. Then the thought came up that make is a good thing and it would be nice to include it in the standard UNIX bundle. And then in order not to break the already written makefiles, that is, those written by these ten people, he did not change anything . Well, that's how we live ... Because of those ten, we all suffer.
')
- Almost at the very beginning there was no / usr folder on UNIX. All binaries were located in / bin and / sbin. But then the whole infa ceased to fit on the disk that was at the disposal of the authors of UNIX (Thompson, Ritchie). Therefore, they got another disk, created the folder / usr, and in it - another bin and another sbin. And mounted a new disk in / usr. From there it went. This is how the “second hierarchy” / usr appeared, and then at some point another “third hierarchy” / usr / local, and then also / opt. As the narrator writes this story: “I won’t be surprised if someday / opt / local appears”. UPD from 2017-02-12: I found the link where I got this story . Read, there is a more accurate version of what happened.
- sbin originally meant "static bin", not "superuser bin", as one might think. And contained sbin static binaries. But then sbin began to contain dynamic binaries, its name lost its meaning.
- Windows is often blamed for the registry and reports that the approach of UNIX-like systems (a bunch of configs) is supposedly better. And by the way, a feature appeared once in ext4 (whether it is a bug, a controversial issue), due to which, when you turn off the computer sharply, Gnome lost all its configs in the user's working folder. And the developer of this ext4 said in the discussion of the report bug that Gnome had to use something like a registry to store information.
UPD from 2017-02-12: sources: one and two . The name of the unsubscribe maintainer ext4: Theodore Ts'o. Here are his words:
If you really need to use fsync or fdatasync. If you are fsync (), fdatasync () is much less heavyweight. You can do that through a binary database, that is grown in chunks, and rarely truncated.
I’m using the GNOME desktop (I’m not a very great desktop panel), and "find. [A-zA-Z] * -mtime 0" doesn’t show a large number of files. There is no doubt that it has been the case. If you’re complainant of what you’re getting As I said, if it’s a good number of files, it’s not a bad thing. (Since it will cost it up, since it will cost performance.)
, UNIX ( /etc/passwd), (!) , , ⟦ls -l
⟧, . ⟦ls -l
âź§! . . . , .
Two famous people, one from MIT and another from Berkeley (but working on Unix) once met to discuss operating system issues. The person from MIT was knowledgeable about ITS (the MIT AI Lab operating system) and had been reading the Unix sources. He was interested in how Unix solved the PC loser-ing problem. The PC loser-ing problem occurs when a user program invokes a system routine to perform a lengthy operation that might have significant state, such as IO buffers. If an interrupt occurs during the operation, the state of the user program must be saved. Because the invocation of the system routine is usually a single instruction, the PC of the user program does not adequately capture the state of the process. The system routine must either back out or press forward. The right thing is to back out and restore the user program PC to the instruction that invoked the system routine so that resumption of the user program after the interrupt, for example, re-enters the system routine. It is called «PC loser-ing» because the PC is being coerced into «loser mode,» where «loser» is the affectionate name for «user» at MIT.
The MIT guy did not see any code that handled this case and asked the New Jersey guy how the problem was handled. The New Jersey guy said that the Unix folks were aware of the problem, but the solution was for the system routine to always finish, but sometimes an error code would be returned that signaled that the system routine had failed to complete its action. A correct user program, then, had to check the error code to determine whether to simply try the system routine again. The MIT guy did not like this solution because it was not the right thing.
— The Rise of «Worse is Better» By Richard Gabriel
, UNIX UNIX , , . , Ctrl-C (. . ) , Ctrl-C, , , Ctrl-C, , EINTR. , EINTR . userspace . . , -. userspace , . . : « , , , ».
— . UNIX- , SA_RESTART. , , . , , SA_RESTART ! , GNU/Linux select, poll, nanosleep . SA_RESTART!
- , , UNIX, . , -, cp , copy, UNIX , . cp , copy. UPD 2017-02-12: , - , cp copy, . , , .
Commands — Are These Real Words?
The basic AIX commands (and all UNIX system commands) are, for the most
part, very short, cryptic, two-letter command names. Imagine back years ago,
when computers had only very slow teletype keyboards and paper “displays.”
(Some of us aren’t imagining, we’re remembering!) Imagine also, people who
didn’t like typing long commands because there was such a long delay between
commands and the computer response. If there were any mistakes, the user had
to retype the whole thing (especially aggravating for folks that type with only
two fingers!).
Also, some UNIX commands came from university students and researchers who
weren’t bound by usability standards (no rules, merely peer pressure). They
could write a very useful, clever command and name it anything—their own initials,
for example (awk by Aho, Weinberger, and Kernighan), or an acronym
(yacc, Yet Another Compiler-Compiler).
- , UNIX — . , grep g/re/p ed. ( cat — concatenation, , :) : vmlinuz — gZipped LINUx with Virtual Memory support).
- printf . , ? , printf, UNIX , , . printf . H2O , .
UPD 2017-02-12: .
- , UNIX ( ) , UNIX, , creat (sic!) create. UPD 2017-02-12: , . No comments. , UNIX Plan 9, UNIX. create :) :)
- :
A child which dies but is never waited for is not really gone in that it still consumes disk swap and system table space. This can make it impossible to create new processes. The bug can be noticed whenseveral & separators are given to the shell not followed by ancommand without an ampersand. Ordinarily things clean themselves upwhen an ordinary command is typed, but it is possible to get into asituation in which no commands are accepted, so no waits are done;the system is then hung.The fix, probably, is to have a new kind of fork which creates aprocess for which no wait is necessary (or possible); also to limit the number of active or inactive descendants allowed to a process.
—
UNIX. - . . , . . . GNU/Linux - . . kill' . - : «It's for design».
- C. C UNIX, UNIX, C . , C , , . , , , , ⟦
4["string"]
⟧, ⟦sizeof ('a') != sizeof (char)
⟧ ( C, C++!), ⟦i++ + ++i
⟧, ⟦while (*p++ = *q++);
âź§ ( , ) .
. C . . ! C. . , . : 2015. 2015- !
, ( autotools, , cmake, , ), , npm (js) cargo (rust), portability library, C, , C , C, C ( ) , , user community. c-language.org , - . , , . ( cpp-language.org , :)) . , C C++. Haskell . Rust.
Rust, , , , , C. , , (, cargo — ). , - *GIT*, *GITHUB*. , *MARKDOWN*. , *SEMVER*. , *GIT*, *GITHUB*, *MARKDOWN*, *SEMVER*, *BUZZWORDS*, *BUZZWORDS* *HIPSTERS' BUZZWORDS*. . , . . , Rust — , - javascript. , Rust . . , -, , , , ? .
, , C/C++. , . : « C/C++ ?» .
, . , , signal , C: ⟦void (*signal(int sig, void (*func)(int)))(int);
âź§ .
- UNIX — legacy.
- UNIX (ext2 .) . , . , , . NTFS .
- UNIX shell PHP! , , , ? PHP. UNIX shell :) , , . ( ) . shell, , legacy, , , , , shell' ( UNIX) .
- . foo ⟦
\
⟧? : ⟦find foo -name '\\'
⟧. : ⟦find foo -name \\\\
âź§. . , UNIX shell, , (, , , ). , UNIX shell backslash expanding, find .
- touch' foo ( )? , : ⟦
find foo | while read A; do touch $A; done
âź§. , . 5 , ( ):
- , ⟦
read A
⟧, ⟦read -r A
⟧. - , ⟦
touch $A
⟧, ⟦touch "$A"
⟧. - , , ⟦
read -r A
⟧, ⟦IFS="" read -r A
⟧. - , ⟦
find foo
⟧ ⟦find foo -print0
⟧, ⟦IFS="" read -r A
⟧ ⟦IFS="" read -rd "" A
⟧ ( ). - , ⟦
touch "$A"
⟧ ⟦touch -- "$A"
âź§.
: ⟦find foo -print0 | while IFS="" read -rd "" A; do touch -- "$A"; done
⟧. , ? , , , POSIX ( ), touch ⟦--
⟧. , , ( ) ⟦./
âź§. , configure, autoconf' ? configure , shell'. ( . -exec xargs, ). (, , , foo, ).
- A , a@a. ? : ⟦
ssh a@a rm -- "$A"
⟧? ( , , .) ! ssh — chroot, setsid, nohup, sudo - , exec- (. . execve). ssh ( su) shell-, . . shell' ( exec- shell- — ). ssh , shell'. , : ⟦ssh a@a 'rm -- "$A"'
⟧? , A . , ssh . , : ⟦ssh a@a "rm -- '$A'"
⟧? , , . , , : ⟦ssh a@a "rm -- $(printf '%q\n' "$A")"
âź§. , ?
- a@a, — b@b, — c@c, — d@d, /foo? , :
ssh a@a "ssh b@b \"ssh c@c \\\"ssh d@d \\\\\\\"rm /foo\\\\\\\"\\\"\""
, ? , , , :
ssh a@a 'ssh b@b "ssh c@c '\''ssh d@d \"rm /foo\"'\''"'
, shell' Lisp, ssh ( , UNIX !), AST (abstract syntax tree), :
(ssh "a@a" '(ssh "b@b" '(ssh "c@c" '(ssh "d@d" '(rm "foo")))))
«? ? Lisp? Lisp?» , ? , . . .
- . A. a@a, — b@b, c@c, d@d , A. :) ( , :) , , , ).
- echo , . , , «Hello, world!», ( . UPD 2017-08-01). (, A) : ⟦
printf '%s\n' "$A"
âź§.
- , stdout stderr cmd /dev/null. : , — ?
cmd > /dev/null 2>&1
cmd 2>&1 > /dev/null
{ cmd > /dev/null; } 2>&1
{ cmd 2>&1; } > /dev/null
( cmd > /dev/null ) 2>&1
( cmd 2>&1 ) > /dev/null
, — 1-, 4- 6- , 2-, 3- 5- — . -, :)
- , . , Microsoft. . UNIX . , . (, , , Ubuntu), . , . . , . , shell , login shell' , argv[0] (?!). abuses ( misuses, , , - ) argv[0]. argv[0] . - . . , , .
- BSD sockets . , - - UNIX , . user space . . Windows ( /etc/hosts, C:\windows\system32\drivers\etc\hosts).
UPD 2017-02-12: .
« UNIX». , UNIX . (« », « » . .) « UNIX». , , . « UNIX» . : , , .
- « ». /etc/passwd, . , UNIX (passwd, fstab ) . . , ? /etc/fstab . , , ? fstab' . , fstab, , . , fstab-decode ( ). , ? :) . , - JSON XML. . , . , , ( ).
« ». . . sed, grep, awk . . , , , . . , XML, JSON, -. , , , . . , - . , , . - . , UNIX shell JSON XML. UNIX shell . , JSON.
! , , 1 . , , find'. , ls' ( xargs). ? : ⟦LC_ALL=C ls -l | while read -r MODE LINKS USER GROUP SIZE M D Y FILE; do if [ "$SIZE" -gt 1024 ]; then rm -- "$FILE"; fi; done
âź§. (LC_ALL , , ls). , , . -, , . , ls, , (. . SIZE FILE). , . :)
, ? - : ⟦ls | grep 'size > 1kb' | rm
⟧. , , , . . ls . ⟦-l
⟧ . , , ls. , ls . , , JSON. «» , . . , , - . grep, JSON. JSON «» , grep «», «size». , JSON size. , , , . 1kb. grep rm. rm «», . , , JSON , , — . rm . JSON . « ». ? ( ), . , Windows Powershell - .
- UNIX shell. UNIX. UNIX shell . . «» UNIX shell? , ( ) UNIX shell , . . , UNIX shell , , . , . . , , , , , . Larry Wall , UNIX shell - . UNIX shell' C. Perl. , Perl UNIX shell. , ( ) « UNIX» ( ). « » : «Those days are dead and gone and the eulogy was delivered by Perl». , UNIX shell, . . shell-. , , Perl.
UNIX shell. shell, : ⟦find foo -print0 | while IFS="" read -rd "" A; do touch -- "$A"; done
âź§. touch (, , xargs, , touch ; , ?). touch! ! . . UNIX shell , .
, UNIX shell . , . , «touch'» . , «» , shell, , .
- . shell shell' ( ), . . , sed'. , . jpg ppm . , grep, sed - . jpg. , . photoshop' gimp' - . , . UNIX.
. , . UNIX, . , « ». shell. , shell. ( , , « » shell ). , . , , . , .
. UNIX. . . UNIX . , , UNIX . , UNIX, « UNIX». , UNIX, .
«UNIX Style, or cat -v Considered Harmful».
. , , , cat — ( «» , , cat, ?). , « UNIX».
cat-v.org, , .
, , , , , . , , ? . .
«Systems Software Research is Irrelevant» , . , UNIX ( - ): «New operating systems today tend to be just ways of reimplementing Unix. If they have a novel architecture — and some do — the first thing to build is the Unix emulation layer. How can operating systems research be relevant when the resulting operating systems are all indistinguishable?»
:
«The Good, the Bad, and the Ugly: The Unix Legacy». , , , : «What makes the system good at what it's good at is also what makes it bad at what it's bad at. Its strengths are also its weaknesses. A simple example: flat text files. Amazing expressive power, huge convenience, but serious problems in pushing past a prototype level of performance or packaging. Compare the famous spell pipeline with an interactive spell-checker». : «C hasn't changed much since the 1970s… And — let's face it — it's ugly». , , .
UNIX . , , UNIX. UNIX, UNIX. IDE. . , , .
, UNIX, : Plan 9. , . UNIX. Plan 9 . «Systems Software Research is Irrelevant» Plan 9, .
James Hague, ( ) : «What I was trying to get across is that if you romanticize Unix, if you view it as a thing of perfection, then you lose your ability to imagine better alternatives and become blind to potentially dramatic shifts in thinking» (
).
«Free Your Technical Aesthetic from the 1970s», . (, , , , , ).
, , UNIX — . , , . « UNIX» , , . UNIX GNU/Linux. .
UPD 2017-02-14: , UNIX shell PHP . , ! UNIX shell , , . . UNIX shell . . , UNIX shell cmd. , Windows Powershell. , , - UNIX shell.
UPD 2017-02-14:
sshikov:
— , « , bash, ...» — unix way . .
, - ! , UNIX way. UNIX . - UNIX .
UPD 2017-02-14: , Windows UNIX- . UNIX, , UNIX , Windows. , Windows. UNIX. , , . « UNIX», . UNIX . . UNIX , « UNIX» . « UNIX», C Shell , , Web-. , Web- , , C ( C , ). - quirks , , C. , , . , , . , , . Windows ( - , Windows UNIX?). - Windows UNIX ( Powershell). UNIX. UNIX , , . UNIX. UNIX , .
UPD 2017-02-15:
habrahabr.ru/post/321652/#comment_10070776.
UPD 2017-02-15:
habrahabr.ru/post/321652/#comment_10071096.
UPD 2017-02-15:
habrahabr.ru/post/321652/#comment_10071714.
UPD 2017-02-16: :
habrahabr.ru/post/321652/#comment_10066240.
UPD 2017-02-16: , UNIX . , . . GNU/Linux :) . UNIX. , UNIX. UNIX , . James Hague, :
Enough time has passed since the silly days of crazed Linux advocacy that I'm comfortable pointing out the three reasons Unix makes sense:
1. It works.
2. It's reliable.
3. It stays constant.
But don't--do not--ever, make the mistake of those benefits being a reason to use Unix as a basis for your technical or design aesthetic. Yes, there are some textbook cases where pipelining commands together is impressive, but that's a minor point. Yes, having a small tool for a specific job sometimes works, but it just as often doesn't.
, , « UNIX». , . , . . . . . , . , , . , « UNIX» James Hague. , .
, «» UNIX . , . . . . , , . /usr make. , UNIX . , UNIX! Bell Labs Multics. : « Multics, - , ». . ? . . UNIX — . , .
, , , UNIX, . UNIX- , . , . , . , UNIX , . , UNIX . UNIX. ( !). C, UNIX shell, , « ». , C make, , UNIX. POSIX. : « IDE make». , , , , IDE — C, make shell.
, UNIX ( , ) . shell- — , . .
, shell, make , IDE, , GUI- . . :) - .
. , , autotools , make. autotools, m4, make shell. , , , .
UNIX:
Write programs that do one thing and do it well.
Write programs to work together.
Write programs to handle text streams, because that is a universal interface.
, UNIX shell . , REST. ( , JSON). — , . universal interface . JSON XML. , , - , .
shell. , , find -exec xargs. , . , . , shell' . - . shell' quirks, . .
.
:
iTWire: Systemd seems to depart to a large extent from the original idea of simplicity that was a hallmark of UNIX systems. Would you agree? And is this a good or a bad thing?
Linus Torvalds: So I think many of the «original ideals» of UNIX are these days more of a mindset issue than necessarily reflecting reality of the situation.
There's still value in understanding the traditional UNIX «do one thing and do it well» model where many workflows can be done as a pipeline of simple tools each adding their own value, but let's face it, it's not how complex systems really work, and it's not how major applications have been working or been designed for a long time. It's a useful simplification, and it's still true at *some* level, but I think it's also clear that it doesn't really describe most of reality.
It might describe some particular case, though, and I do think it's a useful teaching tool. People obviously still do those traditional pipelines of processes and file descriptors that UNIX is perhaps associated with, but there's a *lot* of cases where you have big complex unified systems.
And systemd is in no way the piece that breaks with old UNIX legacy. Graphical applications seldom worked that way (there are certainly _echoes_ of it in things like «LyX», but I think it's the exception rather than the rule), and then there's obviously the traditional counter-example of GNU emacs, where it really was not about the «simple UNIX model», but a whole new big infrastructure thing. Like systemd.
Now, I'm still old-fashioned enough that I like my log-files in text, not binary, so I think sometimes systemd hasn't necessarily had the best of taste, but hey, details…
UPD 2017-02-18: shell. , , find -exec xargs. , . , , , , -exec xargs — . « », UNIX shell.
, , , find -exec xargs.
touch'. « touch' foo ( )?» , touch' , grep' bar . . . file ⟦
grep bar file > tmp; mv tmp file
âź§. ? , , , . , :
find foo -print0 | while IFS="" read -rd "" A; do
grep -- bar "$A" > tmp
mv -- tmp "$A"
done
, , , foo, .
, IFS . , , , foo — ⟦
--
⟧. , . . ⟦
--
⟧ : «, ».
.
, xargs find -exec? touch', , .
: grep , . , shell', ⟦
sh -c
âź§. ? , ?
find foo -exec sh -c "grep -- bar '{}' > tmp; mv -- tmp '{}'" ';'
, ! , . :
find foo -exec sh -c 'grep -- bar "$1" > tmp; mv -- tmp "$1"' dummy '{}' ';'
? . $1. - , $1. xargs. ⟦
sh -c
âź§ $1.
, , , , , - .
. . , find. , . . . , find sublanguage, . . find'. , , , find' . truth value, . . . - . , truth value find , descend (. . ).
, , . ⟦
find -delete -name '*~'
⟧ ⟦
find -name '*~' -delete
âź§ - . , , . . find . . , . , -name truth value
true , . -name true, .
? , find sublanguage. shell. ( sed, — , awk — , UNIX' .) , find . . . find' , descend , callback. , UNIX shell . UNIX shell.
UPD 2017-08-01.
echo , . , , «Hello, world!», .
echo . , bash ⟦
echo "Hello, world!"
âź§.
, . bash , .
UPD 2018-05-31. . , : ⟦
-
âź§, . , , . . foo.