Introduction to Linux

What is Linux?

a Unix-like computer operating system but free and open-source.

The Linux Operating System (OS) is a large program (mostly coded in C) that turns the computer into a useable machine.

Account

Each user has their own space, called their account.

**login: **

ad type your ID and RETURN

Password: type your password and

RETURN. It does not appear.

$ The Linux prompt提示 (or similar). You can now enter commands.

Access denied Password: Login ID and password not match

**logout **

^D : 同时按CONTROL和D键

exit

The Shell

The Linux user interface is called the shell

image-20230307101021308

ssh student@127.0.0.1 2000:远程联机

rz:上传文件

sz x:下载文件

Typing Commands

date:Gives time and date

cal 3 1997:Calendar

image-20230307102257001

who

image-20230307102346439

pwd 当前路径

image-20230307102501547

ifconfig

image-20230307102416877

man cal: Manual pages

image-20230307102550728

uptime

Machine’ s ‘ up ’ time

显示系统已经运行了多长时间、当前登入用户数量、过去1分钟、5分钟、15分钟内的负载信息。

image-20230307102901305

hostname

Name of the machine

image-20230307103139440

apropos topic(要查的命令的topic)

如果你不知道完成某个特定任务所需要命令的名称,可以使用一个关键字通过Linux apropos实用程序来搜索它。该实用程序可以搜索关键字并且显示所有包含匹配项的man页面的简短描述

Lists commands related to topic

和 man -k一个功能

man -k topic(要查的命令的topic)

whatis cmd: One-line description(描述一个命令)

which cmd: 定位一个命令

locate cmd :List files with cmd in their name (or path)

locate your_file_name 即可查找指定文件

Output of these commands can be very long. See one screenful at a time with:

locate game | more

apropos print | more

Press enter/spacebar to go on; ^C/q to stop

Control Characters

image-20230307102628855

Changing your Password

passwd:

System Directories 文件操作

image-20230307104131934

home directory, which is named after your login ID.

pwd showing current directory

image-20230307104205818

root Account

root: super user, who has the full rights to all resources

  • home directory: /root

  • changing to root account: $sudo -i

  • add a new user account: #adduser account-name

终端切换

​ Windows: ALT+F1, ALT+F2

Pathnames

路径名是目录名的序列(以/ 分隔),用于标识目录的位置

Absolute Pathnames

树的顶部(根)和感兴趣的目录之间的目录名称序列。

/bin

/etc/terminfo

/home/ad

/home/student/proj1

Relative Pathnames

从当前所在目录到感兴趣目录的目录名称的顺序。

proj1 if you are in student

student/proj1 if you are in home

image-20230307104546724

image-20230307104610734

Working with Directories

Moving between Directories

image-20230307104656394

student到proj1中

cd proj1:(current working directory.)

pwd :Print name of current working directory

Move back to directory student (the parent directory):cd .. (返回上一级目录)

proj1到proj2

image-20230307104959877

..是上一级目录

../proj2 is a relative pathname

image-20230307105151826 image-20230307105320356
Investigate the System

cat file 命令用于连接文件并打印到标准输出设备上

List file

ls Directory listing

​ ls List current dir.

​ ls /etc List /etc

​ ls -F -F option shows types

Making / Deleting / Renaming Directories

image-20230307105859025

Creating a Text File

cat > file

这将把你在键盘上输入的文本输入到文件中,直到你输入^D (CONTROL和D一起)

Listing Files

cat file List the file

more file List the file a screen at a time. Type spacebar to go on; ^C to stop

less file Like more but more powerful

head file List the first few lines

tail file List the last few lines

Other Basic Commands

image-20230307110434371

image-20230307110448954

image-20230307110531959
I/O Redirection

Most commands output to the screenls

Output can be redirected to a file with‘>‘:

​ ls > dir.txt

​ cal 1997 > year1997

“>”把输出输入到文件中

“>>”:cal 1998 >> years把输出加到文件后

  • Concatenate two files:

    cat f1 f2 > fs

  • Input redirection (less common) uses ‘<‘

    wc < years

  • Combine input and output redirection:

    wc < years > year-counts

Editor

vi is a text editor.

vi shows you part of your file and allows you to enter commands that change something

  • 命令模式:移动光标,移动到文件的不同部分,发出编辑命令,切换到插入模式。

  • 插入模式:无论你输入什么都将被放入文件中(不解释为命令)。

光标移动命令in command mode
image-20230307111104333 image-20230307111141723

Scrolling Commands

image-20230307111204133

delete stuff

image-20230307111241745

Changing Text

image-20230307111257431
Insert Mode

image-20230307111339091

要退出插入模式(回到命令模式),按下“Esc”(escape键)。

有一个状态行(屏幕底部),告诉你你在什么模式/命令

Copy & Paste

p paste text last copied to the right of the cursor

yy copy current line

ye copy from the cursor to the end of the word

Searching and Replacing

/textsearch forward for text

?textsearch backward for text

image-20230307111640009
Saving and Exiting
image-20230307111810994

Other commands

chmod

image-20230307111858754 image-20230307112008255 image-20230307112059245

image-20230307112135833

image-20230307112144345