Skip to content

Tag: cli

tmux save scrollback to a file

Before each command, run the prefix (default Ctrl+B).

:capture-pane -pane -S -3000
:save-buffer buffer.txt

This will write all scrollback from that pane to a file ~/buffer.txt.

Lenovo IdeaPad 1

Lenovo IdeaPad 1 14″ Laptop Computer – Cloud Grey (AMD Ryzen 5 5500U 2.1GHz Processor; 8GB DDR4-3200 Onboard RAM; 256GB Solid State Drive; AMD Radeon 7 Graphics) USD$ 229.99 + taxes.

Micro Center product page screenshot.

Went to the BIOS and changed it to performance mode. Got the Windows keys out and installed Ubuntu 22.04.3 LTS (jammy).

PCI buses information:

$ sudo update-pciids
$ lspci -nn

00:00.0 Host bridge [0600]: Advanced Micro Devices, Inc. [AMD] Renoir/Cezanne Root Complex [1022:1630]
00:00.2 IOMMU [0806]: Advanced Micro Devices, Inc. [AMD] Renoir/Cezanne IOMMU [1022:1631]
00:01.0 Host bridge [0600]: Advanced Micro Devices, Inc. [AMD] Renoir PCIe Dummy Host Bridge [1022:1632]
00:02.0 Host bridge [0600]: Advanced Micro Devices, Inc. [AMD] Renoir PCIe Dummy Host Bridge [1022:1632]
00:02.1 PCI bridge [0604]: Advanced Micro Devices, Inc. [AMD] Renoir/Cezanne PCIe GPP Bridge [1022:1634]
00:02.2 PCI bridge [0604]: Advanced Micro Devices, Inc. [AMD] Renoir/Cezanne PCIe GPP Bridge [1022:1634]
00:02.4 PCI bridge [0604]: Advanced Micro Devices, Inc. [AMD] Renoir/Cezanne PCIe GPP Bridge [1022:1634]
00:08.0 Host bridge [0600]: Advanced Micro Devices, Inc. [AMD] Renoir PCIe Dummy Host Bridge [1022:1632]
00:08.1 PCI bridge [0604]: Advanced Micro Devices, Inc. [AMD] Renoir Internal PCIe GPP Bridge to Bus [1022:1635]
00:08.2 PCI bridge [0604]: Advanced Micro Devices, Inc. [AMD] Renoir Internal PCIe GPP Bridge to Bus [1022:1635]
00:14.0 SMBus [0c05]: Advanced Micro Devices, Inc. [AMD] FCH SMBus Controller [1022:790b] (rev 51)
00:14.3 ISA bridge [0601]: Advanced Micro Devices, Inc. [AMD] FCH LPC Bridge [1022:790e] (rev 51)
00:18.0 Host bridge [0600]: Advanced Micro Devices, Inc. [AMD] Renoir Device 24: Function 0 [1022:1448]
00:18.1 Host bridge [0600]: Advanced Micro Devices, Inc. [AMD] Renoir Device 24: Function 1 [1022:1449]
00:18.2 Host bridge [0600]: Advanced Micro Devices, Inc. [AMD] Renoir Device 24: Function 2 [1022:144a]
00:18.3 Host bridge [0600]: Advanced Micro Devices, Inc. [AMD] Renoir Device 24: Function 3 [1022:144b]
00:18.4 Host bridge [0600]: Advanced Micro Devices, Inc. [AMD] Renoir Device 24: Function 4 [1022:144c]
00:18.5 Host bridge [0600]: Advanced Micro Devices, Inc. [AMD] Renoir Device 24: Function 5 [1022:144d]
00:18.6 Host bridge [0600]: Advanced Micro Devices, Inc. [AMD] Renoir Device 24: Function 6 [1022:144e]
00:18.7 Host bridge [0600]: Advanced Micro Devices, Inc. [AMD] Renoir Device 24: Function 7 [1022:144f]
01:00.0 SD Host controller [0805]: O2 Micro, Inc. SD/MMC Card Reader Controller [1217:8621] (rev 01)
02:00.0 Network controller [0280]: MEDIATEK Corp. MT7921 802.11ax PCI Express Wireless Network Adapter [14c3:7961]
03:00.0 Non-Volatile memory controller [0108]: Micron Technology Inc 2450 NVMe SSD [HendrixV] (DRAM-less) [1344:5411] (rev 01)
04:00.0 VGA compatible controller [0300]: Advanced Micro Devices, Inc. [AMD/ATI] Lucienne [1002:164c] (rev c2)
04:00.1 Audio device [0403]: Advanced Micro Devices, Inc. [AMD/ATI] Renoir Radeon High Definition Audio Controller [1002:1637]
04:00.2 Encryption controller [1080]: Advanced Micro Devices, Inc. [AMD] Family 17h (Models 10h-1fh) Platform Security Processor [1022:15df]
04:00.3 USB controller [0c03]: Advanced Micro Devices, Inc. [AMD] Renoir/Cezanne USB 3.1 [1022:1639]
04:00.4 USB controller [0c03]: Advanced Micro Devices, Inc. [AMD] Renoir/Cezanne USB 3.1 [1022:1639]
04:00.5 Multimedia controller [0480]: Advanced Micro Devices, Inc. [AMD] ACP/ACP3X/ACP6x Audio Coprocessor [1022:15e2] (rev 01)
04:00.6 Audio device [0403]: Advanced Micro Devices, Inc. [AMD] Family 17h/19h HD Audio Controller [1022:15e3]
05:00.0 SATA controller [0106]: Advanced Micro Devices, Inc. [AMD] FCH SATA Controller [AHCI mode] [1022:7901] (rev 81)
05:00.1 SATA controller [0106]: Advanced Micro Devices, Inc. [AMD] FCH SATA Controller [AHCI mode] [1022:7901] (rev 81)

Installing AMD drivers:

$ sudo apt install gdebi
$ sudo gdebi amdgpu-install_5.7.50702-1_all.deb
$ amdgpu-install

Drivers information:

$ glxinfo -B
name of display: :0
display: :0  screen: 0
direct rendering: Yes
Extended renderer info (GLX_MESA_query_renderer):
    Vendor: AMD (0x1002)
    Device: AMD Radeon Graphics (renoir, LLVM 16.0.6, DRM 3.49, 6.2.0-36-generic) (0x164c)
    Version: 23.2.0
    Accelerated: yes
    Video memory: 2048MB
    Unified memory: no
    Preferred profile: core (0x1)
    Max core profile version: 4.6
    Max compat profile version: 4.6
    Max GLES1 profile version: 1.1
    Max GLES[23] profile version: 3.2
Memory info (GL_ATI_meminfo):
    VBO free memory - total: 1138 MB, largest block: 1138 MB
    VBO free aux. memory - total: 2991 MB, largest block: 2991 MB
    Texture free memory - total: 1138 MB, largest block: 1138 MB
    Texture free aux. memory - total: 2991 MB, largest block: 2991 MB
    Renderbuffer free memory - total: 1138 MB, largest block: 1138 MB
    Renderbuffer free aux. memory - total: 2991 MB, largest block: 2991 MB
Memory info (GL_NVX_gpu_memory_info):
    Dedicated video memory: 2048 MB
    Total available memory: 5120 MB
    Currently available dedicated video memory: 1138 MB
OpenGL vendor string: AMD
OpenGL renderer string: AMD Radeon Graphics (renoir, LLVM 16.0.6, DRM 3.49, 6.2.0-36-generic)
OpenGL core profile version string: 4.6 (Core Profile) Mesa 23.2.0-devel
OpenGL core profile shading language version string: 4.60
OpenGL core profile context flags: (none)
OpenGL core profile profile mask: core profile

OpenGL version string: 4.6 (Compatibility Profile) Mesa 23.2.0-devel
OpenGL shading language version string: 4.60
OpenGL context flags: (none)
OpenGL profile mask: compatibility profile

OpenGL ES profile version string: OpenGL ES 3.2 Mesa 23.2.0-devel
OpenGL ES profile shading language version string: OpenGL ES GLSL ES 3.20

Testing if APU is working:

$ sudo apt-get install mesa-utils
$ vblank_mode=0 glxgears
ATTENTION: default value of option vblank_mode overridden by environment.
54476 frames in 5.0 seconds = 10895.144 FPS
54569 frames in 5.0 seconds = 10913.684 FPS
55201 frames in 5.0 seconds = 11038.656 FPS

Benchmarking with glmark2:

$ sudo apt-get install glmark2
$ glmark2 --show-all-options

=======================================================
    glmark2 2021.02
=======================================================
    OpenGL Information
    GL_VENDOR:     AMD
    GL_RENDERER:   AMD Radeon Graphics (renoir, LLVM 16.0.6, DRM 3.49, 6.2.0-36-generic)
    GL_VERSION:    4.6 (Compatibility Profile) Mesa 23.2.0-devel
=======================================================
...
glmark2 Score: 2429

maybe

while true; do if [[ $(($RANDOM % 2 )) = "1" ]] then; echo "y"; else echo "n"; fi done

Mac: changing screenshots location

mkdir ~/Desktop/screenshots

defaults write com.apple.screencapture location ~/Desktop/screenshots

killall SystemUIServer
  1. Creates a directory in /Users/username/Desktop/screenshots.
  2. Sets the default screenshot location to that directory.
  3. Restarts the service responsible for screenshots.

New screenshots (?+Shift+3, 4 or 5) are now stored in ~/Desktop/screenshots.

Simple backup using S3 Sync

Given that you have the AWS CLI installed and configured, here are a few examples of syncing directories with S3.

Sync your home directory:
[bash]
aws s3 sync $HOME s3://homeof$USER
[/bash]

E.g. $USER is sil and $HOME is /home/sil, then this will copy all files from /home/sil to bucket homeofsil.

To download the files back to another directory:
[bash]
mkdir $HOME/oldhome
aws s3 sync s3://homeof$USER $HOME/oldhome
[/bash]

More details about S3 Sync in the official documentation.

Bash Brace Expansion

photo by whiskeyandtears at https://www.flickr.com/photos/whiskeyandtears/2140154564

[bash]$ echo {0..9}
0 1 2 3 4 5 6 7 8 9[/bash]

[bash]$ echo b{a,e,i,o,u}
ba be bi bo bu
[/bash]

[bash]$ echo x{0..9}y
x0y x1y x2y x3y x4y x5y x6y x7y x8y x9y[/bash]

[bash]$ echo {a..z}
a b c d e f g h i j k l m n o p q r s t u v w x y z[/bash]

[bash]$ echo {1..3} {A..C}
1 2 3 A B C[/bash]

[bash]$ echo {1..3}{A..C}
1A 1B 1C 2A 2B 2C 3A 3B 3C[/bash]

[bash]echo {a,b{1,2,3},c}
a b1 b2 b3 c[/bash]

[bash]$ mkdir -p {project1,project2}/{src,tst,bin,lib}/
$ find .
.
./project1
./project1/tst
./project1/bin
./project1/lib
./project1/src
./project2
./project2/tst
./project2/bin
./project2/lib
./project2/src
[/bash]

[bash]$ echo {{A..Z},{a..z}}
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z a b c d e f g h i j k l m n o p q r s t u v w x y z[/bash]

[bash]$ for i in {a..f} 1 2 {3..5} ; do echo $i;done
a
b
c
d
e
f
1
2
3
4
5[/bash]

The examples below requires Bash version 4.0 or greater.

[bash]$echo {001..9}
001 002 003 004 005 006 007 008 009
[/bash]

[bash]$ echo {1..10..2}
1 3 5 7 9
[/bash]

Congelando e Ressuscitando Processos

batman mr freeze

Nem só de morte vive o kill.

Suponha que você tem um processo chamado program e quer congelar seu funcionamento. Para congela-lo sem mata-lo você pode mandar um sinal SIGSTOP com:

kill -s stop `pidof program`

Para ressuscitar o mesmo processo:

kill -s cont `pidof program`

OGG com qualidade

Para o controle de qualidade quando encondando vídeos com o FFmpeg use o parâmetro -qscale seguido de um número. Os número podem ir de 1 (melhor qualidade) até 31 (pior qualidade), sendo que 13 já é uma qualidade bem ruim.

Convertendo pro exemplo um vídeo chamado exemplo.flv para um arquivo ogg com a melhor qualidade seria:

ffmpeg -i exemplo.flv -qscale 1 saida.ogg

Sem usar esse parâmetro os arquivos encodados em OGG ficam com uma qualidade mediana. Uma opção bem útil é usar a mesma qualidade do arquivo de entrada, já que não é possível melhorar a qualidade do vídeo mesmo. Para isso existe o parâmetro -sameq. No exemplo anterior bastaria:

ffmpeg -i exemplo.flv -sameq saida.ogg

Com isso eu tenho reduzido os vídeos da minha câmera para arquivos que só ocupam cerca de 1/5 do tamanho original e ainda assim mantém a mesma qualidade.

Example of Unix commands implemented in Java

I created some illustrative and simple implementations of common Unix commands. For those who are familiar with Unix-like systems them make easier to understand Java. For those who are familiar with Java them make easier to understand Unix-like systems. 🙂

1. PWD

The first one is pwd that show the current working directory.

public class Jpwd {
    public static void main(String[] args) {
        String pwd = System.getProperty("user.dir");
        System.out.println(pwd);
    }
}

Running this at /home/silveira directory gives us as output:

$ java Jpwd

/home/silveira

1. CAT

The command cat is usually utilized for displaying files.

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

public class Jcat {
    public static void main(String[] args) {
        if(args.length==1){
            try {
                FileReader fileReader = new FileReader(args[0]);
                BufferedReader in = new BufferedReader(fileReader);
                String line;
                while((line = in.readLine())!= null){
                    System.out.println(line);
                }
            } catch (FileNotFoundException ex) {
                System.out.println(args[0]+", file not found.");
            }
            catch (IOException ex) {
                System.out.println(args[0]+", input/output error.");
            }
        }
    }
}

$ java Jcat /etc/timezone

America/Fortaleza

3. LS

The command ls is to list files. The File API (java.io.File) is very flexible and portable, but in this example I want just list files and directories of the current directory.

import java.io.File;

public class Jls {
    public static void main(String[] args) {
        File dir = new File(System.getProperty("user.dir"));
        String childs[] = dir.list();
        for(String child: childs){
            System.out.println(child);
        }
    }
}

Usage:

$ java Jpwd

/home/silveira/example

$ java Jls

directoryA

fileA

.somefile

4. CD

The cd command changes the current working directory.

import java.io.File;

public class Jcd {
    public static void main(String[] args) {
        if(args.length==1){
            File dir = new File(args[0]);
            if(dir.isDirectory()==true) {
                System.setProperty("user.dir", dir.getAbsolutePath());
            } else {
                System.out.println(args[0] + "is not a directory.");
            }
        }
    }
}

Usage:

$ java Jpwd
/home/silveira
$ java Jcd /tmp
$ java Jpwd
/tmp