1. 显示当前目录 pwd

wangzhengchao@ubuntu:~$ cd /home/wangzhengchao/Desktop/
wangzhengchao@ubuntu:~/Desktop$ pwd
/home/wangzhengchao/Desktop

 2. 改变目录 cd

wangzhengchao@ubuntu:~$ pwd
/home/wangzhengchao
wangzhengchao@ubuntu:~$ cd Downloads/usr
wangzhengchao@ubuntu:~/Downloads/usr$ pwd
/home/wangzhengchao/Downloads/usr
wangzhengchao@ubuntu:~/Downloads/usr$ cd ..
wangzhengchao@ubuntu:~/Downloads$ pwd
/home/wangzhengchao/Downloads
wangzhengchao@ubuntu:~/Downloads$ cd
wangzhengchao@ubuntu:~$ pwd
/home/wangzhengchao

注意:

  • 当登录系统后,总是处于当前用户主目录中 /home/wangzhengchao
  • ..代表当前目录到上一级目录
  • . 代表当前目录
  • ~代表用户主目录
  • 可以使用命令cd ../..直接进入根目录

3. 列出目录内容 ls

ls基本语法 ls [option] [file]

-a 显示所有文件,包括隐藏文件
-l 显示文件到各种属性
wangzhengchao@ubuntu:~$ pwd
/home/wangzhengchao
wangzhengchao@ubuntu:~$ ls
Desktop Downloads Music Public Videos
Documents examples.desktop Pictures Templates
wangzhengchao@ubuntu:~$ ls -l
总用量
drwxr-xr-x wangzhengchao wangzhengchao 9月 : Desktop
drwxr-xr-x wangzhengchao wangzhengchao 9月 : Documents
drwxr-xr-x wangzhengchao wangzhengchao 9月 : Downloads
-rw-r--r-- wangzhengchao wangzhengchao 9月 : examples.desktop
drwxr-xr-x wangzhengchao wangzhengchao 9月 : Music
drwxr-xr-x wangzhengchao wangzhengchao 9月 : Pictures
drwxr-xr-x wangzhengchao wangzhengchao 9月 : Public
drwxr-xr-x wangzhengchao wangzhengchao 9月 : Templates
drwxr-xr-x wangzhengchao wangzhengchao 9月 : Videos

ls-l 显示的属性包括:

  • 文件权限标志
  • 文件的链接个数
  • 文件所有者的用户名
  • 该用户所在到用户组名
  • 文件大小
  • 最后一次修改到日期
  • 最后一次修改到时间
  • 文件名

4. 列出目录内容 dir / vdir

wangzhengchao@ubuntu:~$ pwd
/home/wangzhengchao
wangzhengchao@ubuntu:~$ dir Downloads/
employees_db navicat121_mysql_en_x64.tar.gz
employees_db-full-1.0..tar.bz2 navicat.desktop
flash_player_npapi_linux.x86_64.tar.gz navicat.png
LGPL readme.txt
libflashplayer.so sogoupinyin_2.2.0.0108_amd64.deb
license.pdf sublime_text_3_build_3176_x64.tar.bz2
navicat121_mysql_en_x64 usr
wangzhengchao@ubuntu:~$ vdir Downloads/
总用量
drwxrwxr-x wangzhengchao wangzhengchao 9月 : employees_db
-rw-rw-r-- wangzhengchao wangzhengchao 3月 employees_db-full-1.0..tar.bz2
-rw-rw-r-- wangzhengchao wangzhengchao 9月 : flash_player_npapi_linux.x86_64.tar.gz
drwxrwxr-x wangzhengchao wangzhengchao 8月 : LGPL
-rw-rw-r-- wangzhengchao wangzhengchao 8月 : libflashplayer.so
-rw-rw-r-- wangzhengchao wangzhengchao 8月 : license.pdf
drwxr-xr-x root root 9月 : navicat121_mysql_en_x64
-rw-rw-r-- wangzhengchao wangzhengchao 9月 : navicat121_mysql_en_x64.tar.gz
-rwxrwxr-x wangzhengchao wangzhengchao 9月 : navicat.desktop
-rw-rw-r-- wangzhengchao wangzhengchao 9月 : navicat.png
-rw-rw-r-- wangzhengchao wangzhengchao 8月 : readme.txt
-rw-rw-r-- wangzhengchao wangzhengchao 9月 : sogoupinyin_2.2.0.0108_amd64.deb
-rw-rw-r-- wangzhengchao wangzhengchao 9月 : sublime_text_3_build_3176_x64.tar.bz2
drwxrwxr-x wangzhengchao wangzhengchao 8月 : usr

dir 用于列出目录内容,vdir用于列出目录内容的详细信息 相当于ls -l

5. 查看文本文件  cat / more

wangzhengchao@ubuntu:~/Downloads$ cat test
A
B
C
D
E
F
G
wangzhengchao@ubuntu:~/Downloads$ cat -n test
A
B
C
D
E
F
G

-n 显示行号,如果文本内容很长,使用cat指令会全部打印常出来,linu提供more指令一页一页地显示出来,空格向下翻一页,enter向下一行,Q退出

 6. 阅读文件的开头和结尾 head / tail

wangzhengchao@ubuntu:~/Downloads$ head -n  test
A
B
wangzhengchao@ubuntu:~/Downloads$ tail -n test
F
G

7. 查找文件内容 grep

一般格式: grep [option] pattern [file...] ,返回所有含有指定pattern的行,同时可以使用-n 命令选项显示所在行号。

wangzhengchao@ubuntu:~/Downloads$ grep Sort sort1026.cpp
void QSort(vector<int> &array, int low, int high){
QSort(array, low, pivot-);
QSort(array, pivot+, high);
void QuickSort(vector<int> &array){
QSort(array, , array.size()-);
void HeapSort(std::vector<int> &array){
// QuickSort(array);
HeapSort(array);
// BubbleSort(array);

对于查找含有空格的字符,需要使用‘’包含进去,如下:

wangzhengchao@ubuntu:~/Downloads$ grep 'vector<int> &array' sort1026.cpp
int Partition(vector<int> &array, int low, int high){
void QSort(vector<int> &array, int low, int high){
void QuickSort(vector<int> &array){
void HeapAdjust(std::vector<int> &array, int start, int end){
void HeapSort(std::vector<int> &array){

8. 查找文件 find

基本语法: find [option] [path...] [expression]

find命令是根据文件的属性进行查找,如文件名,文件大小,所有者,所属组,是否为空,访问时间,修改时间等。

wangzhengchao@ubuntu:~$ find Downloads/ -name *.cpp
Downloads/sort1026.cpp

上述指令表示在Downloads目录下查找文件名含有.cpp的文件。根据其他属性查找文件的方法与上述指令类似。

9. 定位文件 locate

wangzhengchao@ubuntu:~$ locate *正则化.pdf
/home/wangzhengchao/Documents/机器学习集锦/机器学习算法/机器学习算法系列():L1、L2正则化.pdf

10. 用户及版本信息查看

wangzhengchao@ubuntu:~$ who
wangzhengchao tty7 -- : (:)
wangzhengchao@ubuntu:~$ whoami
wangzhengchao
wangzhengchao@ubuntu:~$ uname
Linux
wangzhengchao@ubuntu:~$ uname -a
Linux ubuntu 4.15.--generic #~16.04.-Ubuntu SMP Wed Jul :: UTC x86_64 x86_64 x86_64 GNU/Linux
wangzhengchao@ubuntu:~$ uname -r
4.15.--generic
  • who 显示当前系统有哪些人登录,以及对应的工作台
  • whoami 显示当前用户名称
  • uname 显示当前系统的版本信息  -a 显示详细信息  -r显示内核信息

11. 寻求帮助 man

$ man grep
GREP() General Commands Manual GREP() NAME
grep, egrep, fgrep, rgrep - print lines matching a pattern SYNOPSIS
grep [OPTIONS] PATTERN [FILE...]
grep [OPTIONS] [-e PATTERN]... [-f FILE]... [FILE...] DESCRIPTION
grep searches the named input FILEs for lines containing a match to the given PATTERN. If no files are specified, or if the file “-” is
given, grep searches standard input. By default, grep prints the matching lines. In addition, the variant programs egrep, fgrep and rgrep are the same as grep -E, grep -F, and grep -r, respectively. These variants are
deprecated, but are provided for backward compatibility. OPTIONS
...

12. 获取命令简介 whatis

man到内容显得有些罗嗦,whatis指令帮助用户了解指令的大致用途

wangzhengchao@ubuntu:~$ whatis grep
grep () - print lines matching a pattern

Linux---shell基本指令的更多相关文章

  1. linux shell 常用指令

    1. man 对你熟悉或不熟悉的命令提供帮助解释 eg:man ls 就可以查看ls相关的用法 注:按q键或者ctrl+c退出,在linux下可以使用ctrl+c终止当前程序运行. 2. ls 查看目 ...

  2. Linux shell tee指令学习

    转载自:http://blog.163.com/xujian900308@126/blog/static/12690761520129911304568/   tee tee:读取标准输入的数据,并将 ...

  3. Linux - Shell常用指令

    一.文件.目录操作命令 1.ls命令:显示文件和目录的信息 ls 以默认方式显示当前目录文件列表 ls -a 显示所有文件包括隐藏文件 ls -l 显示文件属性,包括大小,日期,符号连接,是否可读写及 ...

  4. linux: shell常用指令归纳

    1.软件安装方式: 1)源码安装: ~ wget xxxxxx ~ ./configure ~ make ~ make install 2) yum: ~ yum search : 查找软件包 ~ y ...

  5. linux shell 指令搜索顺序

    在linux shell 中输入一个命令,如果有多个同名指令,shell需要按照一定规则去取优先级高的一个执行,shell命令的搜索顺序为: 1.别名,使用alias创建的命令. 2.关键字,如if, ...

  6. Linux Shell 裡一些很少用到卻很有用的指令

    Linux Shell 裡一些很少用到卻很有用的指令 2009年11月30日 13:53:00 yaoyasong 阅读数:414   Linux Shell 裡一些很少用到卻很有用的指令 你是不是已 ...

  7. Linux shell脚本编程(一)

    Linux shell脚本编程: 守护进程,服务进程:启动?开机时自动启动: 交互式进程:shell应用程序 广义:GUI,CLI GUI: CLI: 词法分析:命令,选项,参数 内建命令: 外部命令 ...

  8. Linux Shell 重定向与管道【转帖】

    by 程默 在了解重定向之前,我们先来看看linux 的文件描述符. linux文件描述符:可以理解为linux跟踪打开文件,而分配的一个数字,这个数字有点类似c语言操作文件时候的句柄,通过句柄就可以 ...

  9. [转]linux shell数据重定向(输入重定向与输出重定向)详细分析

      在了解重定向之前,我们先来看看linux 的文件描述符. linux文件描述符:可以理解为linux跟踪打开文件,而分配的一个数字,这个数字有点类似c语言操作文件时候的句柄,通过句柄就可以实现文件 ...

  10. linux shell脚本常用语句

    linux shell 指令 诸如-d, -f, -e之类的判断表达式: 文件比较运算符-e filename  如果 filename存在,则为真  [ -e /var/log/syslog ]-d ...

随机推荐

  1. go11---方法method

    package main /* 方法method Go 中虽没有class,但依旧有method 通过显示说明receiver来实现与某个类型的组合 只能为同一个包中的类型定义方法 Receiver ...

  2. nestedScrollview 嵌套使用recyclerview判断滑动到底部 (嵌套滑动导致 不能使用recyclerview的onscrolled监听)

    NestedScrollView scroller = (NestedScrollView) findViewById(R.id.myScroll); if (scroller != null) { ...

  3. P3256 [JLOI2013]赛车

    传送门 如果把速度看成斜率,起始位置看成截距,这就是一个水平可见直线了-- 不过这题里我实现方法借鉴了CQzhangyu大佬的,先按速度排序,然后维护一个单调栈,如果当前的人速度比栈顶大距离又比它远直 ...

  4. AMD的规范使用

    1.解决命名冲突 2.解决繁琐的文件依赖 3. 可读性.可依赖性 参考这里 // foobar.js // 私有变量 var   test = 123: //  公有方法 function  foot ...

  5. 基于.Net Core的API框架的搭建(2)

    4.加入数据库支持 下面我们为项目加入数据库支持,修改appsettings.json: 然后我们要生成实体类,打开VS工具->NuGet包管理器->程序包管理器控制台: 输入命令: Sc ...

  6. c++编程中处理char和wchar_t的好工具

    /* ttype.h sdragonx 2015-02-18 18:32:43 这个几个模版函数是为了处理ansi或unicode,使字符串值或者字符串函数能够在模版中使用 2018/7/26 23: ...

  7. Linux学习系列八:操作网口

    一些相对高性能的单片机会带以太网接口,网口在MCU里算是比较复杂的外设了,因为它涉及到网络协议栈,通常情况下网络协议栈会运行在一个RTOS中,所以对普通单片机开发者来说网口使用起来相对难度较大一些.在 ...

  8. epoll IO多路复用(异步阻塞AIO)

    epoll的异步阻塞(AIO): 用户线程创建epoll后,其实是内核线程负责扫描 fd 列表(在网络服务器上可以是socket,socket在创建后返回的也是文件描述符),并填充事件链表.但是,并不 ...

  9. 支持多种格式的播放器js代码

    FLV需要播放器,其它视频格式直接插入相应的代码即可. ------------------------------------- /**   *视频播放 by zhensheng@   *参数说明  ...

  10. js操作元素透明度以及浏览器兼容性

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta http ...