tmux
sed (Stream Editor)
sed s/-/\ /gsubstitute globally (- to spaces in this case)
users and groups
- list all users:
cut -d: -f1 /etc/passwdORcompgen -u - list all groups:
compgen -g - see logged in users:
users - get groups current user belongs to:
groups - make a user:
sudo adduser username - default user settings in
/etc/adduser.conf(you can configure default groups, skel directory, etc.) - skeleton directory default:
/etc/skel(may need tomkdir) - delete a user and their home folder:
sudo deluser username --remove-home
git
- if you are new to using
git:- Don't use the desktop gui: if you can
cd,ls, you can usegit - *before each commit, before each commit, run
git status. you should understandM, untracked, new file, etc. Until you can are confident whatgit statusis going to say, (which is never 100%), you should rungit statusbefore committing.
- Don't use the desktop gui: if you can
git checkout -b branchName origin/branchNameto fetch remote branchgit push origin --delete branchNameto delete a remote branch (dogit branch -d <branch_name>to delete local branch)git clone -b <branch> <remote_repo>to clone a repo at a specific branch (useful for puttinggh-pagesbranch indistfolder)git checkout HEAD -- my-file.txtto hard reset a specific filegit reset --hardto hard reset all modified files back to their state at the specified commit (or latest). leaves new files (but don't quote me on that)git resetto go back to last commit. leaves files modified and new files. i.e.git statuswill show the same as it did just beforegit commitgit reset --hardto simulate arm project,git clone project, but it might keep your new files?git reset --softto keep the changes. can basically commit with new message at this point.git tag -a v0.1.0 -m "0.1 Release"to tag the current commit,git push origin --tagsto push tags- git subtree
- renaming a branch:
- If it is your current branch just do.
git branch -m new_name. - If it is another branch you want to rename.
git branch -m old_name new_name. - If your branch was pushed, then after renaming you need to delete it from the remote git and ask your new local to track a new remote branch.
git push origin :old_name.
- If it is your current branch just do.
storage
df -hto get disk usagesudo du -sh ./*to see how much space each file/file in cwd is usingsudo du -sh ./* | gsort -rhto sort by size.sorton linux.brew install coreutilson osx
curl
Simple get:
curl http://localhost:3000/test
Use -O to send output to name of url. -o thingy.html into a file.
JSON POST:
curl -X POST http://localhost:3000/user/signup -H "Content-Type: application/json" -d'{"username":"bob", "password":"Password1"}'
Tar
compress zee file verbosely!
tar czfv output.tar.gz file-or-folder
Note: -czfv will not work, but -zcvf will. The first is easier to remember, but it takes a little while to also remember it does not use a dash.
extract zee file verbosely!
tar xzfv thingy.tar.gz
Look inside a tarball without extracting:
tar -tf filename.tar.gzNetworking
Check which ports are used
netstat -tulpnOn OSX:
lsof -n -i:3001 | grep LISTENkill it:
kill `lsof -n -i:3001 | grep LISTEN | tail -n1 | awk '{print $2}'`
Grep for a specific port:
netstat -tulpn | grep :80Get private IP:
curl -w "\n" http://169.254.169.254/metadata/v1/interfaces/private/0/ipv4/address
Processess
Get PIDs:
ps -aux | grep nameor
pgrep nameVim
You should also know you way around Vim. Good not just for editing, but also viewing long log files for example.
"*y"to copy into system clipboard:%!python -m json.toolto format JSON:e!to reload current file back in:tabedit .to open a new tab:set pasteto turn off autoindent when pasting,:set nopasteto go back to normal$to go to end of lineGto go end of file,42Gto go line 42:set scrollbindin each pane to bind scrolling, or:windo set scrollbindto do it for every open pane at once:read !echo $PATHto read the output of a command into the current position/canBeRegexto search;set hlsearchto have results highlighted,:nohto turn off highlighting until next searchvim +PluginInstall +qallto install vundle plugins from outside vimza,zcto open/close folds- with vim-foldsearch
:Fwto show lines which contain word under cursor. use case: show all lines withoin.objfile:Fsto fold lines with match last search. use case: search for/^[og]to find all object and group declarations, then fold to see them