Linux常用命令

mkdir

mkdir yejiawei                                  创建文件夹

rmdir

rmdir yejiawei                                  移除目录

cd

cd yejiawei                                     进入目录

pwd

pwd                                             显示当前目录

touch

touch file1 file2 file3                         创建三个文件
touch file{1..10}.txt                           创建10个文件

ls

ls -lh                                          列出文件
ls -lhr                                         倒序列出文件               

rm

rm file1                                        移除文件
rm file2 file3                                  移除多个文件
rm *                                            移除所有文件
rm -rf yejiawei                                 移除所有文件和目录
rm -i file1                                     是否删除文件                                

chmod

read=4, write=2 and execute=1

chmod +x script.sh                              使脚本可执行
chmod 775 script.sh                             读写文件权限对所有用户开放
chmod -R 775 yejiawei                           目录和所有子文件开放
chmod u=rx file                                 给用户rx权限
chmod go-rwx file                               拒绝group rwx权限
chmod g+w file                                  给group w权限
chmod a+x file1 file2                           给所有人 execute权限

chown

chown yejiawei file1                            将file1文件owner设置成yejiawei
chown jmutai:admins file1                       将file1文件owner设置成yejiawei,组设置为admins  

chgrp

chgrp admins file1                              将file1文件的组,设置为admins
chgrp -hR admins /tmp/test                      将test目录和其子文件的组,设置为admins

tar

tar cvf archive_name.tar dirname/               归档                    
tar xvf archive_name.tar                        恢复                      
tar tvf archive_name.tar                        查看归档文件        

grep

grep -i "the" demo_file                         查找文件中的关键字

grep -r "the" *                                 在所有文件中查找关键字

find

find -iname "file2.txt"                         根据文件名查找文件

ssh

ssh -l root youripaddress                       登录ssh客户端
ssh -v -l root youripaddress                    debug ssh客户端
ssh -V                                          查看版本

vim

vim +100 file2.txt                              到file2.txt文件的100行
vim -R file2.txt                                只读模式打开文件

diff

diff -w file2.txt file3.txt                     对比文件差别

sort

sort file2.txt                                  对文件内容升序排序
sort -r file2.txt                               对文件内容降序排序

gzip

gzip file2.txt                                  压缩文件
gzip -d file2.txt.gz                            解压缩文件
gzip -l *.gz                                    展示压缩率

bzip2

bzip2 test.txt
bzip2 -d test.txt.bz2

unzip

unzip test.zip
unzip -l test.zip

shutdown

shutdown -h now                                 立即关闭计算机

shutdown -h +10                                 10分钟后关闭计算机

shutdown -r now                                 重启计算机

shutdown -Fr now                                重启计算机并检查文件系统

ftp

ftp IP/hostname                                 连接ftp

ftp> mget *.html                                下载文件

ftp> mls *.html -                               列出文件

service

service iptables status                         查看服务状态
service --status-all
service iptables restart                        重启服务

ps

ps -ef | more                                   查看当前系统运行进程
ps -efH | more
ps -ef | grep vim

free

free                                            查看系统内存使用情况
free -g
free -t

top

top                                             展示系统进程,按cpu使用率排序

df

df -k                                           展示磁盘使用情况
df -h
df -T

kill

kill -9 pid                                     终结进程

cp

cp -p file1 file2                               将file1复制到file2
cp -i file1 file2

mv

mv -i file1 file2                               重命名文件
mv -v file1 file2

cat

cat file1 file2                                 查看文件

ifconfig

ifconfig -a                                     展示所有的网络接口

uname

uname -a                                        展示系统信息

tail

tail file2.txt                                  展示文件最新10行
tail -n 10 file2.txt 
tail -f log-file                                实时查看

less

less huge-log-file.log                          查看大体积文件
CTRL+F 下一页
CTRL+B 上一页

iptables

iptables -L -n                                  列出防火墙的信息
iptables -I INPUT -p tcp --dport 8090 -j ACCEPT  开启8090端口
原文地址:https://www.cnblogs.com/ye-hcj/p/9870074.html