基本命令
查看文件
ls
-F
-a
-R
-l
*_script
cat test_file
-n
创建文件
touch test_file
mkdir new_dir
-p new_dir/sub_dir/last_dir
复制文件
cp src_file new_file
cp src_file /home/document/
cp -R scripts/ new_dir
链接文件
ln -s src_file short_cut_file
ln src_file short_cut_file
移动文件
mv old_name new_name
mv src_file /home/document/
删除文件
rm -i file
-r dir
-f
-rf
rmdir dir
bash shell命令
进程
ps -ef
top
kill -9 pid
磁盘
df -h
排序
sort file
-n file
-M file
搜索
grep [options] pattern [file]
hello my_code
压缩
gzip my_dir
gunzip my_dir
tar -zcvf my_dir.tar.gz sub_dir1/ sub_dir2/
tar -zxvf my_dir.tar.gz
环境变量
加载顺序
-
系统启动会首先加载/etc/profile文件,它遍历执行了/etc/profile.d目录下所有文件
-
之后会按以下顺序,运行第一个被找到的文件,余下的被忽略
/etc/profile
=> $HOME/.bash_profile
=> ($HOME/.bashrc)
=> $HOME/.bash_login
=> $HOME/.profile
其中,.bash_profile文件内会检查是否存在$HOME/.bashrc文件,存在则执行
查看
env
echo $HOME
自定义变量
my_variable=Hello
export my_variable
正确方式:在/etc/profile.d目录中创建.sh文件,在其中编辑自定义变量
删除
unset my_variable
给PATH中添加值
PATH=$PATH:/home/codfish/bin
export PATH
权限
查看
cat /etc/passwd
codfish:x:1000:1000:,,,:/home/codfish:/bin/bash
cat /etc/group
codfish:x:1000:
添加
useradd
-m codfish2
-D
groupadd
删除
userdel
-r codfish2
修改
usermod
groupmod
修改文件权限
chmod
760 my_file
chown
codfish:codfish my_file
分配普通用户权限
- sudo 免密
sed -i 'codfish ALL=(ALL) NOPASSWD: ALL' /etc/sudoers
- 资源目录操作权限
chown -R codfish:codfish /opt/codfish-softwares
SSH免密登录
A服务器免密登录到B服务器
ssh-keygen -t rsa -f ~/.ssh/id_rsa -C "一些备注信息"
cat ~/.ssh/id_rsa.pub
ssh-copy-id -i ~/.ssh/id_rsa.pub -p 22 root@192.168.2.100
ssh root@192.168.2.100
安装软件
Debian系列(Ubuntu)
sudo apt-get install package_name
Red Hat系列(CentOS)
sudo yum install package_name
更多操作使用命令手册查看
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)