Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Common linux / terminal commands I always use but forget. So fuck it I'm saving em here

common terminal commands

ubuntu updates & clean

  • sudo apt update && sudo apt upgrade -y
  • sudo apt autoremove && sudo apt clean

copy mac public ssh key

  • pbcopy < ~/.ssh/id_rsa.pub

edit host file and flush dns after

  • sudo vi /private/etc/hosts
  • dscacheutil -flushcache

tar and untar .gz & .xz files

  • .XZ create: tar cvJf file.tar.xz /whatdir
  • .XZ untar: tar -xf file.tar.xz
  • .GZ create: tar cvzf file.tar.gz /whatdir
  • .GZ untar: tar -xvf file.tar.gz and add -C /dir to put it somewhere

symlink to a directory

  • ln -s /path/to/dir/
  • ln -fs /path/to/dir/ (to force an update of symlink)

tail a log with x lines viewable

  • tail -fn 30 file.log

moving files and directories

move all files and folders from one directory to another directory
  • mv -v ~/repo/* ~/public/
copy a directory and all files in it keeping perms
  • cp -avr /htdocs/wp-content/staging/wp-content/uploads/ /htdocs/wp-content/production/wp-content/
move all files but not folders from one directory to another directory
  • find ~/repo/ -type f -print0 | xargs -0 mv -t ~/public
move only files from the one directory, but not from sub-directories
  • find ~/repo/ -maxdepth 1 -type f -print0 | xargs -0 mv -t ~/public
move a file to/from localhost/remotehost
  • scp user@remotehost.tld:/remote/filepath/file.tar.gz /local/path/file.tar.gz
  • scp file.tar.gz user@remotehost.tld:/remote/filepath/
  • scp user@remotehost1.tld:/remote/filepath/file.tar.gz \user@remotehost2.tld:/remote/filepath/

rename all files in directory to lowercase

  • for f in *; do mv "$f" "`echo $f | tr "[:upper:]" "[:lower:]"`"; done

Bash / ZSH Aliases

  • alias ll='ls -lahGF'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.