Python之路【第三篇】:Linux常用命令

 

在以后的路上,linux肯定要用,但是现阶段我们还用不到,因为现阶段的任务都是在windows下完成的,那么我们为什么要用linux?原因不外乎下面三点:

Linux是稳定的
          何为稳定?打个比方,以前windows会出现蓝屏的情况,而linux不会,这么说明白了吧,试想一下,一个公司的服务器经常死机,

          那可不是一件好玩的事情,用户都会骂大街了!

Linux是开源的
Linux是安全的
上面三个观点也只是网上看来得,俗话说:千里之行,始于足下,linux到底好在哪里,还是需要自己试试才知道

本篇主要总结一些常用的LINUX命令,随时保持修改添加。
  1. 在线帮助
  2. 命令安装
  3. 目录或路径
  4. 显示文件或目录清单
  5. 文件编辑
  6. 查看文件内容

1、在线帮助

1、man  命令
2、help 命令
3、命令 --help
如:
man yum
help ls
ls --help
三种帮助方式结合使用,不要仅局限于一种,因为有些命令使用某一个方式会查不出来

 

2、命令安装

yum -y install name
我们用在线帮助查询查询一下yum命令,发现了什么?
help yum
[root@localhost bin]# help yum
bash: help: no help topics match `yum'.  Try `help help' or `man -k yum' or `info yum'.

 yum --help

[root@localhost bin]# yum --help
bash: /usr/bin/yum: /usr/bin/python3.5: bad interpreter: No such file or directory

  help yum 和 yum --help两种方式对yum命令均无效,因此只能寄希望于man yum,果然不负众望:

SYNOPSIS
       yum [options] [command] [package ...]
DESCRIPTION
       yum  is an interactive, rpm based, package manager. It can automatically perform
       system updates, including dependency analysis and obsolete processing  based  on
       "repository" metadata. It can also perform installation of new packages, removal
       of old packages and perform queries on the installed and/or  available  packages
       among  many  other  commands/services  (see below). yum is similar to other high
       level package managers like apt-get and smart.

       While there are some graphical interfaces directly to the yum code, more  recent
       graphical interface development is happening with PackageKit and the gnome-pack-
       agekit application.

       command is one of:
        * install package1 [package2] [...]
        * update [package1] [package2] [...]
        * update-to [package1] [package2] [...]
        * check-update
        * upgrade [package1] [package2] [...]

只是摘抄了一部分的帮助信息,从信息中可以了解到yum的用途和用法

并且通过这一部分,我们也明白了为何三种帮助方式需要结合使用!

3、目录和路径

/            代表根目录
.            代表当前目录
..           代表上一级目录

pwd         查看当前目录
cd           进入路径(change directory)

 4、显示文件或目录清单

ls用于显示文件或目录清单
ls -l   显示文件或目录清单
ls -al  可以查看隐藏文件,如果需要创建一个隐藏文件,在文件名前面加一个.即可
ls -lh  可以直观的看出文件的大小,h=human代表人性化,所以lh可以理解为人性化的展示文件列表,1M = 1024K 1K = 1024Byte 1Byte = 1024Bit

5、文件编辑

vim
在终端,输入vim filename,便可以进入文件编辑界面,然后点击键盘上的i就进入编辑模式,编辑完成后,按esc退出编辑模式,然后回车,输入:wq保存离开
vim filename +行号,可以直接到行号标记的那一行

6、查看文件内容

cat filename  查看文件内容
more filename 可以一页页或者一行行查看内容,回车是一行行看,空格是一页页看
less 可以使用PgUp和PgDn前后翻页看,而more不能向前观看
grep

7、文件操作

cp
touch 一是用于把已存在文件的时间标签更新为系统当前的时间(默认方式),它们的数据将原封不动地保留下来;二是用来创建新的空文件
find path -name filename 在指定路径下寻找文件
mv filename path将文件移动到指定目录下
rename文件名修改
rm(这个命令要少用,比较危险,删了就找不回来了)
>filename可以把文件内容清空,如>test.txt这样就可以把test.txt的内容给清空了
chmod
chown
useradd

8、目录操作

mkdir  目录名,创建目录
mkdir -p 1/2/3/4/5 递归式的创建目录(创建多级目录)
rmdir 删除目录
tree 目录,显示目录树结构

9、压缩命令

tar zcvf demo.tar.gz 原文件名

10、磁盘内存相关

df -h查看当前linux系统上的磁盘使用情况
du -sh
free -m查看机器内存
top可以查看哪个程序消耗的内存多
当机器运行缓慢的时候,就看内存和CPU情况

11、网络相关

ip   a 查看当前ip地址
wget

 

posted @ 2018-01-02 17:31  RongHe  阅读(457)  评论(0编辑  收藏  举报