Linux

2021-03-18

Curl

sudo curl -L https://down.load/file -o here

Memory usage

NOTE, that cache does not take memory from apps.

free -wh

Compressed Files

Unpack compressed tar gz files

tar xfv ../Downloads/zulu8.40.0.25-ca-jdk8.0.222-linux_x64.tar.gz
unzip netbeans.zip
unzip -l netbeans.zip	// list files
unzip netbeans.zip -d specific-dir/		// extract to dir specific dir
zip -r -0 -s 900m archive-0.zip folder-to-archive/    // split zip each 900MB; just archive no compress; recursivly.

Copy Files

Copy all files with file-* to current folder. verbose on.

cp -v folder/file-* .

Copy files multible times

for i in {1..100}; do cp free.ogg "free$i.ogg"; done

Disc usage

Display free disk space; human readable; max depth

df -h .
du -h --max-depth=1 /home/

Network

arp	// list MAC adress to IP adress
cat /var/dhcp.leases	// show IP adress, hostname, MAC adress
nmap -v ip.adress	// fast simple scan for default ports
sudo service dnsmasq restart	// restart dnsmasq: DCHP server (usually this is installed on openwrt)
dmesg	// display kernel ring buffer (data structure of messages operated by kernel)

Symbolic links

Create and remove symbolic links.

ln -s zulu8.40.0.25-ca-jdk8.0.222-linux_x64 jdk
rm jdk  // remove symbolic link

Image resize

You need a imagemagick tool for this command.

convert -resize 25% screenshot.png screenshot.png

Find

Find files named *.md in or below the directory development/ with max depth 2

find development/ -maxdepth 2 -name *README.md -type f -print

System specification

The command lshw should be installed by default. With lshw you can list cpu, memory or all system information in console, as json or html.

List memory only.

sudo lshw -C memory
  *-memory                  
       description: System Memory
       physical id: 1
       slot: System board or motherboard
       size: 16GiB

List systen information: machine, cpu, battery, ...

inxi
inxi -Fxz

# Battery:   ID-1: BAT0 charge: 42.4 Wh condition: 53.3/57.0 Wh (93%) status: Not charging

List all with format html.

sudo lshw -html > specs.html

Free up space

Use autoremove on ubuntu to remove old packages, kernel, ...

sudo apt-get autoremove

You can also clean apt chache

sudo du -sh /var/cache/apt
sudo apt-get autoclean

Clear systemd journal logs older then 3 days

journalctl --disk-usage
sudo journalctl --vacuum-time=3d

Remove snap older versions

du -h /var/lib/snapd/snaps

#!/bin/bash
# Removes old revisions of snaps
# CLOSE ALL SNAPS BEFORE RUNNING THIS
set -eu
snap list --all | awk '/disabled/{print $1, $3}' |
    while read snapname revision; do
        snap remove "$snapname" --revision="$revision"
    done

If you want to use a UI then stacer is a good tool

Snap

The snap-store under linux using ~ 500MB. As an alternative you can use gnome-software.

sudo snap remove snap-store && sudo apt install gnome-software

Battery

Calculate the battery capacity with energy_full values: 56760000 / 57020000 * 100 = 99.5%

cat /sys/class/power_supply/BAT0/energy_full
56760000

cat /sys/class/power_supply/BAT0/energy_full_design
57020000

Tools like tlp or tlp-stat --battery could also be useful for battery management or stats.

Links