• Skip to main content

Uly.me

cloud engineer

  • Home
  • About
  • Archives

find

GCP Find Instance Boot Disk

April 13, 2022

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

Replace spaces with comma

February 4, 2020

Here’s a simple sed command to replace multiple spaces into a comma delimited file.

sample.txt

one       two
three     four

one two three four

The sed command.

sed 's/ \+ /,/g' sample.txt > sample2.txt

sed 's/ \+ /,/g' sample.txt > sample2.txt

sample2.txt

one,two
three,four

one,two three,four

Filed Under: Linux Tagged With: comma, find, replace, sed, spaces, tab

Count Number of Files in Directory

May 14, 2019

Get a count of the number of files in a directory.

# using ls
ls | wc -l
ls -Aq | wc -l
# include hidden files 
find . ! -name . -prune -print | grep -c /
find .//. ! -name . -print | grep -c //
# using tree if installed. yum install tree. apt-get install tree
tree

# using ls ls | wc -l ls -Aq | wc -l # include hidden files find . ! -name . -prune -print | grep -c / find .//. ! -name . -print | grep -c // # using tree if installed. yum install tree. apt-get install tree tree

Filed Under: Linux Tagged With: count, find, ls, tree, wc

Find the Biggest File

April 1, 2019

Find the biggest files in the current directory. Sort by from large to small. Display only the top 20. Display in human readable format.

find -type f -exec du -Sh {} + | sort -rh | head -n 20

find -type f -exec du -Sh {} + | sort -rh | head -n 20

Filed Under: Linux Tagged With: big, du, file, find, sort

List Big Files

March 13, 2019

Find out which files or directories are using up disk resources.

# display the biggest files
find -type f -exec du -Sh {} + | sort -rh | head -n 5
# display the biggest directories
du -Sh | sort -rh | head -5

# display the biggest files find -type f -exec du -Sh {} + | sort -rh | head -n 5 # display the biggest directories du -Sh | sort -rh | head -5

Filed Under: Linux Tagged With: directories, display, files, find, large

  • Home
  • About
  • Archives

Copyright © 2023