Skip to content

Instantly share code, notes, and snippets.

@PompaDonpa
Last active August 31, 2022 15:20
Show Gist options
  • Save PompaDonpa/2ea500f5bf15dcf92455916ecbee7bdc to your computer and use it in GitHub Desktop.
Save PompaDonpa/2ea500f5bf15dcf92455916ecbee7bdc to your computer and use it in GitHub Desktop.
Shell Commands
" Moves *.py files to < PATH > "
find . -name "*.py" -print0 | xargs -0 -I {} mv {} /Users/<user>/Desktop/unix_practice/code/python
" Deletes everything inside . but -name <file> "
find . ! -name index.html -delete
" Copies everything with permissions "
cp -rp unix_practice/* ./unix_practice_backup_1
" Find the most used commands in ZSH change history to history 1 "
history | awk '{$1="";print substr($0,2)}' | sort | uniq -c | sort -n | tail -n 10
" Executing commands "
" Trying to ssh as user foo in server bar.mit.edu "
ssh foo@bar.mit.edu
ssh foobar@192.168.1.42
" Will grep locally the remote output of ls "
ssh foobar@server ls | grep PATTERN
" Will grep remotely the local output of ls "
ls | ssh foobar@server grep PATTERN
" SSH Keys - Key generation "
ssh-keygen -o -a 100 -t ed25519 -f ~/.ssh/id_ed25519
" Key based authentication "
cat .ssh/id_ed25519.pub | ssh foobar@remote 'cat >> ~/.ssh/authorized_keys'
ssh-copy-id -i .ssh/id_ed25519.pub foobar@remote
" Copying files over SSH "
cat localfile | ssh remote_server tee serverfile
" When copying large amounts of files/directories, the secure copy scp "
scp path/to/local_file remote_host:path/to/remote_file
" The most common scenario is local port forwarding, where a service in the remote machine listens in a port
and you want to link a port in your local machine to forward to the remote port. For example, if we execute
jupyter notebook in the remote server that listens to the port 8888. Thus, to forward that to the local port 9999,
we would do ssh -L 9999:localhost:8888 foobar@remote_server and then navigate to locahost:9999 in our local machine. "
" Port Forwarding "
localhost:PORT
127.0.0.1:PORT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment