findコマンドを結果のファイル数をカウントする

findの結果をファイル数をカウントする方法ですが、findコマンドの後にパイプ(|)の後に、wcコマンドを組み合わせればカウントできます
$ find . -name "*.log" -type f | wc -l5ファイルのバックアップを作る時に日付を付与するワンライナー

ファイルバックアップする時に下記のようなコマンドで、ファイル名に日付をつけてバックアップすることがあります。
$ cp/home/admin/test.txt/home/admin/test_20230907.txtこれ普 ...
sedコマンドで「/」 と 「&」を含む場合のエクケープ処理

シェルスクリプト内でテキストファイル内の一部の文字を置換する処理があって、半角空白と「&」を含んでいて、置換がうまく処理されずに変数名が残ってしまいました
$ cat in.txtCORPORATION 御中$ sh s ...「APCu」の有効になっているか確認する

PHPのAPCu(Alternative PHP Cache user caching)は、PHPプログラムのパフォーマンスを向上させるための仕組みの一つで、PHPコードの結果やデータをキャッシュする機能を提供します。これにより、同じ ...
csvファイルの指定したカラムの空白文字を変換する

csvファイルで指定したカラム内の値がファイル名でWindowsだと良いのですが、Linuxだと良くないので半角の空白をアンスコ(_)やハイフン(-)に変換したくて、シェルスクリプトで頑張って色々とやってみましたがうまくいきませんでし ...
「grep -E」で正規表現を使って検索する【grep】

grepは指定したファイルなどから、特定の文字列を検索できるコマンドです。
grepで正規表現を使いたい場合は「egrep」を使えば良いのですが、「-E」のオプションを使うとgrepコマンドで、拡張正規表現 (Extended ...
PHP 8.2から8.0 にダウングレード

先日、PHP 8.2「CentOS 9系でPHP 8.2を使用する」にバージョンアップしたのですが、php-zipで依存関係でエラーとなり色々とやったのですが、解消しません。
$ php -vPHP Warning: Modul ...シェルスクリプトでコマンドの結果を変数に代入する

シェルスクリプトで、コマンドの実行結果を変数に代入したいケースがあります。代入する方法は下記のようなコマンド代入できます。
結果を代入したいコマンドをバッククォート(`)で囲むか、$()の括弧の部分にコマンドをいれるかのどちら ...
SQL文をコマンドで実行した場合に結果のみの値を取得する

MySQL(MariaDB)で、SQL分をコマンドで実行するとカラムが表示されます。SQL分を叩く箇所をシェルスクリプト内で使いたいのでカラム無 ...
swapが使用しているプロセスのTOP10を表示する

最近、サーバーのメモリが逼迫してswapを使っている場合があり、どのプロセスが使用しているか確認したいのでその方法を調べました
/proc 以下のプロセス情報で確認する使用しているプ ...
psコマンドで、CPU使用率・メモリ使用量でソートする

PSコマンドでは、通常ではプロセスID順に並んでいますが、この並びをCPU使用率・メモリの使用率に変更して表示する事ができます。CPUやメモリ以外の項目でもソートできるので詳し ...
ディレクトリごとの容量が大きい順で並び替えて表示する

ディスク容量が少なくなって、どのディレクトリが使用しているか確認したいときに「du」コマンドで使用している容量は下記のように確認できます
$ sudo du -sh/var/www/vhosts/*/219M/var/www/v ...シェルスクリプトでwhile文で使用した変数がループ外で反映されない場合

下記のようなシェルスクリプトでwhileループ内読み込んだファイルの内容を表示して、行数をカウントしています。
while内では、変数が表示されますがwhileループの外だと変数は「0」と表示されます
「acme.sh」でルートの鍵長を指定する【無料SSL証明書】

古いサーバーで、pythonのバージョンが古いので「acme.sh」を利用して無料のSSL証明書を発行しました
証明書のチェックをCMANのSSLチェックでおこなうと、ルートの鍵長が「256」となっていました。OPENSSLで ...
URLをシェルスクリプトで監視する

先日、「.htaccess」を編集して記述ミスがあったらしくしばらく「Internal Server Error 500」でHPが停止していました。プロセス監視はしていますがURLのチェックをしていないので下記のシェルスクリプトで監視 ...