Skip to content

Instantly share code, notes, and snippets.

@bytemain
Last active January 2, 2021 11:38
Show Gist options
  • Save bytemain/81eb4367b8bffd2977edb014fbcaccd6 to your computer and use it in GitHub Desktop.
Save bytemain/81eb4367b8bffd2977edb014fbcaccd6 to your computer and use it in GitHub Desktop.
cheat
cat /etc/passwd |awk -F ':' '{print $1}'
通过 awk 命令我们可以筛选出符合要求的行或者列数据
以:为分隔符,将 password 分为多列,并且提取出第一列的内容
---
$(awk '/Host github.com/{print NR}' ~/.ssh/config)
查找内容出现在第几行
% crontab, scheduling
# List cron jobs
crontab -l
# Edit cron job
crontab -e
# set a shell
SHELL=/bin/bash
# crontab format
* * * * * command_to_execute
- - - - -
| | | | |
| | | | +- day of week (0 - 7) (where sunday is 0 and 7)
| | | +--- month (1 - 12)
| | +----- day (1 - 31)
| +------- hour (0 - 23)
+--------- minute (0 - 59)
# example entries
# every 15 min
*/15 * * * * /home/user/command.sh
# every midnight
0 0 * * * /home/user/command.sh
# every Saturday at 8:05 AM
5 8 * * 6 /home/user/command.sh
---
tags: [ vcs ]
---
# To set your identity:
git config --global user.name <name>
git config --global user.email <email>
# To set your editor:
git config --global core.editor <editor>
# To enable color:
git config --global color.ui true
# To stage all changes for commit:
git add --all
# To stash changes locally, this will keep the changes in a separate changelist
# called stash and the working directory is cleaned. You can apply changes
# from the stash anytime
git stash
# To stash changes with a message
git stash save <message>
# To list all the stashed changes
git stash list
# To apply the most recent change and remove the stash from the stash list
git stash pop
# To apply any stash from the list of stashes. This does not remove the stash
# from the stash list
git stash apply stash@{6}
# To commit staged changes
git commit -m <message>
# To edit previous commit message
git commit --amend
# Git commit in the past
git commit --date="`date --date='2 day ago'`"
git commit --date="Jun 13 18:30:25 IST 2015"
# more recent versions of Git also support --date="2 days ago" directly
# To change the date of an existing commit
git filter-branch --env-filter \
'if [ $GIT_COMMIT = 119f9ecf58069b265ab22f1f97d2b648faf932e0 ]
then
export GIT_AUTHOR_DATE="Fri Jan 2 21:38:53 2009 -0800"
export GIT_COMMITTER_DATE="Sat May 19 01:01:01 2007 -0700"
fi'
# To removed staged and working directory changes
git reset --hard
# To go 2 commits back
git reset --hard HEAD~2
# To remove untracked files
git clean -f -d
# To remove untracked and ignored files
git clean -f -d -x
# To push to the tracked master branch:
git push origin master
# To push to a specified repository:
git push [email protected]:<username>/<repo>.git
# To delete the branch "branch_name"
git branch -D <branch>
# To make an exisiting branch track a remote branch
git branch -u upstream/foo
# To see who commited which line in a file
git blame <file>
# To sync a fork with the master repo:
git remote add upstream [email protected]:<username>/<repo>.git # Set a new repo
git remote -v # Confirm new remote repo
git fetch upstream # Get branches
git branch -va # List local - remote branches
git checkout master # Checkout local master branch
git checkout -b new_branch # Create and checkout a new branch
git merge upstream/master # Merge remote into local repo
git show 83fb499 # Show what a commit did.
git show 83fb499:path/fo/file.ext # Shows the file as it appeared at 83fb499.
git diff branch_1 branch_2 # Check difference between branches
git log # Show all the commits
git status # Show the changes from last commit
# Commit history of a set of files
git log --pretty=email --patch-with-stat --reverse --full-index -- Admin\*.py > Sripts.patch
# Import commits from another repo
git --git-dir=../some_other_repo/.git format-patch -k -1 --stdout <commit SHA> | git am -3 -k
# View commits that will be pushed
git log @{u}..
# View changes that are new on a feature branch
git log -p feature --not master
git diff master...feature
# Interactive rebase for the last 7 commits
git rebase -i @~7
# Diff files WITHOUT considering them a part of git
# This can be used to diff files that are not in a git repo!
git diff --no-index path/to/file/A path/to/file/B
# To pull changes while overwriting any local commits
git fetch --all
git reset --hard origin/master
# Update all your submodules
git submodule update --init --recursive
# Perform a shallow clone to only get latest commits
# (helps save data when cloning large repos)
git clone --depth 1 <remote-url>
# To unshallow a clone
git pull --unshallow
# Create a bare branch (one that has no commits on it)
git checkout --orphan branch_name
# Checkout a new branch from a different starting point
git checkout -b master upstream/master
# Remove all stale branches (ones that have been deleted on remote)
# So if you have a lot of useless branches, delete them on Github and then run this
git remote prune origin
# The following can be used to prune all remotes at once
git remote prune $(git remote | tr '\n' ' ')
# Revisions can also be identified with :/text
# So, this will show the first commit that has "cool" in their message body
git show :/cool
# Undo parts of last commit in a specific file
git checkout -p HEAD^ -- /path/to/file
# Revert a commit and keep the history of the reverted change as a separate revert commit
git revert <commit SHA>
# Pich a commit from a branch to current branch. This is different than merge as
# this just applies a single commit from a branch to current branch
git cherry-pick <commit SHA1>
netstat –anp | grep 8080
lsof -i tcp:8080 | grep LISTEN | awk '{print $2}'| awk -F"/" '{ print $1 }' | xargs kill -9
lsof -i:端口号
register as service
```
pg_ctl register -N PostgreSQL
```
ps -aux | grep java
# 以内存使用量排序,显示出消耗内存最多的10个运行中的进程
ps aux | sort -nk +4 | tail
sudo sed -i 's|http://archive.ubuntu.com|https://mirrors.tuna.tsinghua.edu.cn|g' /etc/apt/sources.list
# To replace all occurrences of "day" with "night" and write to stdout:
sed 's/day/night/g' <file>
# To replace all occurrences of "day" with "night" within <file>:
sed -i 's/day/night/g' <file>
# To replace all occurrences of "day" with "night" on stdin:
echo 'It is daytime' | sed 's/day/night/g'
# To remove leading spaces:
sed -i -r 's/^\s+//g' <file>
# To remove empty lines and print results to stdout:
sed '/^$/d' <file>
# To replace newlines in multiple lines:
sed ':a;N;$!ba;s/\n//g' <file>
# To insert a line before a matching pattern:
sed '/Once upon a time/i\Chapter 1'
# To add a line after a matching pattern:
sed '/happily ever after/a\The end.'
# To extract an uncompressed archive:
tar -xvf /path/to/foo.tar
# To create an uncompressed archive:
tar -cvf /path/to/foo.tar /path/to/foo/
# To extract a .gz archive:
tar -xzvf /path/to/foo.tgz
# To create a .gz archive:
tar -czvf /path/to/foo.tgz /path/to/foo/
# To list the content of an .gz archive:
tar -ztvf /path/to/foo.tgz
# To extract a .bz2 archive:
tar -xjvf /path/to/foo.tgz
# To create a .bz2 archive:
tar -cjvf /path/to/foo.tgz /path/to/foo/
# To extract a .tar in specified Directory:
tar -xvf /path/to/foo.tar -C /path/to/destination/
# To list the content of an .bz2 archive:
tar -jtvf /path/to/foo.tgz
# To create a .gz archive and exclude all jpg,gif,... from the tgz
tar czvf /path/to/foo.tgz --exclude=\*.{jpg,gif,png,wmv,flv,tar.gz,zip} /path/to/foo/
# To use parallel (multi-threaded) implementation of compression algorithms:
tar -z ... -> tar -Ipigz ...
tar -j ... -> tar -Ipbzip2 ...
tar -J ... -> tar -Ipixz ...
tmpwatch [参数] [过期时间] [指定目录]
tmpwatch 24 /tmp/
#删除/tmp目录下超过24小时未使用的文件,最小为1小时。
tmpwatch --test 3 /tmp/
#测试删除/tmp目录中超过3小时未使用的文件
tmpwatch -afv 24 /tmp/
#删除/tmp目录中超过一天未使用的文件
tmpwatch -afv 3 /tmp/
#删除/tmp目录中超过3小时未使用的文件
# install
yay -S packname
# remove
yay -P packname
# search
pacman -Ss abc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment