Skip to main content
added 30 characters in body
Source Link
Jack G
  • 269
  • 3
  • 11

Here's my sed-in-place helper function that preserves modification and creation timestamps. It's pure POSIX shell script and works in BusyBox / AlpineLinux.

sednomodtime() (
  _SEDFILE="$1"SEDFILE="$1"
  shift
  TMPFILE="$(mktemp -- "$SEDFILE.XXXXXX")" &&\
   sed "$@" <"$_SEDFILE"<"$SEDFILE" >"$_SEDFILE.new">"$TMPFILE" &&\
   touch -r "$_SEDFILE""$SEDFILE" "$_SEDFILE.new""$TMPFILE" &&\
   mv -f "$_SEDFILE.new""$TMPFILE" "$_SEDFILE""$SEDFILE"
)

For example usage, one of my Linux kernel modifications is:

sednomodtime fs/pstore/inode.c -Ee 's/CONFIG_PSTORE_DEFAULT_KMSG_BYTES/10240/g'

Here's my sed-in-place helper function that preserves modification and creation timestamps. It's pure POSIX shell script and works in BusyBox / AlpineLinux.

sednomodtime() (
  _SEDFILE="$1"
  shift
  sed "$@" <"$_SEDFILE" >"$_SEDFILE.new" &&\
   touch -r "$_SEDFILE" "$_SEDFILE.new" &&\
   mv -f "$_SEDFILE.new" "$_SEDFILE"
)

For example usage, one of my Linux kernel modifications is:

sednomodtime fs/pstore/inode.c -Ee 's/CONFIG_PSTORE_DEFAULT_KMSG_BYTES/10240/g'

Here's my sed-in-place helper function that preserves modification and creation timestamps. It's pure POSIX shell script and works in BusyBox / AlpineLinux.

sednomodtime() (
  SEDFILE="$1"
  shift
  TMPFILE="$(mktemp -- "$SEDFILE.XXXXXX")" &&\
   sed "$@" <"$SEDFILE" >"$TMPFILE" &&\
   touch -r "$SEDFILE" "$TMPFILE" &&\
   mv -f "$TMPFILE" "$SEDFILE"
)

For example usage, one of my Linux kernel modifications is:

sednomodtime fs/pstore/inode.c -Ee 's/CONFIG_PSTORE_DEFAULT_KMSG_BYTES/10240/g'
Source Link
Jack G
  • 269
  • 3
  • 11

Here's my sed-in-place helper function that preserves modification and creation timestamps. It's pure POSIX shell script and works in BusyBox / AlpineLinux.

sednomodtime() (
  _SEDFILE="$1"
  shift
  sed "$@" <"$_SEDFILE" >"$_SEDFILE.new" &&\
   touch -r "$_SEDFILE" "$_SEDFILE.new" &&\
   mv -f "$_SEDFILE.new" "$_SEDFILE"
)

For example usage, one of my Linux kernel modifications is:

sednomodtime fs/pstore/inode.c -Ee 's/CONFIG_PSTORE_DEFAULT_KMSG_BYTES/10240/g'