互联网应用笔记(三)
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
ssh student@127.0.0.1 2000:远程联机
rz:上传文件
sz x:下载文件
Typing Commands
date:Gives time and date
cal 3 1997:Calendar
who
pwd 当前路径
ifconfig
man cal: Manual pages
uptime
Machine’ s ‘ up ’ time
显示系统已经运行了多长时间、当前登入用户数量、过去1分钟、5分钟、15分钟内的负载信息。
hostname
Name of the machine
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
Changing your Password
passwd:
System Directories 文件操作
home directory, which is named after your login ID.
pwd showing current directory
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
Working with Directories
Moving between Directories
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
..是上一级目录
../proj2 is a relative pathname
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
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
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
Scrolling Commands
delete stuff
Changing Text
Insert Mode
要退出插入模式(回到命令模式),按下“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
Saving and Exiting
Other commands
chmod