前書き
このリポジトリは、xargsコマンドを実行して|(パイプ)から受け取った文字列でファイルを開く体験ができます
インストールする必要のあるコマンド
- git
クイックスタート
上記のコマンドをインストール済みの方は、以下のコマンドを実行してリポジトリからダウンロード後、ディレクトリを移動し、xargsコマンドを実行してopenコマンドでファイルを開いてください
ubuntu
git clone https://github.com/trygfmi/xargs_openFile
cd xargs_openFile
find . -type f -name "*.txt" | xargs -n 1 open
macos
※MacPortsを使用しています
git clone https://github.com/trygfmi/xargs_openFile
cd xargs_openFile
find . -type f -name "*.txt" | xargs open
windows
※MSYS2 MINGW64を使用しています
git clone https://github.com/trygfmi/xargs_openFile
cd xargs_openFile
find . -type f -name "*.txt" | xargs -n 1 start
実行手順
ubuntu
クリックして詳細を開く
事前確認
以下のコマンドを端末に打ち込んでcommand not foundが出なければokです
git --version
preinstall
command not foundが出たコマンドを以下のコマンドでインストールしてください
sudo apt install git
コマンド
以下のコマンドを実行することで詳細のファイルが開かれるはずです
git clone https://github.com/trygfmi/xargs_openFile
cd xargs_openFile
find . -type f -name "*.txt" | xargs -n 1 open
詳細
example1.txt
example2.txt
example3.txt
example4.txt
example5.txt
macos
クリックして詳細を開く
事前確認
以下のコマンドをターミナルに打ち込んでcommand not foundが出なければokです
source ~/bashrc_folder/macports_alias
git --version
※macosはMacPortsパッケージマネージャを使用してコマンドを管理します。もしインストールしていない方は以下のリンクからMacPortsのインストール手順をご覧ください
またコマンドに別名を設定して既存の環境と競合しないでコマンドを呼び出せるようにします。
初めてこのブログを利用する方は、以下の2つの記事を参考に環境構築してください
preinstall
command not foundが出たコマンドを以下のコマンドでインストールしてエイリアスを設定してください
sudo port install git
echo 'alias git="/opt/local/bin/git"' >> ~/bashrc_folder/macports_alias
コマンド
以下のコマンドを実行することで詳細のファイルが開かれるはずです
source ~/bashrc_folder/macports_alias
git clone https://github.com/trygfmi/xargs_openFile
cd xargs_openFile
find . -type f -name "*.txt" | xargs open
詳細
example1.txt
example2.txt
example3.txt
example4.txt
example5.txt
windows
クリックして詳細を開く
事前確認
以下のコマンドをMSYS2 MINGW64に打ち込んでcommand not foundが出なければokです
git --version
※windowsはMSYS2 MINGW64で確認しています。もしインストールしていない方は以下のリンクからmsys2のインストール手順をご覧ください
preinstall
command not foundが出たコマンドを以下のコマンドでインストールしてください
pacman --sync git
コマンド
以下のコマンドを実行することで詳細のファイルが開かれるはずです
git clone https://github.com/trygfmi/xargs_openFile
cd xargs_openFile
find . -type f -name "*.txt" | xargs -n 1 start
詳細
example1.txt
example2.txt
example3.txt
example4.txt
example5.txt
後書き
find . -type f -name “*.txt”とfind . -type f -name “*.txt” | xargsを実行してみてください。出力されたファイルパスの文字列をxargsコマンドが空白区切りに処理して、openコマンドで開けるようにしてくれています。windowsとubuntuのxargs -n 1は、コマンドが引数を一つしか認識しないのでオプションで1つずつ渡しています。windowsのstartは、openコマンドを使用できないため使用しています