linux 部分常用技巧
来源:互联网 发布:交互式动画制作软件 编辑:程序博客网 时间:2024/06/03 10:07
Linux 技巧
- 后台运行程序 &
- 打包压缩: tar
- -c 归档文件
- -x 压缩文件
- -z gzip压缩文件
- -v 显示压缩或者解压缩的过程
- -f 使用文档名
- expamle: tar -cvf /home/abc.tar /home/abc 只打包,不压缩
- tar -zcvf /home/abc.tar.gz /home/abc 打包,并用gzip压缩
- 当然,如果想解压缩,就直接替换上面的命令 tar -cvf / tar -zcvf / tar -jcvf 中的“c” 换成“x” 就可以了
- 查看所有进程端口使用情况 netstat -apn
- 查看端口情况 lsof -i[:port]
- 查看某一个命令的详情 man
- 查看进程信息 ps -aux
- a all显示其他用户信息
- u 启动这个进程的用户和它启动的时间
- x 查看系统中属于自己的进程
- 查看某个进程的信息(linux环境下)
ps -aux|grep [info]
info是关键字 - git grep 在当前工作目录(Tree)中, 查找相关的东西
杀死某个进程 kill
- kill -9(SIGKILL) [pid]
secure Copy scp命令:
- 从本地到远程: scp foobar.txt your_username@remotehost.edu:/some/remote/directory
- 从本地到远程: scp -r foo your_username@remotehost.edu:/some/remote/directory/bar -r 表示文件夹
- 从远程到本地: scp your_username@remotehost.edu:foobar.txt /some/local/directory
给可执行文件(sh)添加权限: chmod 777 *.sh
- chmod adc file a,b,c表示三者用户的权限
- a :User
- b :Group
- c :Other
>
-rw——- (600) – 只有属主有读写权限。
-rw-r–r– (644) – 只有属主有读写权限;而属组用户和其他用户只有读权限。
-rwx—— (700) – 只有属主有读、写、执行权限。
-rwxr-xr-x (755) – 属主有读、写、执行权限;而属组用户和其他用户只有读、执行权限。
-rwx–x–x (711) – 属主有读、写、执行权限;而属组用户和其他用户只有执行权限。
-rw-rw-rw- (666) – 所有用户都有文件读、写权限。这种做法不可取。
-rwxrwxrwx (777) – 所有用户都有读、写、执行权限。更不可取的做法。
以下是对目录的两个普通设定:
drwx—— (700) - 只有属主可在目录中读、写。
drwxr-xr-x (755) - 所有用户可读该目录,但只有属主才能改变目录中的内容。
如下是权限图
- 制作可执行文件bin的软连接 ln -s [可执行文件路径]
- 查看某一个端口的情况 netstat -an|grep 8091
- 显示内存使用情况: free -h
- uptime为显示当前系统的平均负载,
17:29 up 18 days, 27 mins, 5 users, load averages: 2.37 2.26 2.15
最近 - 统计文件中的字数,字节数,行数: wc (-c -l -w)
- 监控linux上面的相关进程
- dstat:多功能网络系统资源统计工具
- systemctl: 系统服务管理器指令
- systemctl start [server-name]:启动某服务
- systemctl stop [server-name]:停止某服务
- netstat 显示网络状况
- find :查找某个文件的命令
find .
查看当前目录下的所有文件find /home -name "*.txt"
查看/home目录下所有.txt的文件find . \( -name "*.txt" -o -name "*.pdf" \)
查找当前路径下面所有以.txt
.pdf
结尾的文件find . -name "*.py"|wc -l
查看当前目录下所有的py
文件find . -not \( -path './$(VENV)' -prune \) -name '*.pyc' -exec rm -f {} \;
清除python项目中pyc文件, find命令中括号使用了转义, 用来组织多个条件find . \( -name "*.py" \)| xargs wc -l
统计当前文件中所有的代码行数
tmux
- tmux ls 列出tmux服务
- tmux attach -t index 挂载某个tmux服务
- prefix key :ctrl+B (简称pk)
- 创建一个窗口 pk+C
- 关闭一个窗口 pk+&
- 窗口直接的切换: pk+index (index为窗口的序号)
- 关闭删除某个session: tmux kill-session -t 会话名
- 关闭当前session,但是在后台运行 :pk+D
- 重命名一个session: tmux rename-session -t [index] [name]
- 重命名一个window: tmux rename-window -t [old-window] [name]
- 创建一个tmux session: tmux new -s
vim
- 翻到下一页: ctrl+f
- 翻到上一页: ctrl+b
- Esc: vsp [filepath]垂直分屏打开一个文件
- yy 复制一行 nyy复制当前光标之后的n行 p粘贴
- 显示行号: set number
- 不显示行号: set nonu
- 切换到右边的屏: ctrl+w l
- 切换到左边的屏: ctrl+w h
- vim +PluginInstall +qall 安装插件
- ESC: U 撤销
- CTRL+R 反撤销
- ESC: b上一个单词,e下一个单词
docker
- docker ps:查看docker中的进程
git
git checkout
切换分支git commit -a
提交更新git push origin [branch-name]
提交更新到远程分支git fetch orgin
获取所有远程分支的更新git branch --track <new><remote>
用来第一次创建本地分支提交代码git rebase -i
在本地进行commit的合并 i 之后加相应的参数可以进行到某个时间点合并- 可以通过
git reset 和 git checkout
来修改代码文件的工作区域 git fetch origin, git merge origin/another-branch
用来在更新本地分支(合并远程分支)git fetch origin, git rebase origin/another-branch
功能同上- 当更新本地分支出现:
First, rewinding head to replay your work on top of it...
,并且要强制更新本地分支则git fetch origin, git reset --hard origin/<branch>
- 当本地分支更新完成之后, 需要手动
git push origin/<branch>
更新跟踪的远程分支 git branch branch_name --set-upstream-to origin/branch_name
git 切换跟踪的远程分支- 当提交
merge request
时,出现了冲突则git fetch
git rebase origin/<branch>
来解决冲突 git diff
用来查看当前改变和HEAD的区别,git diff HEAD^ HEAD
查看上一次提交和当前HEAD的区别,git diff a b
, a 早期提交, b后来提交- 添加
.gitignore
文件echo '.idea' >> .gitignore, git rm -r --cached .idea, git add .gitignore
git config --local
配置当前项目的配置,git config --global
配置全局配置
g++
reference:
.a
文件编译期静态链接, 在编译器静态链接到项目中, 是项目工程的一部分.so
文件运行期动态连接到项目中去,如果对.so
文件有一定的改动不需要重新编译项目工程文件- C标准库,C++STL都是
.so
gcc -Wall -fPIC -c *.c
gcc -shared -Wl,-soname,libctest.so.1 -o libctest.so.1.0 *.o
TCPdump
- tcpdump 运行启动linux下的抓包工具
阅读全文
0 0
- linux 部分常用技巧
- Javascript部分常用技巧
- linux部分使用技巧
- Html的部分常用技巧
- linux常用部分命令
- Linux常用技巧之一
- LINUX常用技巧
- Linux Vi常用技巧
- linux常用技巧
- Linux Shell常用技巧
- Linux 常用技巧
- linux SHELL常用技巧
- Linux Shell常用技巧
- Linux Shell常用技巧
- Linux 常用技巧
- Linux Shell常用技巧
- linux常用技巧总结
- Linux Shell常用技巧
- 路由的优化
- java >; 转义成 >
- bzoj 4033(树形dp)(背包dp)
- 深入理解Java之线程池
- 下拉刷新上拉加载更多
- linux 部分常用技巧
- java方法练习
- 【BZOJ3997】【TJOI2015】组合数学
- LintCode 字符串置换 python
- ARKit-带你走进全新的世界(一:初探)
- bzoj 1112 treap
- leetcode之surrounded-regions
- 当今社会到底更需要专才还是通才
- POJ3617 Best Cow Line(贪心,字典序最小)