Skip to content

Misc

Directories / Files

Find files or directories by keyword

find /path -type {f or d} -name "*keyword*"

Count all files in directory (recursively)

find dir/ -type f | wc -l

List files above size

sudo find dir/ -type f -size +500M -exec ls -lh {} \;

List top N files by size

du -ah dir/ | sort -nr | head -n20
find /usr/lib -maxdepth 1 -type l -ls | sort

Find/Remove Files

find dir/ -name "*.ext" -exec rm -rf {} \;

Rename files to add leading zeros ref

rename -e 's/\d+/sprintf("%03d",$&)/e' -- *.pdf

Directory size

du -h --max-depth=1 dir/
du -sh dir/

Loop through files in directory

#!/bin/bash
FILES="/path/to/*"
for f in $FILES
do
  echo "Processing $f file..."
  cat "$f"
done

Filename and extension

name and extension: f="$(basename -- $FILE)"
name and extension: ${FILE##*/}
extension only: "${FILE#*.}" (tar.gz)
extension only: "${FILE##*.}" (gz)

Downloads

Download website

wget -mkEpnp https://engelsjk.com

Download files from FTP directory

wget -r -nc ftp://ftp2.website.tld/files/

Download files from server directory

wget -r -np -nH -w 2 --cut-dirs=4 -R index.html http://hostname/aaa/bbb/ccc/ddd/

ref

Other

Find all library files

find /usr/lib/ -name libx.so'*' -print

List dependencies

ldd $(which package)

Rsync ref

rsync -avz --delete --backup --backup-dir="backup_$(date +\\%Y-\\%m-\\%d)" /src/path/ /dest/path

Compress tar.gz

tar -zcvf archive_name.tar.gz folder_to_compress

HTTP request data in JSON ref

curl --write-out '%{json}' https://example.com -o saved

Ports/PID's

lsof -Pn -i4
lsof -i :{PORT}
kill -9 {PID}

Save list of mac applications

mdfind -onlyin /Applications kMDItemKind="Application" > apps.txt

Install bootable iso on USB

sudo dd bs=1m if=manjaro-kde-19.0.2-200311-linux54.iso of=/dev/rdisk2

Start OpenSSH service on Linux ref

sudo systemctl enable sshd.service
sudo systemctl start sshd.service

Specify which rsa file to use ref

host github.com
 HostName github.com
 IdentityFile ~/.ssh/id_rsa_github
 User git

Pacman is unavailable

sudo rm /var/lib/pacman/db.lck

Create bootable usb

sudo fdisk -l
sudo dd if=memtest86-usb.img of=/dev/sdd

New Git Repo

echo "# test" >> README.md
git init
git add README.md
git commit -m "first commit"
git remote add origin https://github.com/engelsjk/test.git
git push -u origin master

Serve Hugo on local network

hugo server --bind=10.0.0.9 --baseURL=http://10.0.0.9:1313

Review journalctl logs

journalctl --since "1 hour ago"

Check if csv has same number of columns

awk -F',' '{print NF}' data.csv | sort -nu

Open list of urls in new tabs

xargs -n1 firefox -new-tab < urls.txt

Posts no stories

instaloader --login user --stories --storyitem-filter="date_utc >= datetime(2022,7,4)" --no-posts profile

Format HDD

How to Format a Drive as exFAT on Linux