Live data from Hacker News

Ask HN: Can I see your cheatsheet?

news.ycombinator.com

51–60 of 173 posts

Re: Ask HN: Can I see your cheatsheet?

#51
post #49

- List dirs and file count, to find dir with high file count. for i in /home/*; do echo $i; find $i | wc -l; done for i in /*; do echo $i; find $i | wc -l; done - Report space usage of the top level subdirectories. du -h --max-depth=2 - Report space summary only, no directory output. du -s -h - Find out which device a directory is in. df /tmp df /home - Print of tree of directories tree . - Disk fdisk -l, list disk p…

I very often use the while pattern. Where ls -1 and echo $line can be swapped out.

    ls -1 | while read line; do echo $line; done

Re: Ask HN: Can I see your cheatsheet?

#52
Like some others, I don't have a list of cheatsheets except my bash history and my browser bookmarks. My bash history atm contains 4575 unique entries (I reset it a few weeks ago). It is like L1 cache to me for accessing most frequently used commands. Beside that I press `*` then Space in browser bar to search my previously bookmarks (I add keywords to them upon bookmarking by modifying the title). Beside these two, nowadays I write Makefiles in every project I work on. That way one can consolidate all commands that otherwise would be forgotten or scattered in configs, in one place.

Re: Ask HN: Can I see your cheatsheet?

#53
post #43

- Find all files modified in the last 90 minutes find . -type f -mmin -90 - Find all files and do something to each one find . -type f -mmin -90 | xargs ls -l - Find all files modified before 2 days ago find . -type f -mtime +2 - Removing files older than 7 days find . -type f -mtime +7 -name '*.gz' -exec rm {} \; - Find all files modified after last 2 days find . -type f -mtime -2 - Find all files modified at the la…

Ooh thanks!!!

Re: Ask HN: Can I see your cheatsheet?

#54
post #33

No maintained cheat sheet here either. I do use `history | grep` quite a lot though. One thing I try to do is to keep my keyboard shortcuts consistent between programs/systems. That way the chance of my instinct of pressing ` +a` to move the cursor to the start of the line will be correct more often. Another thing I try to do when a project has a set of complex commands that are needed, is to add them as a rule in it…

I use Ctrl+R chronically for the same thing.

I've been loving mcfly[0], a history search that can be bound to . It makes suggestions based on your current directory as well as your command history.

[0] https://github.com/cantino/mcfly

Re: Ask HN: Can I see your cheatsheet?

#55
post #43

- Find all files modified in the last 90 minutes find . -type f -mmin -90 - Find all files and do something to each one find . -type f -mmin -90 | xargs ls -l - Find all files modified before 2 days ago find . -type f -mtime +2 - Removing files older than 7 days find . -type f -mtime +7 -name '*.gz' -exec rm {} \; - Find all files modified after last 2 days find . -type f -mtime -2 - Find all files modified at the la…

There needs to be a new version of find with a more intuitive UI. (I suspect it exists, but I can't remember the name right now)

This is fd.

    fd --newer 90min
    fd --newer 90min -x ls -l {}
    fd --older 2d
    fd -g '*.txt' --older 7d -x rm {}
    fd --newer 2d
    fd --newer 3d --older 1d

Re: Ask HN: Can I see your cheatsheet?

#56
post #43

- Find all files modified in the last 90 minutes find . -type f -mmin -90 - Find all files and do something to each one find . -type f -mmin -90 | xargs ls -l - Find all files modified before 2 days ago find . -type f -mtime +2 - Removing files older than 7 days find . -type f -mtime +7 -name '*.gz' -exec rm {} \; - Find all files modified after last 2 days find . -type f -mtime -2 - Find all files modified at the la…

There needs to be a new version of find with a more intuitive UI. (I suspect it exists, but I can't remember the name right now)

I've been pretty happy with `fd`: https://github.com/sharkdp/fd

Re: Ask HN: Can I see your cheatsheet?

#57
Usually I'll just search online and read man pages (and experiment different options and solutions) but here's a short list of my most used aliases and functions, I guess that's the closest thing I have to a cheatsheet

  alias private='shopt -uo history'

  alias unprivate='shopt -so history'

  alias gl="git log --all --decorate --oneline --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)%Creset'"

  alias gitlog='git log --graph --pretty=format:"%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)%Creset" --abbrev-commit --date=relative --branches'

  alias sha256sum="shasum -a 256"

  alias sha512sum="shasum -a 512"

  alias flushDNSMac="sudo killall -HUP mDNSResponder"

  alias myip="dig +short myip.opendns.com @resolver1.opendns.com"

  alias m1="arch -arm64"

  alias x86="arch -x86_64"

  alias ibrew='arch -x86_64 /usr/local/bin/brew'

  alias upgrade="ibrew upgrade && m1 brew upgrade && mas upgrade"

  alias docker-clean='docker ps -aq | xargs -P $(nproc) -n1 docker rm -f ; docker rmi -f $(docker images --filter "dangling=true" -q --no-trunc)'

  alias autoscalerstatus="kubectl describe -n kube-system configmap cluster-autoscaler-status"

  alias evictedpods="kubectl get pods --all-namespaces --field-selector=status.phase=Failed"

  2qr() {
    qrencode "$1" -t ANSI256 -o -
  }

  curl_status() {
    if [ -n "${1}" ]; then
      curl -L -o /dev/null --silent --head --write-out '%{http_code}\n' "$1"
    fi
  }

  webp_convert() {
    local file="$1"
    cwebp -q 100 "$file" -o "${file%.\*}.webp"
  }

To minify everything (using https://github.com/tdewolff/minify)

  find ./dist/ -type f \( \
    -name "*.html" \
    -o -name '*.js' \
    -o -name '*.css' \
    -o -name '*.svg' \
    -o -name "*.xml" \
    -o -name "*.json" \
    -o -name "*.htm" \
    \) \
    -and ! -name "*.min\*" -print0 |
    xargs -0 -n1 -P4 -I '{}' sh -c 'minify -o "{}" "{}"'

Re: Ask HN: Can I see your cheatsheet?

#58
Creating clips from tv recordings:

    ffmpeg -ss 01:59:00.000 -i "interlaced.ts" -ss 00:00:12.000 -t 26 -max_muxing_queue_size 1024 -c:a libopus -b:a 96k -c:v libx264 -crf 20 -vf "yadif=1" -profile:v baseline -level 3.0 -pix_fmt yuv420p -movflags +faststart -y clip.mp4
Make clip compatible with WhatsApp:

    ffmpeg -i in.mp4 -map 0:v:0 -map 0:a:0 -map_metadata -1 -map_chapters -1 -c:v libx264 -preset slow -tune film -crf 32 -c:a aac -b:a 128k -profile:v baseline -level 3.0 -pix_fmt yuv420p -movflags +faststart out.mp4
Copying in various terminals:

    PuTTY: select
    tmux: Shift + select
    cmd: select + Enter in quick edit mode
    Windows Terminal: select + Right Click

Re: Ask HN: Can I see your cheatsheet?

#60
I use my ebooks for reference:

* GNU grep and ripgrep (https://learnbyexample.github.io/learn_gnugrep_ripgrep/)

* GNU sed (https://learnbyexample.github.io/learn_gnused/)

* GNU awk (https://learnbyexample.github.io/learn_gnuawk/)

* Ruby one-liners cookbook (https://learnbyexample.github.io/learn_ruby_oneliners/)

* Perl one-liners cookbook (https://learnbyexample.github.io/learn_perl_oneliners/)

* Command line text processing with GNU Coreutils (https://learnbyexample.github.io/cli_text_processing_coreuti...)

* Command line text processing with Rust tools (https://learnbyexample.github.io/cli_text_processing_rust/) — work-in-progress

* Computing from the Command Line (https://learnbyexample.github.io/cli-computing/) — work-in-progress

Post reply on HN