【Linux学习笔记】Linux常用命令

更新时间:2018/06/29

前言

最近开始学习Linux,记录一下,备注一下:今天有人问我博客中代码乱,解释一下,我用的oh-my-zsh,在终端里面带颜色,实际上箭头右面第一个是路径,之后才是命令哈~~~

常用系统工作命令

echo

用于在终端输出字符或变量值,格式:echo [字符串|$变量],命令如下:

➜  ~ echo SHELL
SHELL
➜  ~ echo $SHELL
/bin/zsh
date

用于显示和设置系统时间和日期,格式:date [选项] [+指定格式]

参数 解释
%t tab键
%H 小时00~23
%I 小时00~12
%M 分钟00~59
%S 秒00~59
%j 今年的第几天

常用命令及输出结果如下:

➜  ~ date
2018621日 星期四 210222秒 CST
➜  ~ date "+%Y-%m-%d %H:%M:%S"
2018-06-21 21:02:33
➜  ~ date "+%j"
172
ps

用于查看系统进程状态,格式:ps [参数]

参数 解释
-a 显示所有进程
-u 显示用户详细信息
-x 显示没有控制终端的进程

常用命令及输出结果如下:

➜  ~ ps
  PID TTY           TIME CMD
 4049 ttys000    0:00.04 /Applications/iTerm.app/Contents/MacOS/iTerm2 --server login -f
 4051 ttys000    0:01.34 -zsh
 4077 ttys001    0:00.03 /Applications/iTerm.app/Contents/MacOS/iTerm2 --server login -f
 4080 ttys001    0:00.36 -zsh
➜  ~ ps -a
  PID TTY           TIME CMD
 4049 ttys000    0:00.04 /Applications/iTerm.app/Contents/MacOS/iTerm2 --server login -f
 4051 ttys000    0:01.34 -zsh
15097 ttys000    0:00.00 ps -a
 4077 ttys001    0:00.03 /Applications/iTerm.app/Contents/MacOS/iTerm2 --server login -f
 4080 ttys001    0:00.36 -zsh
kill 和 killall

kill 用于终止PID进程,格式:kill [参数] [进程PID],killall 用于终止指定名称的全部进程,格式:killall [参数] [进程名称]

➜  ~ kill 2100
➜  ~ killall httpd
history

用于显示历史执行过的命令,根据命令前的序号可直接调用命令:

➜  ~ history
  1  ls
  2  ll
  ...
  641  ps -x
  642  who
  643  last
➜  ~ !642
➜  ~ who

工作目录切换

pwd,cd,ls,ll

pwd用于查看当前路径,cd用于进入/退出路径,ls和ll用于查看当前路径下的文件,其基本命令如下:

➜  ~ pwd
/Users/roguesir
➜  ~ ls
Desktop            Downloads          Personal          Documents          Github             virtual-env
➜  ~ cd Github
➜  Github ll
total 0
drwxr-xr-x   6 roguesir  staff   204B  4  1 14:03 Book-Paper-Sharing
drwxr-xr-x  10 roguesir  staff   340B  4  1 17:25 DL-ML-project
drwxr-xr-x   9 roguesir  staff   306B  4 13 17:18 Machine-Learning-Repo
drwxr-xr-x   8 roguesir  staff   272B  5 21 18:43 Python-R-code
drwxr-xr-x   4 roguesir  staff   136B  5 21 18:45 Recommendation-Algorithm
drwxr-xr-x  24 roguesir  staff   816B  3 28 09:40 roguesir.github.io
➜  Github ls -a
.                        .DS_Store                DL-ML-project            Python-R-code            roguesir.github.io
..                       Book-Paper-Sharing       Machine-Learning-Repo    Recommendation-Algorithm
➜  Github ll -a
total 16
drwxr-xr-x   9 roguesir  staff   306B  3 30 16:21 .
drwxr-xr-x  45 roguesir  staff   1.5K  6 25 23:07 ..
-rw-r--r--@  1 roguesir  staff   6.0K  3 30 15:56 .DS_Store
drwxr-xr-x   6 roguesir  staff   204B  4  1 14:03 Book-Paper-Sharing
drwxr-xr-x  10 roguesir  staff   340B  4  1 17:25 DL-ML-project
drwxr-xr-x   9 roguesir  staff   306B  4 13 17:18 Machine-Learning-Repo
drwxr-xr-x   8 roguesir  staff   272B  5 21 18:43 Python-R-code
drwxr-xr-x   4 roguesir  staff   136B  5 21 18:45 Recommendation-Algorithm
drwxr-xr-x  24 roguesir  staff   816B  3 28 09:40 roguesir.github.io
➜  Github cd ..
➜  ~ cd -
~/Github
➜  Github

文本编辑

cat与more

cat和more用于查看文档内容,适用于较短文档;more适用于较长文档,格式cat [文档名] 、more[文档名]

head 和 tail

head和tail用于查看文件的前几行和末几行,格式为:head [参数] [文档名]、tail [参数] [文档名],默认显示六条,自定义用-n参数,如下:

➜  Face-Scoring git:(master) head train.py

from __future__ import print_function
import os
import matplotlib.pyplot as plt
import tensorflow as tf
from PIL import Image
import numpy
import tensorflow as tf


➜  Face-Scoring git:(master) tail train.py
        if count % 10 == 0:
            # Calculate batch loss and accuracy
            loss, acc = sess.run([cost, accuracy], feed_dict={x: batch_xs,
                                                              y: batch_ys,
                                                              keep_prob: 1.})
            print("count = " + str(count) + ", Minibatch Loss= " + str(loss) + ", Training Accuracy= " + str(acc) )
    print("Optimization Finished!")
    saver.save(sess,"./model/model.ckpt")

➜  Face-Scoring git:(master) head -n 3 train.py

from __future__ import print_function
import os
➜  Face-Scoring git:(master) head -3 train.py

from __future__ import print_function
import os
wc

wc用于查看文本信息,常用参数为-l,用于查看文本行数,如下:

➜  Face-Scoring git:(master) wc -l train.py
     146 train.py
➜  Face-Scoring git:(master) wc train.py
     146     483    4778 train.py
diff

diff用于比较两个文件的差异,常用:diff [文件1] [文件2]

文件目录管理

mkdir用于创建目录;touch用于新建文件;cp用于复制文件;mv用于移动或改名;rm用于删除文件,上述操作中,递归可食用参数-R,命令如下:

➜  ~ mkdir roguesir
➜  ~ cd roguesir
➜  roguesir touch roguesir
➜  roguesir ls
roguesir
➜  roguesir cp roguesir rogue
➜  roguesir ls
rogue    roguesir
➜  roguesir mv rogue rogue-sir
➜  roguesir ls
rogue-sir roguesir
➜  roguesir rm rogue-sir
➜  roguesir ls
roguesir

压缩解压与查找

tar
grep
find

猜你喜欢

转载自blog.csdn.net/roguesir/article/details/80766104