Linux 技巧
Linux Handbook
For RedHat Enterprise Linux
System
System
# clean old kernel packages
package-cleanup --oldkernels --count=1
# get boot method
systemctl get-default
# set boot level to command lines
systemctl set-default multi-user.target
# set boot level to GUI
systemctl set-default graphical.target
- install/uninstall
# list groups of package
yum group list
# list packages of a group
yum group info "Minimal Install"
yum group info "core"
# install packages
sudo yum install <package name>
Services
# check service status
systemctl status docker
# configure a service start on boot
systemctl enable docker
# start a service
systemctl start docker
systemctl restart docker
systemctl stop docker
Storage
Linux Storage:
Physical Disks:/dev/sda, /dev/sdb, etc
Physical Volumes: /dev/sda1, /dev/sda2, etc,也可以是/dev/sdb
Logical Volume Groups: rehl, centos
Logical Volumes: /dev/rehl/root
File System: xfs
# enlarge disk size for rehl
# check disk size
df -lh
# list physical disks. If there is no /dev/sdb, try reboot.
fdisk -l | grep "Disk /"
# find volume group name
vgdisplay | grep "VG Name"
# find physical volume name
pvdisplay | grep "PV Name"
# extend a physical volume to a logical volume group
vgextend rhel /dev/sdb
# add spaces to a logical volume
lvextend -l +100%FREE /dev/rhel/root
# XFS file system
xfs_growfs /dev/rhel/root
# check disk size
df -lh
# ----- enlarge disk size for centos -------
df -lh
fdisk -l | grep "Disk /"
vgdisplay | grep Name
pvdisplay | grep Name
vgextend centos /dev/sdb
lvextend -l +100%FREE /dev/centos/root
xfs_growfs /dev/centos/root
df -lh
# ----- physical disk partitions --------
# list disk partitions
fdisk -l
# ----- LVM : logical volume management --------
# active volume group
lvm vgchange -ay
# ----- LVM : merge /home to / --------
# copy /home
mkdir backup
mv /home/* ./backup
# umount /home
umount /home
# remove volume /home
lvremove /dev/centos/home
# extend root size
lvextend -l +100%FREE /dev/centos/root
# get the configuration work
xfs_growfs /dev/centos/root
# clear backup folder
rm -rf ./backup
FTP
wget -r -nH --cut-dirs=3 ftp://username:password@ftp_hostname//dir1/dir2
# Install FTP
yum install ftp
# FTP commands
# connect to a server
ftp IP/hostname
# Or
ftp
ftp> open IP/hostname
# transfer mode. Use binary mode in most cases.
ftp> binary
ftp> ascii
# get: download a specific file
# mget: download multiple files
# put|mput
# cd|pwd: directory operations on FTP server
# lcd: change local direcoty
# close: close connection
# quit: quit ftp
Zip
# install 32bit zip package
sudo yum -y install bzip2-libs*686
# zip
zip -u package.zip file1 file2
Locale
# show system locale
locale
# show system support locale
locale -a
# using utf-8 as system locale
# export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8
# support Asia fonts
sudo yum groupinstall Fonts
# list installed fonts
fc-list
Network
# check network status
/sbin/service network status
# check ip address
ip address
# check the listening ports and applications on Linux
sudo lsof -i -P -n | grep LISTEN
sudo netstat -tulpn | grep LISTEN
sudo nmap -sTU -O IP-address-Here
工具
Docker
- Install docker
# create docker group
grep "^docker" /etc/group
if [ $? -ne 0 ]; then
/usr/sbin/groupadd docker
fi
id root | grep docker
if [ $? -ne 0 ];then
/usr/sbin/usermod -a -G docker root
/usr/sbin/usermod -g docker root
fi
# install docker
curl -fsSL https://get.docker.com/ | sh
# support HTTP response via HTTPS
tee /etc/docker/daemon.json <<-EOF
{
"insecure-registries": ["<private host name>:5000"]
}
EOF
# check docker version
docker --version
# restart docker
systemctl stop docker
systemctl daemon-reload
systemctl start docker
# install docker-compose, make sure the path is in the /usr/local/sbin PATH variable
curl -L "https://github.com/docker/compose/releases/download/1.22.0/docker-compose-`uname -s`-`uname -m`" > /usr/local/sbin/docker-compose
chmod +x /usr/local/sbin/docker-compose
# check docker-compose version
docker-compose --version
- docker commands
# restart docker services
sudo systemctl stop docker
sudo systemctl daemon-reload
sudo systemctl start docker
# start docker, need to wait few minutes
sudo systemctl restart docker
docker-compose start
# stop docker
docker-compose stop
# stop and clear changes
docker-compose down
docker system prune -f
# start with images
docker-compose up -d
# Re-Install
## cd <compose configure path>
docker-compose down
docker system prune -f
# docker rm -fv $(docker ps -qa)
docker rmi $(docker images -q)
docker-compose pull
docker-compose up -d
# Login docker with root
docker exec -u 0 -it <container id> bash
# Enable docker ssh
docker exec <container id> /usr/sbin/sshd
tmux
Links
What is tmux
tmux 是一个多通道终端。
最大的好处是:
- 可以避免终端中断带来的session中断
当运行tmux时,实际上会运行一个tmux service,保持session的运行。
tmux的提出的概念是 tmux / sessions * / windows + / panes +
tmux可以管理多个sessions。
一个session有多个windows。
一个windows有多个panes。
每个pane是一个终端。
Install
sudo yum -y install tmux
tmux prefix
prefix is a key concept in tmux, it is a tmux shortcut key, default is [ctrl + b].
for example, the detach command is
tmux -detach
If you use [ctrl + b, d], also works.
configuration file
~/.tmux.conf
tmux idiot
# install tmux
sudo yum -y install tmux
# create a session here
tmux new-session -s here
# detach the session
prefix + d
# attach the session
tmux a
tmux a -t here
tmux commands
- Help
# list command
tmux list-command
# list shortcut keys
tmux list-keys
- Sessions
| command | shortcut key | meaning |
|---|---|---|
| tmux new-session -s [session name] | create an session | |
| tmux attach-session -t [session name] | attach to an (or the only) session | |
| tmux detach-session | prefix + d | detach with the current session |
| tmux list-sessions | list all sessions | |
| tmux kill-session -t [session name] | kill a session |
- Windows
| command | shortcut key | meaning |
|---|---|---|
| tmux list-windows | list all windows | |
| tmux kill-window -t [window name] | prefix + & | kill a window |
- Panes
| command | shortcut key | meaning |
|---|---|---|
| tmux split-window | prefix + % | new a horizontal pane |
| tmux split-window -v | prefix + " | new a horizontal pane |
| tmux split-window -h | prefix + % | new a vertical pane |
| tmux rotate-window | prefix + C-o | rotate panes |
| tmux select-pane -U | prefix + Up | select the up pane |
| tmux select-pane -D | prefix + Down | select the down pane |
| tmux select-pane -L | prefix + Left | select the left pane |
| tmux select-pane -R | prefix + Right | select the right pane |
| tmux resize-pane -U | prefix + A-Up | resize the up side |
| tmux resize-pane -D | prefix + A-Down | resize the down side |
| tmux resize-pane -L | prefix + A-Left | resize the left side |
| tmux resize-pane -R | prefix + A-Right | resize the right side |
| tmux list-panes | list all panes | |
| tmux kill-pane -t [pane name] | prefix + x | kill a pane |
- Save sessions
Installation with Tmux Plugin Manager (recommended)
Add plugin to the list of TPM plugins in ~/.tmux.conf:
set -g @plugin 'tmux-plugins/tmux-resurrect'
Hit prefix + I to fetch the plugin and source it. You should now be able to use the plugin.
Key bindings
prefix + Ctrl-s - save
prefix + Ctrl-r - restore
Linux 技巧的更多相关文章
- 每个极客都应该知道的Linux技巧
每个极客都应该知道的Linux技巧 2014/03/07 | 分类: IT技术 | 0 条评论 | 标签: LINUX 分享到:18 本文由 伯乐在线 - 欣仔 翻译自 TuxRadar Linux. ...
- 【转】Linux 技巧: Bash 参数和参数扩展
重点看下清单7 现在,很多 Linux® 和 UNIX® 系统上都有 bash shell,它是 Linux 上常见的默认 shell.通过本文,您将了解到如何在 bash 脚本中处理参数和选项,以及 ...
- 欢迎关注我的微信公众账号:Linux技巧(微信号:irefactoring),一起学习Linux知识~~~
最近很少写博客了,一方面是近期工作比较繁忙,第二是把精力都放在GitHub和读源码去了. 申请了一个微信公众账号:Linux技巧 微信ID:irefactoring(意思是爱重构) ========= ...
- Linux 技巧:让进程在后台可靠运行的几种方法【转】
我们经常会碰到这样的问题,用 telnet/ssh 登录了远程的 Linux 服务器,运行了一些耗时较长的任务, 结果却由于网络的不稳定导致任务中途失败.如何让命令提交后不受本地关闭终端窗口/网络断开 ...
- 这些linux技巧大大提高你的工作效率
前言 linux中的一些小技巧可以大大提高你的工作效率,本文就细数那些提高效率或者简单却有效的linux技巧. 命令编辑及光标移动 这里有很多快捷键可以帮我们修正自己的命令.接下来使用光标二字代替光标 ...
- Linux 技巧:让进程在后台运行更可靠的几种方法
Linux 技巧:让进程在后台运行更可靠的几种方法 https://www.ibm.com/developerworks/cn/linux/l-cn-nohup/index.html 我们经常会碰到这 ...
- Linux 技巧:让进程在后台可靠运行的几种方法(转)
下面举了一些例子, 您可以针对不同的场景选择不同的方式来处理这个问题. nohup/setsid/& 场景: 如果只是临时有一个命令需要长时间运行,什么方法能最简便的保证它在后台稳定运行呢? ...
- Linux 技巧:让进程在后台可靠运行的几种方法
我们经常会碰到这样的问题,用 telnet/ssh 登录了远程的 Linux 服务器,运行了一些耗时较长的任务, 结果却由于网络的不稳定导致任务中途失败.如何让命令提交后不受本地关闭终端窗口/网络断开 ...
- Linux技巧学习
主要是收集一些Linux的技巧: 1.编写可靠shell脚本的八个建议 指定bash,推荐使用 /usr/bin/env bash 和 /bin/bash,不要使用/usr/bin/bash. set ...
- 转: Linux 技巧:让进程在后台可靠运行的几种方法
我们经常会碰到这样的问题,用 telnet/ssh 登录了远程的 Linux 服务器,运行了一些耗时较长的任务, 结果却由于网络的不稳定导致任务中途失败.如何让命令提交后不受本地关闭终端窗口/网络断开 ...
随机推荐
- (1)访问控制 (2)final关键字 (3)对象创建的过程 (4)多态
1.访问控制(笔试题)1.1 常用的访问控制符 public - 公有的 protected - 保护的 啥也不写 - 默认的 private - 私有的 1.2 访问控制符的比较 访问控制符 访问权 ...
- mysql的表和约束操作
在创建表是默认为加上数据引擎和字符集,如创建一个student表,代码如下: create table students(id int unsigned zerofill auto_increment ...
- 从 s = "我爱北京天安门" 中悟道了-----------迭代器操作print(c.__next__())的最!大!好!处!-----------------------------------------------------可以一个一个输出
s = "我爱北京天安⻔"c = s.__iter__() # 获取迭代器# print(c) # 打印迭代器的地址# print(c.__next__()) # 打印迭代器中的下 ...
- SDN上机第二次作业
SDN第二次上机作业 1.安装floodlight 参考链接:http://www.sdnlab.com/19189.html 2.生成拓扑并连接控制器floodlight,利用控制器floodlig ...
- Hadoop HA on Yarn——集群配置
集群搭建 因为服务器数量有限,这里服务器开启的进程有点多: 机器名 安装软件 运行进程 hadoop001 Hadoop,Zookeeper NameNode, DFSZKFailoverContro ...
- MyEclipse10.6 myeclipse2013下添加jadClipse反编译插件 .
jad是一个使用比较广泛的Java反编译软件,jadClipse是jad在eclipse下的插件,下面像大家介绍下如何将jadclipse加入到MyEclipse10.X,9.X,8.X,6.X等各版 ...
- 25个增强iOS应用程序性能的提示和技巧 — 中级篇
本文由破船译自:raywenderlich 转载请注明出处:BeyondVincent的博客 _____________ 在开发iOS应用程序时.让程序具有良好的性能是非常关键的.这也是用户所期望的. ...
- SDWC补题计划
2018的寒假去了SD的冬令营,因为一班二班难度悬殊,对我很不友好,几乎什么也没学会,但是我把两个班的课件都存了下来,现在慢慢把两个班的例题以及课后题都补一补(毕竟冬令营的钱不能白花). 这些题目横跨 ...
- 20155314 2016-2017-2 《Java程序设计》第3周学习总结
20155314 2016-2017-2 <Java程序设计>第3周学习总结 教材学习内容总结 学习目标 区分基本类型与类类型 理解对象的生成与引用的关系 掌握String类和数组 理解封 ...
- django 模板关闭自动转义
Django的模板中会对HTML标签和JS等语法标签进行自动转义,原因显而易见,这样是为了安全.但是有的时候我们可能不希望这些HTML元素被转义,比如我们做一个内容管理系统,后台添加的文章中是经过修饰 ...