Commands that I want to write down because I'm always looking them up anyways
^a
beginning of line^e
end of line^k
delete everything to the right^w
delete previous word^r
interactive search; start typing to lookup previous commands.enter
to execute,^g
to abandonESC-b
go back one wordESC-f
go forward one word!!
previous command!$
last argument from previous command.!:0
,!:1
, to index arguments^from^to
replace first occurrence of from with tohistory
displays all previous commands. Follow with!999
, where 999 is the index of a history item to execute again. Or, try!ma
, which would execute the closest command which begins with 'ma'- press
esc
followed byctrl+e
to expand the command but not execute it (SF)
- press
cd -
go to previous directorypushd
,popd
cd to directory and push it onto a stack; usepopd
to revist the stack of directoriesstrace
to view messages from a particular process id. Useful iftop
is displaying exepensive processes that you want to debug.sudo strace -p PID
- presentation using this to debug ruby apps
- see free memory
watch -n 5 free -m
- git pull and overwrite
git reset --hard HEAD; git pull
- delete but leave on file system
git rm --cached test.txt
- delete a remote branch
git push origin :branch_name
- resolve conflicts all me or all them
git checkout --ours index.html
git checkout --theirs index.html
- checkout a remote branch
git checkout -b new_branch origin/new_branch
- pull and merge all changes with the remote copy (SO)
git pull -s recursive -X theirs
- view history and then rollback to an older commit
git log
git reset --hard SHA1_HASH
- Add remote
git remote add origin [email protected]:patrickmoberg/pyagg.git
- Checkout a specific commit on a new branch
git checkout -b aNewBranch SHA1
(SHA1 = commit id)
- Checkout a file from a different branch
git checkout <branch_you_want_to_merge_from> <file_paths...>
- Update list of branches
git fetch
- pull a specific commit from another branch
git cherry-pick <commit-hash>
- checkout and track a remote branch
git checkout -b local-name origin/remote-name
- Reset a file to a specific commit
git checkout sha1hash file/to/restore
- Show commits in one branch and not another (SO)
git log --graph --left-right --cherry-pick --oneline master...experiment
- show all commits in any branch (--all) that introduced or removed a string from a file
git log --all -Sdomain_safe_username app/models/user.rb
- undo last commit (see here)[https://stackoverflow.com/questions/927358/git-undo-last-commit]
git reset --soft HEAD^
# then perform your editsgit add -A
# add your editsgit commit -c ORIG_HEAD
# commit them back
- search commits
git log --grep=foobar --since=1.month
- retrieve a deleted file SO
git rev-list -n 1 HEAD -- <file_path>
# the last commit which affected it (therefore the deleting commit)git checkout <deleting_commit>^ -- <file_path>
# checkout the previous commit
- rebase pushed commits (assuming no one else has pulled them SO
git rebase -i
and thengit push origin +<branch>
(orgit push --force origin <branch>
)
- Show logs on that aren't in HEAD
git log ..<branchname>
- Short status
git status --short
- Search for merge conflict markers (not git I know, but useful)
grep -r'<<<<' *
- Search for a line of text
git log -s'.round_border'
- view contents of git stash
git stash show -p stash@{0}
- create a tag
git tag -a v2 -m "p2 submission"
git push origin master --tags
push tags
- ignore chmod changes
git config core.filemode false
- Find and replace.
git grep -l 'original_text' | xargs sed -i '' -e 's/original_text/new_text/g'
.
- download from remote server
scp [email protected]:/home/play/backup/current/mysql-dump.gz mysql-dump.gz
- push to remote server
scp ~/Desktop/bnter_2011_10_19.sql [email protected]:~
- bulk rename examples (sed tutorial)
for f in fgh*; do mv $f $(echo $f | sed 's/fgh/jkl/g'); done
for f in *; do mv $f $(echo $f | sed 's/2/1/g'); done
for f in *; do mv $f $(echo $f | sed 's/hair/girlhair/g'); done
for f in *; do mv $f $(echo $f | sed 's/male/female/g'); done
for f in *; do mv $f $(echo $f | sed 's/female_\(.*\)_/&_female_/g'); done
- tail a log for a specific result, showing 5 lines before and after it
tail -f log/production.log | grep -5 "likes"
grep -A 5 "likes"
# just the 5 lines after the matchgrep -B 5 "likes"
# just the 5 lines before the match
- sed modify in place
sed -i '' -e "s/\(line\)/#\1/g" file.txt
- tar and gzip directory
tar -cvzf p1.tar.gz p1/*.jpeg
- gzip to a new file
gzip --stdout textfile > /path/to/spacious/filesystem/textfile.gz
- unzip a .zip file
unzip file.zip -d destination_folder
- grep for a string in a dir
grep -nr string my_directory
- grep again?
grep -r -i somethingtosearchfor
- run a script against a DB
mysql -u root -pPASSWORD -h localhost bnter_latest < ~/Desktop/bnter_staging.sql
- shut it down
mysqladmin -u root -pPASSWORD shutdown
- dump a table to file
mysqldump -c -u root -pPASSWORD database table > ~/Desktop/dump.sql
- write a query result to a file
mysql -e "select * from myTable" -u myuser -pxxxxxxxxx mydatabase > mydumpfile.txt
- dump database ignoring some tables
mysqldump -c -u root -pPASS --database bnter_latest --ignore-table=bnter_latest.filedata --ignore-table=bnter_latest.files > ~/Desktop/bnter.sql
- put logs to table (will reset on server restart)
SET GLOBAL general_log = 'ON'; SET GLOBAL log_output = 'TABLE'; SELECT * FROM mysql.general_log ORDER BY event_time DESC;
- change encoding
- mysqldump -u root -p --opt --default-character-set=latin1 --skip-set-charset DBNAME > DBNAME.sql
- mysql -u root -p --default-character-set=utf8 DBNAME < DBNAME.sql
- see SO post
- create a user and grant them privileges
CREATE USER 'monty'@'localhost' IDENTIFIED BY 'some_pass';
GRANT ALL PRIVILEGES ON *.* TO 'monty'@'localhost';
- Get size of all databases in MB
SELECT table_schema "Data Base Name",
sum( data_length + index_length ) / 1024 / 1024 "Data Base Size in MB"
FROM information_schema.TABLES
GROUP BY table_schema;
- find and kill a query
show processlist
kill <pid>
- drop an index
DROP INDEX index_name ON tbl_name
- dump just structure
mysqldump -d database01 > dumpfile.sql
- dump by where statement
mysqldump --databases X --tables Y --where="1 limit 1000000"
- flush DNS cache
dscacheutil -flushcache
- top CPU consumers
top -o cpu -stats command,cpu,threads -n 20
- Compile a directory tree of .coffee files into a parallel tree of .js, in lib:
coffee -o lib/ -c src/
- Watch a file for changes, and recompile it every time the file is saved:
coffee --watch --compile experimental.coffee
- Combine the previous 2
coffee --watch -o coffee_js/ -c coffee/
- Concatenate a list of files into a single script:
coffee --join project.js --compile src/*.coffee
- post requst
curl -d "param1=value1¶m2=value2" https://example.com/resource.cgi
- download a file
curl https://github.com/goggin13/dotfiles/blob/master/colorssh.sh -o ~/colorssh.sh
- debug transfer times
curl https://banters.com/?session_id=YOUR_SESSION_ID -w 'curl times [s]:\n\ttime_starttransfer: %{time_starttransfer}\n\ttime_redirect: %{time_redirect}\n\ttime_pretransfer: %{time_pretransfer}\n\ttime_connect: %{time_connect}\n\ttime_namelookup: %{time_namelookup}\n\ttime_appconnect: %{time_appconnect}\n\ttime_total: %{time_total}' -i
- Make and run a jar file
javac *.java
-- compilejar cfm PopulateS3ImagesJob.jar manifest.txt PopulateS3ImagesJob.class
--jarify- manifest.txt contains at least 'Main-Class: PopulateS3ImagesJob'
java -jar PopulateS3ImagesJob.jar
-- run it
echo stats | nc 127.0.0.1 11211
- Edit conf file
sudo su - postgres
sudo vi /Library/PostgresPlus/<version>SS/data/pg_hba.conf
- rows older than...
DELETE FROM radacct WHERE acctstoptime < (now() - '30 days'::interval);
- show tables
SELECT * FROM pg_catalog.pg_tables
- list databases
\list
- global search and replace
:%s/search_string/replacement_string/g
- start
/etc/init.d/haproxy start
- push pull local and remote database
heroku db:pull
heroku db:push
- rails new myapp --skip-bundle --database=postgresql --skip-test-unit --skip-index-html
mkdir ~/bin; cd ~/bin
git clone [email protected]:goggin13/dotfiles.git
- in ~/.bashrc
. ~/bin/dotfiles/bashrc
- in ~/.bash_profile
if [ -f ~/.bashrc ]; then . ~/.bashrc fi
ln -s ~/bin/dotfiles/ssh/config ~/.ssh/config