Skip to content

Instantly share code, notes, and snippets.

@hanminghui
Last active September 13, 2024 19:43
Show Gist options
  • Select an option

  • Save hanminghui/965475d3034cb858ad5eca80d28c8393 to your computer and use it in GitHub Desktop.

Select an option

Save hanminghui/965475d3034cb858ad5eca80d28c8393 to your computer and use it in GitHub Desktop.
[Shell Scripts] some shell scripts #shellscripts
# there are many subdirectories, and each file has a .tgz file in it.
# run this to check path, test first
for d in ./*/
do (cd $d && echo $PWD)
done
# run this to extrat files to its directory.
for d in ./*/
do (cd $d && find . -name '*.tgz' -not -name '.*' -exec tar xvzf {} -C $PWD \;)
done
# there are many [name].py and ._[name].py files in a directory
# first use find to find only the [name].py files
# then use sed to change the first line, and also make a backup
find -name "*.py" -not -name ".*" -exec sed -i.bak "1 s/^.*$/#! \/usr\/bin\/python2/" {} \;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment