Random Tech Thoughts

The title above is not random

Shell

Shell Tricks

  • Easy changing directory
    • cd - change to last directory
    • pushd and pops:
      • pushed change directory and store the current directory on a stack
      • pops pop one directory from the stack and change to it
  • The environment variable SHLVL gives the level of shells I’m in
  • Getting all the href links from a URL

    curl -s <url> | grep -o '<a *href *= *"[^"]*"' | cut -d '"' -s -f 2
    
  • ls sort by modification time:

    ls -t
    

find

  • Find broken soft links:

    find . -type l | (while read FN ; do test -e "$FN" || ls -ld "$FN"; done)
    
  • Find all hard links to some file:

    find -x <path> -samefile <file name>
    

    -x avoids searching in directories with different device number

  • Find files with modification in the future, use the -newer option

    find . -type f -newer <some file>