• Skip to main content

Uly.me

cloud engineer

  • Home
  • About
  • Search

Bash Replace Spaces with a Comma

May 8, 2023

Replace spaces with commas from one file and send the output to another file.

tr -s '[:blank:]' ', ' < input.txt > output.txt

tr -s '[:blank:]' ', ' < input.txt > output.txt

It’s perfect for creating a comma delimited file for importing to Excel.

Filed Under: Linux Tagged With: bash, commas, file, input, output, replace, spaces

FFMPEG Resize Video

April 13, 2023

Here’s how to reduce a MP4 video using H.265 format.

ffmpeg -i input.mp4 -vcodec libx265 -crf 28 output.mp4

ffmpeg -i input.mp4 -vcodec libx265 -crf 28 output.mp4

I was able to reduce a video file from 550MB to 26MB without much quality loss.

Filed Under: Linux Tagged With: h.265, mp4, resize

Bash Sort Files

April 10, 2023

How to sort files in Bash.

Display contents

$ cat file.txt
bbb
aaa
ccc
kkk
uuu
ppp

$ cat file.txt bbb aaa ccc kkk uuu ppp

Sort

$ sort file.txt
aaa
bbb
ccc
kkk
ppp
uuu

$ sort file.txt aaa bbb ccc kkk ppp uuu

Sort in place

$ sort -o file.txt file.txt
$ cat file.txt
aaa
bbb
ccc
kkk
ppp
uuu

$ sort -o file.txt file.txt $ cat file.txt aaa bbb ccc kkk ppp uuu

Filed Under: Linux Tagged With: bash, file, sort

Display certain lines in a file

March 23, 2023

This will display only lines 40-50 in a file called lines.txt.

$ cat lines.txt | head -n 50 | tail -n 10

$ cat lines.txt | head -n 50 | tail -n 10

For lines 90-100.

$ cat lines.txt | head -n 100 | tail -n 10

$ cat lines.txt | head -n 100 | tail -n 10

and so on.

Filed Under: Linux Tagged With: cat, display, head, lines, tail

Memory Info on Linux

March 15, 2023

Here’s how to view system memory on Linux.

Default display is in kB

cat /proc/meminfo
MemTotal:        7492768 kB
MemFree:          427368 kB
MemAvailable:    5424768 kB

cat /proc/meminfo MemTotal: 7492768 kB MemFree: 427368 kB MemAvailable: 5424768 kB

Display in MB

awk '$3=="kB"{$2=$2/1024;$3="MB"} 1' /proc/meminfo | column -t
MemTotal:           7317.16      MB
MemFree:            404.527      MB
MemAvailable:       5285.4       MB

awk '$3=="kB"{$2=$2/1024;$3="MB"} 1' /proc/meminfo | column -t MemTotal: 7317.16 MB MemFree: 404.527 MB MemAvailable: 5285.4 MB

Output in GB

awk '$3=="kB"{$2=$2/1024^2;$3="GB";} 1' /proc/meminfo | column -t
MemTotal:           7.14566      GB
MemFree:            0.370392     GB
MemAvailable:       5.13733      GB

awk '$3=="kB"{$2=$2/1024^2;$3="GB";} 1' /proc/meminfo | column -t MemTotal: 7.14566 GB MemFree: 0.370392 GB MemAvailable: 5.13733 GB

Filed Under: Linux Tagged With: display, linux, meminfo, memory, proc

  • « Go to Previous Page
  • Go to page 1
  • Go to page 2
  • Go to page 3
  • Go to page 4
  • Interim pages omitted …
  • Go to page 201
  • Go to Next Page »
  • Home
  • About
  • Search

Copyright © 2023