シェルスクリプトでlsをパイプでつなぐのはなぜ悪いのか ~ ShellCheck: SC2010, SC2011, SC2012 とファイル名改行問題ShellScriptUNIXshellシェル芸POSIX はじめに シェルスクリプトで ls コマンドの出力結果(ファイル名一覧)をパイプで他のコマンドに渡して処理するのは推奨されません。ls コマンドを使ったコードを ShellCheck で検査するとおそらく問題があると警告が表示されるでしょう。ls を使うなという指摘自体には賛成なのですが SC2010、SC2011、SC2012 に書いてある理由については正しい説明がされていないと思っています。この記事ではなぜ ls の出力結果を他のコマンドにパイプで渡すのが悪いのか、ls を使わずに実現するにはどうしたら良いのかを解説したいと思います。一つ補足をしておくと、この問題は CLI コマ
概要 ファイル名のリストだけ高速に欲しいみたいな場合に大量にファイルがあるディレクトリでlsを打って返ってこないみたいなのが地味にストレスになったりするので高速に済ませる手段が無いかを調べてみた。 1ディレクトリに100万ファイル程度 計測前にecho 3 > /proc/sys/vm/drop_cachesを都度実行し10回程度計測 計測 ls -l めっちゃ遅い real 0m24.052s user 0m5.668s sys 0m8.071s straceをしてみるとこんな感じ。-lをつけるとメタデータを取りに行くのでこれが遅いらしい。sysが長い % time seconds usecs/call calls errors syscall ------ ----------- ----------- --------- --------- ---------------- 44.6
[試して理解]Linuxのしくみ ―実験と図解で学ぶOS、仮想マシン、コンテナの基礎知識【増補改訂版】 作者:武内 覚技術評論社Amazon 2022年も良い技術書がたくさん出版されましたが、その中でも『Linuxのしくみ』はぜひ手元に置いておきたい1冊ですね。 特に、主にアプリケーションレイヤーを主戦場としている人たちにとって、OSは各種ミドルウェアと比較すると「よく分からないもの」という存在になりがちです。しかし、OSがなければアプリケーションも動かないわけで、基本的な知識としてこの本に書かれているようなレベルのことを押さえておくと性能が出ない時に無闇に資源を増やす前に考えるべきことの気づきが得られます(無闇に資源を増やす、という選択肢が取れる時代になったのは、それはそれで良いことですが) 特に、前半のプロセス周りは、「sar」「taskset」など自分も今までちゃんと使ったことがない
先日、同僚と「世の中のエンジニアはターミナルにどんなalias設定をしているんだろう?」という談義になったので、GitHub上の1000リポジトリのコードから調査してみました。 2019/04/10 コメントを元に微修正しました。コメントくださった方々、ありがとうございます。 2019/04/11 こんなのも書いてみました。 よく使われているvimrcの設定ランキング 2019/04/15 プラグイン版も書きました。よく使われているvimのプラグイン top20 aliasとは wikipediaより UNIXなどにおいてコマンドを別名で登録したもの。別名を登録するコマンド名。 長いコマンドやいつも利用するオプションを毎回入力するのは手間ですよね? ターミナルの設定ファイルにaliasを記述することで、別名として定義することが可能というわけです。 調査方法 GitHub APIを利用 do
2022/10/16 以下ご指摘をもとに内容を修正および追記 https://zenn.dev/link/comments/463223a4de9ec2 はじめに Linux上でコマンドを実行したときのコマンドライン引数についてつらつら書きたくなったので書きます。 プロセスのコマンドライン引数とは、たとえばfoo bar bazというコマンドを実行したら、通常はコマンドライン引数はfoo、bar、およびbazになります。直観的には引数は”bar”と"baz"だけのようにおもえるかもしれませんが、とにかくこういう定義です。 コマンドライン引数はプログラムの中からはCやC++ではmain関数のargv配列引数から参照できます。上述の例であればargv[0]には実行ファイル名が入ります。それ以降の"bar"はargv[1]に、"baz"はargv[2]に入っています。argvに相当する変数はシェ
はじめに 少し前から話題になっているが、日本の労働生産性はG7で最も低いらしい。 日本生産性本部資料より https://www.jpc-net.jp/intl_comparison/intl_comparison_2018_press.pdf 日本は人口減少に突入していることもあって、「作業の効率化」や「自動化・省力化」をいうフレーズをあらゆる業種で聞くようになった。 ITエンジニアは、あらゆる職業の中でも最も効率化、自動化をして生産性を高められるといっても過言ではないだろう。プログラマの三大美徳(「怠惰」「短気」「傲慢」)にもあるように、同じことを何度もやらない、楽をするためにがんばるという生産性を意識した感性が重要視されているからだ。 生産性を高めることで、勉強する時間が作れたり、新しいことを経験したりするなどしてさらにスキルアップができ、さらに生産性が上がるという好循環を作り出すこ
拙著、「[試して理解]Linuxのしくみ ~実験と図解で学ぶOS、仮想マシン、コンテナの基礎知識【増補改訂版】」が10/17日に発売されることになりました。本記事はその宣伝のためのブログエントリです。 [試して理解]Linuxのしくみ ―実験と図解で学ぶOS、仮想マシン、コンテナの基礎知識【増補改訂版】 作者:武内 覚技術評論社Amazon まずは本書がどのようなものかについて説明し、その後に、すでに第一版を読まれている方向けに第一版と本書の差分について説明します。 どんな本なのか 筆者は過去にLinuxカーネル開発をしていたのですが、そのころから次のような思いをずっと持っていました。 OS、とくにOSカーネルについての広く浅い知識はOSカーネル開発者だけではなく多くの技術者にとって役立つはず 当時OSカーネルについての知識を得ようとすると、OSを作ったりサポートしたりする人用の難しくて分
GitHub ❤ ~/ Why would I want my dotfiles on GitHub? Backup, restore, and sync the prefs and settings for your toolbox. Your dotfiles might be the most important files on your machine. Learn from the community. Discover new tools for your toolbox and new tricks for the ones you already use. Share what you’ve learned with the rest of us. Navigating this site If you’re just starting out, before you g
Unixが"."から始まるファイルを表示しないのは、本来の仕様ではなくバグだった。もともとlsコマンドは "." と ".." だけを非表示にするはずだったのだが、KenとDennisはこれを手抜き実装した: if (name[0… https://t.co/OsdhpaGEsg
Like many Unix users, I long ago created a ~/bin/ directory in my home directory and added it to my PATH so that I could supplement the wonderfully rich set of basic Unix commands with some conveniences and shell scripts of my own devising. The problem, of course, was the chance of collision. Because my shell script names tended to be short and pithy collections of lowercase characters, just like
Innovative Tech: このコーナーでは、テクノロジーの最新研究を紹介するWebメディア「Seamless」を主宰する山下裕毅氏が執筆。新規性の高い科学論文を山下氏がピックアップし、解説する。 米ペンシルベニア大学、米MIT、ポーランドのXIV Staszic High School、米国の研究機関Aarno Labs、米Stevens Institute of Technologyによる研究チームが開発した「Practically Correct, Just-in-Time Shell Script Parallelization」は、UNIXシェルで実行されるプログラムの速度を精度を保証しながら劇的に加速させるシステムだ。 このシステムはUNIXシェルにおいて、スクリプトを先読みして並列化を行う。これによりプログラム結果を正確な上で最大34倍高速化し、Webインデックスや自然
Linuxユーザーによって長く使われているものの、ほとんどメンテナンスされていないコマンドがあるという。米レッドハットは6月3日(米国時間)、同社のシステム管理者向けコミュニティ「Enable Sysadmin」「6 deprecated Linux commands and the tools you should be using instead|Enable Sysadmin」において、新しいツールが以前のツールよりも優れているかどうかについては議論の余地があると前置きしつつ、まだ使われている可能性のある古いコマンドとそれに代わる代替コマンドを紹介した。 6 deprecated Linux commands and the tools you should be using instead|Enable Sysadmin 記事では、次のツールが取り上げられている。
追記(2022/03/20) Linux限定だし概要レベルだけど包括的なドキュメントがあった。 2. Keyboard generalities キー入力したときに起きていることを説明している。 キーボードコントローラはキーボードドライバにスキャンコードを送信する (スキャンコードモードの)キーボードドライバはアプリケーションプログラムにスキャンコードを送信する (キーコードモードの)キーボードドライバはキー押下、キー離上それぞれのスキャンコードをキーコードに変換し、アプリケーションプログラムに送信する (それ以外の)キーボードドライバはキーコードでキーマップを辞書引きして、発見した文字列(エスケープシーケンスの場合もある)をアプリケーションプログラムに送信する 「アプリケーションプログラムに送信する」は、実際には「端末ドライバに送信する」に相当する。 (端末ドライバ=sttyなのかな)
The Missing Semester of Your CS Education Classes teach you all about advanced topics within CS, from operating systems to machine learning, but there’s one critical subject that’s rarely covered, and is instead left to students to figure out on their own: proficiency with their tools. We’ll teach you how to master the command-line, use a powerful text editor, use fancy features of version control
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く