Skip to content

Instantly share code, notes, and snippets.

View forestbaker's full-sized avatar

input - process - output forestbaker

View GitHub Profile
@wwalker
wwalker / perms
Last active September 9, 2017 22:28
copy the permissions from one tree to another that have identical directory/file structure
find . -print0 | grep -Z -z -v '^\.$' | xargs -0 stat -c '%a:%U:%G:%n' | perl -n -e '($p, $u, $g, $f) = (/(.*?):(.*?):(.*?):(.*)/); print "chown $u:$g \"$f\"\n"; print "chmod $p \"$f\"\n";' > /tmp/doit.sh
cd /path/to/source; find . -print0 | grep -Z -z -v '^\.$' | xargs -0 stat -c '%a:%U:%G:%n' | perl -n -e '($p, $u, $g, $f) = (/(.*?):(.*?):(.*?):(.*)/); `chown $u:$g "$f"`; `chmod $p "$f"`;' | ssh target_host 'cat > /tmp/doit.sh; cd /path/to/target; . /tmp/doit.sh; rm /tmp/doit.sh'
On the target:
cd /path/to/targetdir; find . -print0 | grep -Z -z -v '^\.$' | ssh source 'cd /path/to/sourcedir; xargs -0 stat -c "%a:%U:%G:%n"' | perl -n -e '($p, $u, $g, $f) = (/(.*?):(.*?):(.*?):(.*)/); `chown $u:$g "$f"`; `chmod $p "$f"`;'
@hattmarris
hattmarris / linux.sh
Last active September 25, 2015 08:43
Linux Commands
# ubuntu tree
sudo apt-get install tree
# print to terminal in tree format
$ tree [DIRECTORY]
# example [csv] directory outputs:
├── csv
│   ├── CVS
│   │   ├── Entries
@wwalker
wwalker / trace_header.sh
Last active April 6, 2022 03:43
Bash -x tracing without the clutter
#!/bin/bash
# the following sets up a bash script to write the -x tracing to a log file
# in /tmp, with a meaningful, unique name, and a trap to remove it if the
# script completes successfully. Therefore, if the script fails, in any
# way, the log is there to peruse. If it succeeds (exit 0) then nothing
# is left behind
# Set up a function to remove the trace file on successful run (exit 0)
cleanup_trace_file() {
@forestbaker
forestbaker / shell_style_guide
Last active November 24, 2015 17:19
shell style guide & design philosophy
Complex Shell Script Outline
----------------------------
header
begin script
preamble:
- sanity checks
- create shell environ
- log & debug
error handling
check dependencies