Linux---shell基本指令
2024-08-22 22:27:08
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
最新文章
- VS2010 ERROR:c1xx fatal error c1083
- POJ 1273 Drainage Ditches题解——S.B.S.
- 使用SSIS进行数据清洗
- mongoengine
- IntelliJ IDEA 我的配置--留个脚印
- 越狱Season 1- Episode 16
- bzoj1009
- Hadoop 处理“Name node is in safe mode”问题(转)
- Java 集合的简单实现 (ArrayList &; LinkedList &; Queue &; Stack)
- MongoDB install
- URL传递中文参数乱码问题
- ALU底层方法及计算机整数加减乘除模拟
- React browserHistory.push()传参
- tensorflow实现循环神经网络
- java web 实现文件夹上传(保留目录结构)
- 阿里云oss服务通用类
- 背水一战 Windows 10 (40) - 控件(导航类): AppBar, CommandBar
- C语言位操作--两整数中的最大值与最小值
- mysql 建库建表建用户
- PHPCMS V9 fsockopen 函数被禁用解决方案