Skip to content

Instantly share code, notes, and snippets.

@duobei
Forked from flaneur2020/shell_tips.md
Created November 21, 2012 08:34
Show Gist options
  • Save duobei/4123817 to your computer and use it in GitHub Desktop.
Save duobei/4123817 to your computer and use it in GitHub Desktop.
shell tips
  • gcc -M hello.c 可以得到某文件依赖的头文件。

  • grep processor /proc/cpu_info 显示当前的CPU数目

  • sudo shutdown -r now 重启机器

  • sshfs yourname@host:/path/to/your/dir ~/local sshfs挂载到本地

  • sudo -u fleuria bash: 切换用户

  • xxxdump | vim -: 将stdout的输出重定向给vim

后台任务

  • 后台进程并不等于它是长期执行的进程,在用户注销时,可能照样会收到sighup。

    解决方法是使用tmux或者nohup

  • 列出后台任务:jobs

crontab

crontab并没有直接向用户暴露配置文件的位置,是因为crontab这种比较敏感的脚本,是不能容忍语法错误的。crontab -e保存之后,就相当于经过了一层语法检验。编辑crontab:

crontab -e

格式:minute hour day_in_month month day_in_week program

比如:

  • 每天凌晨1点执行:0 1 * * * blah

svn

svn提供了比git更为精细的权限控制,按照目录为单位。

  • checkout: svn co http://svn.miaomiao.com/svn/trunk -r HEAD
  • 创建自己的分支目录:svn mkdir http://svn.foo.com/svn/branches/fleuria
  • 创建特性分支:svn cp http://svn.foo.com/svn/trunk http://svn.foo.com/svn/branches/fleuria/issue1
  • 切换分支:svn switch http://svn.foo.com/svn/branches/fleuria/issue1
  • 不像git有暂存区,svn在提交时只能将需要提交的文件列在命令里: svn commit -m 'commit message' file1.c file2.c
  • 撤销当前的所有更改: svn revert -R .
  • merge需要先得到revision的范围: svn log /branches/feature_233 --stop-on-copy; svn merge /branches/feature_233 -r 999:1000
  • 获取分支的第一个revision: svn log -v --stop-on-copy
  • 当前修改: svn st -q
  • revert当前的所有修改: svn revert `svn st -q`
  • merge合并过trunk的分支时记得加上: --reintergrate

Troubleshoots:

Working copy locked

cd .svn; rm lock

svn: E160013: '/svn/shire/!svn/bc/135926/branches/miaomia/meow' path not found

先检查下哪里拼错了。

git-svn

建svn分支:

git svn branch foo
git checkout -b foo -t remotes/foo
git commit
git svn dcommit
  • Q: Could not unmemoize function `lookup_svn_merge', because it was not memoized to begin with at /usr/local/Cellar/git/1.7.6/libexec/git-core/git-svn line 3226

    A: rm -rf .git/svn/.caches

  • Q: Multiple branch paths defined for Subversion repository. You must specify where you want to create the branch with the --destination argument.

    A: 修改.git/config,添加: branches = branches/liyazhou/*:refs/remotes/*[svn-remote "svn"]下。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment