Skip to content

Instantly share code, notes, and snippets.

@martin-rdz
Last active September 1, 2022 07:38
Show Gist options
  • Save martin-rdz/e6eeb72564e9e45c7c1e369d89b36c80 to your computer and use it in GitHub Desktop.
Save martin-rdz/e6eeb72564e9e45c7c1e369d89b36c80 to your computer and use it in GitHub Desktop.
Collection of terminal one-liners

bash helpers

Loop over numbers

for i in $(seq -f "%02g" 1 11); do wget ftp://arlftp.arlhq.noaa.gov/archives/gfs0p25.v1/201903${i}_gfs0p25; done

for i in $(seq -f "%02g" 1 31); do python run_conversion_batch.py --date 201903${i}; done

Loop over dates

d=20200601; while [ "$d" != 20210102 ]; do ./run_cloudnet_cron.sh --date $d ; d=$(date -d "$d + 1 day" '+%Y%m%d') ; done

Loop lines in a file

cat output.dat | while read line || [[ -n $line ]]; do echo ${line}; done

Loop over a list

ls /data/level1b/peakTree/rpg94_lacros/ | while read -r line; do python3 2022-03-04_peaktree_cloudlab.py --date "$line"; done

Size per folder

du -sh -- *

Files newer than

find ${directory} -name "*.nc" -mtime +5

mount by label

udisksctl mount -b /dev/disk/by-label/Games

loop over array

:~$ b=("alfa" "beta beta2" "gamma")
:~$ echo ${b[@]}
alfa beta beta2 gamma
:~$ echo ${b[*]}
alfa beta beta2 gamma
:~$ for i in ${b[@]}; do echo $i; done # similar result by: for i in ${b[*]}; do echo $i; done
alfa
beta
beta2
gamma
:~$ for i in "${b[*]}"; do echo $i; done
alfa beta beta2 gamma
:~$ for i in "${b[@]}"; do echo $i; done
alfa
beta beta2
gamma

PowerShell helpers

Size per folder

$fso = new-object -com Scripting.FileSystemObject; gci -Directory | select @{l='Size'; e={$fso.GetFolder($_.FullName).Size}},FullName | sort Size -Descending | ft @{l='Size [MB]'; e={'{0:N2}    ' -f ($_.Size / 1MB)}},FullName

interactive Python

import readline; print('\n'.join([str(readline.get_history_item(i + 1)) for i in range(readline.get_current_history_length())]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment