Linux---shell基本指令
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基本指令的更多相关文章
- linux shell 常用指令
1. man 对你熟悉或不熟悉的命令提供帮助解释 eg:man ls 就可以查看ls相关的用法 注:按q键或者ctrl+c退出,在linux下可以使用ctrl+c终止当前程序运行. 2. ls 查看目 ...
- Linux shell tee指令学习
转载自:http://blog.163.com/xujian900308@126/blog/static/12690761520129911304568/ tee tee:读取标准输入的数据,并将 ...
- Linux - Shell常用指令
一.文件.目录操作命令 1.ls命令:显示文件和目录的信息 ls 以默认方式显示当前目录文件列表 ls -a 显示所有文件包括隐藏文件 ls -l 显示文件属性,包括大小,日期,符号连接,是否可读写及 ...
- linux: shell常用指令归纳
1.软件安装方式: 1)源码安装: ~ wget xxxxxx ~ ./configure ~ make ~ make install 2) yum: ~ yum search : 查找软件包 ~ y ...
- linux shell 指令搜索顺序
在linux shell 中输入一个命令,如果有多个同名指令,shell需要按照一定规则去取优先级高的一个执行,shell命令的搜索顺序为: 1.别名,使用alias创建的命令. 2.关键字,如if, ...
- Linux Shell 裡一些很少用到卻很有用的指令
Linux Shell 裡一些很少用到卻很有用的指令 2009年11月30日 13:53:00 yaoyasong 阅读数:414 Linux Shell 裡一些很少用到卻很有用的指令 你是不是已 ...
- Linux shell脚本编程(一)
Linux shell脚本编程: 守护进程,服务进程:启动?开机时自动启动: 交互式进程:shell应用程序 广义:GUI,CLI GUI: CLI: 词法分析:命令,选项,参数 内建命令: 外部命令 ...
- Linux Shell 重定向与管道【转帖】
by 程默 在了解重定向之前,我们先来看看linux 的文件描述符. linux文件描述符:可以理解为linux跟踪打开文件,而分配的一个数字,这个数字有点类似c语言操作文件时候的句柄,通过句柄就可以 ...
- [转]linux shell数据重定向(输入重定向与输出重定向)详细分析
在了解重定向之前,我们先来看看linux 的文件描述符. linux文件描述符:可以理解为linux跟踪打开文件,而分配的一个数字,这个数字有点类似c语言操作文件时候的句柄,通过句柄就可以实现文件 ...
- linux shell脚本常用语句
linux shell 指令 诸如-d, -f, -e之类的判断表达式: 文件比较运算符-e filename 如果 filename存在,则为真 [ -e /var/log/syslog ]-d ...
随机推荐
- centos7 安装8188eu驱动小记
最小化安装把lsusb和lspci装上 使用lsusb 和lspci的命令, centos上的安装命令: yum -y install usbutils yum -y install pciutils ...
- C#计算运行时间
using System.Diagnostics; private Stopwatch stw = new Stopwatch(); stw.Start(); stw.Stop(); MessageB ...
- codeforces 940F 带修改的莫队
F. Machine Learning time limit per test 4 seconds memory limit per test 512 megabytes input standard ...
- Ural1099 Work Scheduling 一般图的最大匹配
Ural1099 给定无向图, 求最大匹配. 在寻找增广路的过程中,可能出现一个奇环,这时候把奇环收缩,成为一朵“花”,并在新图上继续增广. 为了记录匹配关系,需要在花中寻找路径,每一条增广路径都可以 ...
- HTML5中File
一 File对象与FileList对象 当将input元素的type类型设置为file时,web页面上会显示一个选择文本按钮和一个文本显示框,单击文件按钮可以选择一个文件,文本显示框中会显示选中的文件 ...
- vue商品详情页添加动画(eg)
<template> <div class="food" transition="move"></div> </tem ...
- 清北刷题10.23night
NOIP 模拟赛 张若天 年 ⽉ ⽇ 题⽬名称 监听 实验室 ⽂明 可执⾏⽂件名 monitor lab civilization 输⼊⽂件名 monitor.in lab.in civilizati ...
- JavaScript--DOM访问子结点childNodes
访问子结点childNodes 访问选定元素节点下的所有子节点的列表,返回的值可以看作是一个数组,他具有length属性. 语法: elementNode.childNodes 注意: 如果选定的节点 ...
- C++函数重载的4种错误示例
函数重载的4种错误示例: #include <iostream> #include <string> using namespace std; //函数重载 同函数名,函数重载 ...
- C#结构体+结构体与类的区别
C# 结构(Struct) 在 C# 中,结构是值类型数据结构.它使得一个单一变量可以存储各种数据类型的相关数据.struct 关键字用于创建结构. C# 结构的特点 您已经用了一个简单的名为 Boo ...