Liunx常用命令

200 阅读3分钟

一起养成写作习惯!这是我参与「掘金日新计划 · 4 月更文挑战」的第1天,点击查看活动详情

last

查看最近操作的用户

    last -10

passwd

设置用户的密码,在windows中用的netuser

    passwd root #回车之后要输入密码,但是密码不显示出来

su

切换用户

    su root 
    su -root 
    su 普通用户
    #切换到root用户并带着root的环境变量

ls

list列表显示目录中的所有目录和文件

    ls -alt
    ll ../test*
    #a=all l=long t=time

cd

更换目录

    cd /user/local
    cd .. #回到上级目录
    cd ~ #回到当前用户的home目录
    cd - #回到上一次的操作目录
    cd / #回到根目录

pwd

pwd显示当前工作路径

    pwd

man

查看帮助

    man ls
    #也可以使用ls --help

mkdir

make dir 创建目录

    mkdir 目录名称

rmdir

删除目录

    rmdir 目录名称
    #只能删除目录,不能删除文件。一般用rm -rf来删除目录

touch

删除一个空文件

    touch test.txt
    #创建文件,有扩展名与没扩展名是不同的

cp

拷贝一文件到目标目录

    cp -r 文件 目标目录

rm

删除文件或目录

    rm -rf / 
    #-r是指递归删除,-f是指强制删除

mv

移动或者重命名

    mv test1.txt test2.txt

cat

显示文件的全部内容

    cat test1.txt test2.txt
    #把test.txt,test2.txt的内容都显示在屏幕上

more

分页显示

    more test.txt

less

分页显示

    less test.txt

head

显示文件的前面多少行内容

    head -50 test2.txt
    #默认为10行

tail

显示文件的最后多少行内容

    tail -30 test2.txt

进行日志监控

    tail -f test2.txt

chmod

修改权限

    chmod -R 777 phpwind
    chmod +x test.bin

chown

修改所有者

    chown root test.txt

grep

查看文件中的内容,如果包含则整行显示

    grep "error" test.txt
    ps -ef|grep "tomcat"

find

查找文件

    find / -type f -name test.txt

wc

字数统计

    wc test.txt
    #行数、单词数、字节数

vi,vim

文本编辑

    vi 文件名.后缀名

ps

查看系统运行的任务(程序)

    ps -ef|grep "任务名"
    ps -aux|grep "进程名"
    #-aux会显示该进程的CPU和内存的使用情况

top

查看CPU、内存资源

top

kill

强制关闭一个进程

    kill -9 pid
    #可以使用进程名,但是建议使用进程ID

hostname

查看主机名,也就是计算机名

    hostname

netstat

查看端口号

    netstat -ano|grep "端口号"
    #在windows下是使用netstat -ano|find "80"

ifconfig

查看IP地址

    ifconfig

ping

查看本机与目标地址的网络连通性

    ping 192.168.x.xx

df

查看磁盘分区以及磁盘使用情况

    df

du

查看文件和目录对磁盘空间的使用情况

    du

tar

解压缩tar.gz

    tar -zxvf xx.tar.gz

解压缩tar

    tar -xvf xx.tar

压缩文件夹

    tar -cxvf xx.tar.gz /home/xx

unzip

解压缩zip文件

    unzip xx.zip

gzip

用来把文件进行压缩,压缩进gz格式

    gzip test.txt
    #压缩后的名字为test.txt.gz

gunzip

用来解压缩gz格式文件

    gunzip test.txt.gz
    #对应的还有zip unzip命令

rpm

安装

    rpm -ivh xx.rpm

卸载

    rpm -e 应用程序名

查看应用程序的名称

    rpm -qa|grep "应用程序名的一部分"

yum

在线安装

    yum install httpd

查看应用程序的名称

    yum list installed

卸载

    yum uninstall xx.xx

wget

网络下载

    wget http://www.example.com