Browsed by
Category: Linux

Bash – substitute substring in a string

Bash – substitute substring in a string

Today I came across interesting issue – how to remove part of the string containing slash. Full string:

The desired goal is to extract releases/10 from the string. Code:

And here we go:

Python dependencies on project level

Python dependencies on project level

Since I started work with Python, I struggled with dependencies on a project level. I was aware of requirements.txt file, but handling it became very difficult for multiple projects. Fortunately I found very handy tool called pipreqs which generages a project level requirements.txt file using one command. Installation

Usage Just go into your project directory and run

and install inside target environment

Sometimes it does on work on 100 %, but it can save a lot of…

Read More Read More

ls -la output explanation

ls -la output explanation

Show files ls Will provide basic overview of files and folders present in the directory

Show files with details ls -l With file / folder details

Show hidden files ls -la Will show hidden files with . prefix

Output exmplanation

Bonus Running this command will add alias ll to run ls -la where this shortcut is not present yet.

Connecting the Raspberry Pi Zero W/WH to WiFi

Connecting the Raspberry Pi Zero W/WH to WiFi

Recently I bought a Raspberry Pi Zero WH, and I wanted to connect it to my WiFi, but first 5 guides from Google were not working well, so I wanted to share the approach I used using raspi-config. 0. Get ready Raspbian on the Pi And connect to it using ethernet or plug in the monitor to it via HDMI. 1. Get ready SSH You can do this using sudo raspi-config (5. Interfacing options/P2 SSH) or using

Default credentials…

Read More Read More

Display apps and occupied ports (Linux)

Display apps and occupied ports (Linux)

PROBLEM: My app is not starting, because port is already in use! SOLUTION: Find it and kill it 🙂 netstat -tulpn Will provide nice table with all info you migh like, truncated outpus below:

sudo ss -tulpn More fresh, more detailed (i like it more than netstat)

Now you can find what is “eating” your ports and you are able to debug errors 🙂 Note: If you cannot see the PID, use sudo to execute the command

Resize swap in Ubuntu 18.04 and later (Linux)

Resize swap in Ubuntu 18.04 and later (Linux)

PROBLEM: My swap is too small 🙁 SOLUTION: Disable, resize and enable swap again! 1. Disable swap

2. Resize swap With goal of 2 GB (1 GB * 2)

Where: if – input file of – output file bs – block size count – block multiplier Note: If you get error: dd: memory exhausted by input buffer of size 1073741824 bytes (1.0 GiB) just try to change the bs to MB and increase the count size

3. Make…

Read More Read More

Permanently exporting environment variables using direnv (Linux)

Permanently exporting environment variables using direnv (Linux)

PROBLEM: I use some variables (credentials) so often, but I don’t like exporting them each time SOLUTION: Start using direnv! Direnv should be already present in your system You can check the same on the direnv website (here), if is not, you can always build it from binary. Hook direnv into shell Add this line on the end of your .bashrc file (if you are using bash)

Create .envrc file And put all variables you would like to have accesible…

Read More Read More

Create permanent command alias (Linux)

Create permanent command alias (Linux)

PROBLEM: My set up aliases are not persistent after reboot SOLUTION: Write them to ~/.bashrc Edit ~/.bashrc Using sudo

Add as many aliases as you wish! Separe by new line. I prefer adding them on the beginning of the file so I can find them quickly.

Copy output from terminal directly to your clipboard! (Linux)

Copy output from terminal directly to your clipboard! (Linux)

PROBLEM: It is difficult to copy and past outputs from and to terminal SOLUTION: Use xclip! Install xclip To install xclip on Ubuntu just use apt get, on other use the equivalent command.

Basic commands To copy output to your clipboard, just simply use | xclip (| means, everything before pipe is input for command after pipe)like this:

And you have content of myfile in your clipboard! To paste from your clipboard, just use:

Advanced strategy! To work…

Read More Read More