tmux
sed (Stream Editor)
sed s/-/\ /g
substitute globally (- to spaces in this case)
users and groups
- list all users:
cut -d: -f1 /etc/passwd
ORcompgen -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 status
is going to say, (which is never 100%), you should rungit status
before committing.
- Don't use the desktop gui: if you can
git checkout -b branchName origin/branchName
to fetch remote branchgit push origin --delete branchName
to 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-pages
branch indist
folder)git checkout HEAD -- my-file.txt
to hard reset a specific filegit reset --hard
to 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 reset
to go back to last commit. leaves files modified and new files. i.e.git status
will show the same as it did just beforegit commit
git reset --hard
to simulate arm project
,git clone project
, but it might keep your new files?git reset --soft
to 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 --tags
to 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 -h
to get disk usagesudo du -sh ./*
to see how much space each file/file in cwd is usingsudo du -sh ./* | gsort -rh
to sort by size.sort
on linux.brew install coreutils
on 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.gz
Networking
Check which ports are used
netstat -tulpn
On OSX:
lsof -n -i:3001 | grep LISTEN
kill it:
kill `lsof -n -i:3001 | grep LISTEN | tail -n1 | awk '{print $2}'`
Grep for a specific port:
netstat -tulpn | grep :80
Get private IP:
curl -w "\n" http://169.254.169.254/metadata/v1/interfaces/private/0/ipv4/address
Processess
Get PIDs:
ps -aux | grep name
or
pgrep name
Vim
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.tool
to format JSON:e!
to reload current file back in:tabedit .
to open a new tab:set paste
to turn off autoindent when pasting,:set nopaste
to go back to normal$
to go to end of lineG
to go end of file,42G
to go line 42:set scrollbind
in each pane to bind scrolling, or:windo set scrollbind
to do it for every open pane at once:read !echo $PATH
to read the output of a command into the current position/canBeRegex
to search;set hlsearch
to have results highlighted,:noh
to turn off highlighting until next searchvim +PluginInstall +qall
to install vundle plugins from outside vimza
,zc
to open/close folds- with vim-foldsearch
:Fw
to show lines which contain word under cursor. use case: show all lines witho
in.obj
file:Fs
to fold lines with match last search. use case: search for/^[og]
to find all object and group declarations, then fold to see them