# pre-installed on Ubuntu 18:
tracepath -n IP/HOST
mtr -n IP/HOST
Tag Archives: linux
Get Linux system process list without ‘ps’ command
When you work with embedded systems sometimes you would feel happy to have a Linux box until you discover there are plenty of basic things that you don’t have available, the extreme of that could be the ‘ps’ command which is used most of the time for checking if any process is running . Maybe you know that thanks the /proc filesystem there is access to the source of the information.
Keep next command close for solving this inconvenience he next time:
find /proc -mindepth 2 -maxdepth 2 -name exe -exec ls -lh {} \; 2>/dev/null
Convert JSON file to YAML file using CLI
Just a cookbook about how to get a YAML file when you have a JSON one.
python -c 'import sys, yaml, json; yaml.safe_dump(json.load(sys.stdin), sys.stdout, default_flow_style=False)' < file.json > file.yaml
Nested byobu, re-assigning shortcuts
Reading time: 2 – 2 minutes
I’m a byobu user for a long time, I love it for many reasons. But this is just a quick tip for extreme users like me. I mean people who use byobu for local consoles with remote byobu sessions running on top of SSH, for instance.
When prefix key combinations has to be sent to the remote host we have to press “Control + a + a” and finally the command that we want to send to the remote systems. This is not comfortable many times. So, I modified my configuration file for changing the prefix when I want to send remote commands to the nested byobu.
This is going to work this way:
Control + a
-
- as a prefix for local byobu session.
Control + b
- as a prefix for remote byobu session
Take a look on this screen capture where you can see byobu status bars stacked.
If you find useful the configuration that I described the only thing that you have to do is modify the configuration file: ~/.byobu/keybindings.tmux
unbind-key -n C-a set -g prefix C-a set -g prefix2 F12 unbind-key -n C-b bind-key -n C-b send-prefix
I hope this is useful as it is for me.
nethogs: Linux net top tool
Reading time: < 1 minute When a title says all that you have to say, the best is paste the link of the tool and just attach a screenshot: nethogs.
HTTPie – command line HTTP client
Reading time: 1 – 2 minutes
I imagine you are used to using curl for many command line scripts, tests, and much more things. I did the same but some weeks ago I discovered HTTPie which is the best substitute that I’ve ever found for curl. Of course, it’s also available for a lot of Linux distributions, Windows, and Mac. But I used it with docker which is much more transparent for the operative system and easy to update. To be more precise I use next alias trick for using this tool:
alias http='sudo docker run -it --rm --net=host clue/httpie'
Official website: httpie.org
Let me paste some highlights about HTTPie:
- Sensible defaults
- Expressive and intuitive command syntax
- Colorized and formatted terminal output
- Built-in JSON support
- Persistent sessions
- Forms and file uploads
- HTTPS, proxies, and authentication support
- Support for arbitrary request data and headers
- Wget-like downloads
- Extensions
- Linux, macOS, and Windows support
From the tool webpage a nice comparison about how HTTPie looks like versus curl.
Linux: Mounting file as a partition
Reading time: 1 – 2 minutes
When we have a file with a ‘dd’ of a full disk and we want to mount a partition of that disk, we have to use an offset for jumping to the beginning of the partition that we want to mount.
Using ‘fdisk’ command we can find the partitions of that disk copied inside a file.
fdisk -l FILE_WITH_DISK_INSIDE
Once partition table is shown there is a column called ‘Start’ using the corresponding number in this column for the partition that we want we can obtain the offset required for our mounting point. Reasoning behind that is multiply start sector per number of bytes per sector.
# OFFSET = START * 512
mount -o ro,loop,offset=OFFSET FILE_WITH_DISK_INSIDE /mnt
I hope thanks to this technical note next time that I forget how to get the offset I find it fastly.
UPDATE 2018/08/29:
If you don’t want to do that manually, there is a small tool called losetup which maps the partitions of a disk image on a file.
# example, attaching partitions to loopback devices
losetup -P /dev/loop0 DISK_IMAGE
# just mount the devices now, they are /dev/loop0pX where X is the number of the partition
# dettach this assignament:
losetup -d /dev/loop0
Ubuntu synchronize NTP clock
Reading time: < 1 minute Synchronise Linux clock when NTP service is running but the clock is not on time:
sudo service ntp stop sudo ntpd -gq sudo service ntp start
socat tip: VPN without cyphering
Reading time: < 1 minute Fast reminder and tip for socat, it can work on two devices or more:
# SERVER: socat TCP-LISTEN:4443 TUN:192.168.255.2/24,up # CLIENT: socat TCP:SERVER_IP:4443 TUN:192.168.255.1/24,up
ngrok – service which solve services behind NAT issues
Reading time: < 1 minute This is another short entry, in this case for recommending a service which we solve typical problem solved using a DNAT. Once we have a service on our laptop, or on a private server and we have to expose that service on the internet for some time or permanently usually we have to go the firewall, or router and create a NAT rule forwarding a port. This is a simple and powerful service which is going to solve that for you. There is a free account for understanding and testing the service, other plans are available and especially affordable for professional requirements.
I was frogetting to say it’s compatible with Linux, Windows and Mac.