Last active
August 4, 2024 06:45
Revisions
-
santisbon revised this gist
Mar 16, 2023 . No changes.There are no files selected for viewing
-
santisbon revised this gist
Sep 6, 2022 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -36,7 +36,7 @@ for file in /usr/**/python*[[:digit:]](*); do echo -n $file '\t'; $file --versio /usr/local/anaconda3/pkgs/python-3.9.12-hdfd78df_0/bin/python3.9 Python 3.9.12 ``` Specifying optional patterns (Requires EXTENDED_GLOB to be set. See below) For each file in the Homebrew installation (recursively) named "python", followed by an **optional** pattern consisting of anything ending in a digit, [expanding](https://thevaluable.dev/zsh-expansion-guide-example/) only executable simple files (not directories or links): Print (without line breaks) the file name, a tab, and then execute the file with the --version option. ```zsh for file in /opt/homebrew/**/python(*[[:digit:]])#(*); do echo -n $file '\t'; $file --version; done -
santisbon revised this gist
Sep 6, 2022 . 1 changed file with 3 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -19,7 +19,8 @@ Find the broadcast address of your network by searching for the line with "broad $ ifconfig | grep broadcast ``` ## zsh glob expansion Let's say you want to list some python executables and check their version. For each file in /usr/ (recursively) named "python", followed by anything, followed by a digit, [expanding](https://thevaluable.dev/zsh-expansion-guide-example/) only executable simple files (not directories or links) do the following: Print (without line breaks) the file name, a tab, and then execute the file with the --version option. @@ -34,7 +35,7 @@ for file in /usr/**/python*[[:digit:]](*); do echo -n $file '\t'; $file --versio /usr/local/anaconda3/pkgs/python-3.10.4-hdfd78df_0/bin/python3.10 Python 3.10.4 /usr/local/anaconda3/pkgs/python-3.9.12-hdfd78df_0/bin/python3.9 Python 3.9.12 ``` Specifying optional patterns (Requires EXTENDED_GLOB to be set. See below) For each file in the Homebrew installation (recursively) named "python", followed by an optional pattern consisting of anything ending in a digit, [expanding](https://thevaluable.dev/zsh-expansion-guide-example/) only executable simple files (not directories or links): Print (without line breaks) the file name, a tab, and then execute the file with the --version option. ```zsh -
santisbon revised this gist
Sep 6, 2022 . 1 changed file with 14 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -34,8 +34,21 @@ for file in /usr/**/python*[[:digit:]](*); do echo -n $file '\t'; $file --versio /usr/local/anaconda3/pkgs/python-3.10.4-hdfd78df_0/bin/python3.10 Python 3.10.4 /usr/local/anaconda3/pkgs/python-3.9.12-hdfd78df_0/bin/python3.9 Python 3.9.12 ``` Specifying optional patterns For each file in the Homebrew installation (recursively) named "python", followed by an optional pattern consisting of anything ending in a digit, [expanding](https://thevaluable.dev/zsh-expansion-guide-example/) only executable simple files (not directories or links): Print (without line breaks) the file name, a tab, and then execute the file with the --version option. ```zsh for file in /opt/homebrew/**/python(*[[:digit:]])#(*); do echo -n $file '\t'; $file --version; done /opt/homebrew/Caskroom/miniconda/base/bin/python3.9 Python 3.9.12 /opt/homebrew/Caskroom/miniconda/base/envs/ldm/bin/python3.9 Python 3.9.13 /opt/homebrew/Caskroom/miniconda/base/pkgs/python-3.9.12-hbdb9e5c_0/bin/python3.9 Python 3.9.12 /opt/homebrew/Caskroom/miniconda/base/pkgs/python-3.9.13-hc596b02_0_cpython/bin/python3.9 Python 3.9.13 /opt/homebrew/Caskroom/miniconda/base/python.app/Contents/MacOS/python Python 3.9.12 /opt/homebrew/Cellar/[email protected]/3.10.6_2/Frameworks/Python.framework/Versions/3.10/bin/python3.10 Python 3.10.6 /opt/homebrew/Cellar/[email protected]/3.9.13_4/Frameworks/Python.framework/Versions/3.9/bin/python3.9 Python 3.9.13 ``` For each file in the Hombrew installation (recursively) named "zsh", followed by anything, [expanding](https://thevaluable.dev/zsh-expansion-guide-example/) only executable simple files (not directories or links) do the following: Print (without line breaks) the file name, a tab, and then execute the file with the --version option. ```zsh -
santisbon revised this gist
Sep 6, 2022 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -25,6 +25,7 @@ For each file in /usr/ (recursively) named "python", followed by anything, follo Print (without line breaks) the file name, a tab, and then execute the file with the --version option. ```zsh for file in /usr/**/python*[[:digit:]](*); do echo -n $file '\t'; $file --version; done /usr/bin/python3 Python 3.8.9 /usr/local/Cellar/[email protected]/3.9.13_1/Frameworks/Python.framework/Versions/3.9/bin/python3.9 Python 3.9.13 /usr/local/anaconda3/bin/python3.9 Python 3.9.12 -
santisbon revised this gist
Sep 6, 2022 . 1 changed file with 14 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -19,9 +19,10 @@ Find the broadcast address of your network by searching for the line with "broad $ ifconfig | grep broadcast ``` In zsh you can use glob expansion to do something like this: Let's say you want to list some python executables and check their version. For each file in /usr/ (recursively) named "python", followed by anything, followed by a digit, [expanding](https://thevaluable.dev/zsh-expansion-guide-example/) only executable simple files (not directories or links) do the following: Print (without line breaks) the file name, a tab, and then execute the file with the --version option. ```zsh for file in /usr/**/python*[[:digit:]](*); do echo -n $file '\t'; $file --version; done /usr/bin/python3 Python 3.8.9 @@ -33,6 +34,16 @@ for file in /usr/**/python*[[:digit:]](*); do echo -n $file '\t'; $file --versio /usr/local/anaconda3/pkgs/python-3.9.12-hdfd78df_0/bin/python3.9 Python 3.9.12 ``` Another example. For each file in the Hombrew installation (recursively) named "zsh", followed by anything, [expanding](https://thevaluable.dev/zsh-expansion-guide-example/) only executable simple files (not directories or links) do the following: Print (without line breaks) the file name, a tab, and then execute the file with the --version option. ```zsh for file in /opt/homebrew/**/zsh*(*); do echo -n $file '\t'; $file --version; done /opt/homebrew/Cellar/zsh/5.9/bin/zsh zsh 5.9 (arm-apple-darwin21.3.0) /opt/homebrew/Cellar/zsh/5.9/bin/zsh-5.9 zsh 5.9 (arm-apple-darwin21.3.0) ``` Some szh [expansion](https://zsh.sourceforge.io/Doc/Release/Expansion.html#Filename-Generation) options require ```EXTENDED_GLOB``` to be set like this: ```Shell setopt extendedglob -
santisbon revised this gist
Sep 6, 2022 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -4,7 +4,7 @@ Linux and Cygwin ```bash find /test -name \*.txt -exec sed -i 's/oldValue/newValue/g' {} \; ``` macOS In [sed](https://www.gnu.org/software/sed/manual/sed.html) the -i option edits files in-place instead of printing to standard output and requires a file extension. Use "" to overwrite the file in place. ```bash -
santisbon revised this gist
Sep 6, 2022 . 1 changed file with 4 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -4,15 +4,15 @@ Linux and Cygwin ```bash find /test -name \*.txt -exec sed -i 's/oldValue/newValue/g' {} \; ``` macOS. In [sed](https://www.gnu.org/software/sed/manual/sed.html) the -i option edits files in-place instead of printing to standard output and requires a file extension. Use "" to overwrite the file in place. ```bash find /test -name \*.txt -exec sed -i "" 's/oldValue/newValue/g' {} \; ``` Find a string in current directory and subdirectories, print line number, exclude some directories and files. Redirect output to a file. ```Shell grep -rn --exclude-dir={node_modules,__pycache__} --exclude={"*.md","LICENSE"} mystring . > ~/results.txt ``` Find the broadcast address of your network by searching for the line with "broadcast" in it: ```Shell -
santisbon revised this gist
Jul 27, 2022 . 1 changed file with 4 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -14,7 +14,10 @@ Find a string in current directory and subdirectories, print line number, exclud ```bash grep -rn --exclude-dir={node_modules,amplify} mystring . ``` Find the broadcast address of your network by searching for the line with "broadcast" in it: ```Shell $ ifconfig | grep broadcast ``` In zsh you can use glob expansion to do something like this: Let's say you want to list some python executables and check their version. For each file in /usr/ (recursively) named "python" followed by anything, followed by a digit, [expanding](https://thevaluable.dev/zsh-expansion-guide-example/) only executable simple files (not directories or links) do the following: -
santisbon revised this gist
Jul 27, 2022 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -16,9 +16,9 @@ grep -rn --exclude-dir={node_modules,amplify} mystring . ``` In zsh you can use glob expansion to do something like this: Let's say you want to list some python executables and check their version. For each file in /usr/ (recursively) named "python" followed by anything, followed by a digit, [expanding](https://thevaluable.dev/zsh-expansion-guide-example/) only executable simple files (not directories or links) do the following: Print the file name (no line breaks), a tab, and then execute the file with the --version option. ```zsh for file in /usr/**/python*[[:digit:]](*); do echo -n $file '\t'; $file --version; done /usr/bin/python3 Python 3.8.9 -
santisbon revised this gist
Jul 27, 2022 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -17,7 +17,7 @@ grep -rn --exclude-dir={node_modules,amplify} mystring . In zsh you can use glob expansion to do something like this: You want to list the python executables and check their version. For each file in /usr/ (recursively) named "python" followed by anything, followed by a digit, [expanding](https://thevaluable.dev/zsh-expansion-guide-example/) only executable simple files (not directories or links) do the following: print the file name (no line breaks), a tab, and then execute the file with the --version option. ```zsh for file in /usr/**/python*[[:digit:]](*); do echo -n $file '\t'; $file --version; done -
santisbon revised this gist
Jul 27, 2022 . 1 changed file with 6 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -15,6 +15,7 @@ Find a string in current directory and subdirectories, print line number, exclud grep -rn --exclude-dir={node_modules,amplify} mystring . ``` In zsh you can use glob expansion to do something like this: You want to list the python executables and check their version. For each file in /usr/ (recursively) named "python" followed by anything, followed by a digit, expanding only executable simple files (not directories or links) do the following: print the file name (no line breaks), a tab, and then execute the file with the --version option. @@ -27,4 +28,9 @@ for file in /usr/**/python*[[:digit:]](*); do echo -n $file '\t'; $file --versio /usr/local/anaconda3/envs/snowflakes/bin/python3.10 Python 3.10.4 /usr/local/anaconda3/pkgs/python-3.10.4-hdfd78df_0/bin/python3.10 Python 3.10.4 /usr/local/anaconda3/pkgs/python-3.9.12-hdfd78df_0/bin/python3.9 Python 3.9.12 ``` Some szh [expansion](https://zsh.sourceforge.io/Doc/Release/Expansion.html#Filename-Generation) options require ```EXTENDED_GLOB``` to be set like this: ```Shell setopt extendedglob ``` -
santisbon renamed this gist
Jul 27, 2022 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
santisbon revised this gist
Jul 27, 2022 . 1 changed file with 14 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -13,4 +13,18 @@ find /test -name \*.txt -exec sed -i "" 's/oldValue/newValue/g' {} \; Find a string in current directory and subdirectories, print line number, exclude some directories. ```bash grep -rn --exclude-dir={node_modules,amplify} mystring . ``` In zsh you can use glob expansion to do something like this: You want to list the python executables and check their version. For each file in /usr/ (recursively) named "python" followed by anything, followed by a digit, expanding only executable simple files (not directories or links) do the following: print the file name (no line breaks), a tab, and then execute the file with the --version option. ```zsh for file in /usr/**/python*[[:digit:]](*); do echo -n $file '\t'; $file --version; done /usr/bin/python3 Python 3.8.9 /usr/local/Cellar/[email protected]/3.9.13_1/Frameworks/Python.framework/Versions/3.9/bin/python3.9 Python 3.9.13 /usr/local/anaconda3/bin/python3.9 Python 3.9.12 /usr/local/anaconda3/envs/snakes/bin/python3.10 Python 3.10.4 /usr/local/anaconda3/envs/snowflakes/bin/python3.10 Python 3.10.4 /usr/local/anaconda3/pkgs/python-3.10.4-hdfd78df_0/bin/python3.10 Python 3.10.4 /usr/local/anaconda3/pkgs/python-3.9.12-hdfd78df_0/bin/python3.9 Python 3.9.12 ``` -
santisbon revised this gist
Jul 27, 2022 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,4 @@ Assuming there's a /test folder with .txt files in it. Note how the * character is escaped to prevent expansion. Linux and Cygwin ```bash -
santisbon renamed this gist
Jul 27, 2022 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
santisbon revised this gist
Jul 27, 2022 . 2 changed files with 16 additions and 9 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,16 @@ Assuming there's a /test folder with .txt files in it.Note how the * character is escaped to prevent expansion. Linux and Cygwin ```bash find /test -name \*.txt -exec sed -i 's/oldValue/newValue/g' {} \; ``` OS X. In [sed](https://www.gnu.org/software/sed/manual/sed.html) the -i option edits files in-place instead of printing to standard output and requires a file extension. Use "" to overwrite the file in place. ```bash find /test -name \*.txt -exec sed -i "" 's/oldValue/newValue/g' {} \; ``` Find a string in current directory and subdirectories, print line number, exclude some directories. ```bash grep -rn --exclude-dir={node_modules,amplify} mystring . ``` This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,9 +0,0 @@ -
santisbon revised this gist
Nov 18, 2018 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -5,5 +5,5 @@ find /test -name \*.txt -exec sed -i 's/oldValue/newValue/g' {} \; # The -i option requires a file extension. Use "" to overwrite the file in place. find /test -name \*.txt -exec sed -i "" 's/oldValue/newValue/g' {} \; # Find a string in current directory and subdirectories, print line number, exclude some directories. grep -rn --exclude-dir={node_modules,amplify} mystring . -
santisbon revised this gist
Nov 18, 2018 . 1 changed file with 4 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -3,4 +3,7 @@ find /test -name \*.txt -exec sed -i 's/oldValue/newValue/g' {} \; # OS X. # The -i option requires a file extension. Use "" to overwrite the file in place. find /test -name \*.txt -exec sed -i "" 's/oldValue/newValue/g' {} \; # Find a string in current directory and subdirectories, excluding some directories. grep -r --exclude-dir={node_modules,amplify} mystring . -
asantisbon created this gist
Apr 1, 2013 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,6 @@ # Linux and Cygwin find /test -name \*.txt -exec sed -i 's/oldValue/newValue/g' {} \; # OS X. # The -i option requires a file extension. Use "" to overwrite the file in place. find /test -name \*.txt -exec sed -i "" 's/oldValue/newValue/g' {} \;