• Skip to main content

Uly.me

cloud engineer

  • Home
  • Archives
  • Search

Archives for April 2022

GCP Find Instance Boot Disk

April 13, 2022 by Ulysses

How to find a boot disk from an instance.

gcloud compute instances describe servername \
--format='get(disks[0].source)' \
--zone=us-central1-c \
--project project-id

gcloud compute instances describe servername \ --format='get(disks[0].source)' \ --zone=us-central1-c \ --project project-id

Result

https://www.googleapis.com/compute/v1/projects/project-id/zones/us-central1-f/disks/servername-boot

https://www.googleapis.com/compute/v1/projects/project-id/zones/us-central1-f/disks/servername-boot

Filed Under: Cloud Tagged With: boot, disk, find, gcp

7zip in Mac OS

April 6, 2022 by Ulysses

Install

brew install p7zip

brew install p7zip

Extract

7z x file.7z

7z x file.7z

Compress

7z a file.7z mydirectory

7z a file.7z mydirectory

Filed Under: Mac Tagged With: append, brew, extract, install, p7zip

Remove Extended Attributes on Mac

April 3, 2022 by Ulysses

If you have a file with @ sign at end, this is how to remove extended attributes on the Mac OS.

Example.

ls -l
-rwxr-xr-x@  4 username  staff   128 Mar 24 10:51 sample.txt

ls -l -rwxr-xr-x@ 4 username staff 128 Mar 24 10:51 sample.txt

Remove extended attributes.

xattr -c sample.txt

xattr -c sample.txt

Result

ls -l
-rwxr-xr-x  4 username  staff   128 Mar 24 10:51 sample.txt

ls -l -rwxr-xr-x 4 username staff 128 Mar 24 10:51 sample.txt

Filed Under: Linux, Mac Tagged With: attributes, extended, mac os, remove

GCP Backup Instance

April 3, 2022 by Ulysses

Here’s the script to backup GCP disks.

#!/bin/bash
now=$(date +%s)
disks=$(gcloud compute disks list --project project-id --filter="users:instance" --format="value(name)")
for disk in $disks
do
  gcloud compute disks snapshot $disk \
  --snapshot-names=$disk-$now \
  --zone=us-central1-a \
  --project=project-id \
  --async
done

#!/bin/bash now=$(date +%s) disks=$(gcloud compute disks list --project project-id --filter="users:instance" --format="value(name)") for disk in $disks do gcloud compute disks snapshot $disk \ --snapshot-names=$disk-$now \ --zone=us-central1-a \ --project=project-id \ --async done

Filed Under: Cloud, Linux Tagged With: backup, disks, gcp, manual, snapshots

Vi Search and Replace

April 3, 2022 by Ulysses

How to do search and replace in Vim.

Search for “foo” and replace it with “bar” in the current line. Use :s

:s/foo/bar/g

:s/foo/bar/g

Search for “foo” and replace it with “bar” in the entire document. Use :%s

:%s/foo/bar/g

:%s/foo/bar/g

You can also pipe instead of forward slash. Useful if your search contains a /.

:%s|foo/|bar|g

:%s|foo/|bar|g

Filed Under: Linux Tagged With: entire, file, replace, search, vim

  • Home
  • About
  • Contact

Copyright © 2022