Red hat Linux 第四章
RH linux study
学习记录:
cd - 返回上次操作的目录!
经典命令 :
cd my_seller/mystery_chapter[...] ../?
.. 可以代表上一个目录!
. 指的是当前目录!
-`+ %S` 中内容先执行!!
-$USER
~ 家目录!
:
Info * 表示链接
u 返回
p 进去
第四章
> 重定向(覆盖)
>> 追加 !(留着原来的!!!)
& 全部 ````````
2 错误的
[kiosk@foundation4 Desktop]$ find /etc -name passwd>../Desktop/1.txt
??
/dev/null 系统垃圾箱
“| ”管道符 对一个命令的结果进行处理 !
2&>1 错的变成 对的!!
` ************************
> 和 2>&! 的 位置关系!!!
前和后有区别!!!
> 2> 分开执行!!
Vim 使用:
:help 显示帮助
:q 退出
:set nu
: / str 查找
Ctrl+V 高亮模式 选中 ,
Delete 可以删除 !
u 找回删除 !
进入高亮模式 选中 行首 按 I(大写的 i) ; 变为输入模式 输入 # 按 ESC
Ctrl +W 后 N / V
自己查看神奇的效果!!!
第二章 (请再看一下历史记录,第二章课后练习题) s 2014. ---- 阿修
Lab 1
要求创建12个文件,
文件名为tv_seasonX_episodeY.ogg
命令为:touch tv_season{1,2}_episode{1..6}.ogg
Lab 2
创建8个文件,文件名为mystery_chaptreX.odf X 是(1~8)
命令 touch mystery_chaptre{1..8}.odf 实现,例图:
Lab 3
使用一个命令在用户的Vedios 目录下新建两个文件夹 season1 和 season2
命令为: mkdir /home/用户名/Vedios/season{1..2}
Lab 4
将Lab 1 新建的文件,移入 Lab 3 文件中 。 使用两个命令 :
mv /home/用户/Destop/tv_season1* /home/用户/Vedios/season1
mv /home/用户/Destop/tv_season2* /home/用户/Vedios/season2
Lab 5
询问!!!!
新建内嵌目录/Documents/my_bestseller
新建目录 cp 时 -b touch 时 -b 看用法
Lab 6
在my_bestseller 目录下使用一个命令创建3个子目录。
mkdir 指定绝对路径my_bestseller/{editor plot_change vacation}
Lab 7
在桌面
mv mystery_chapter* /home/hejiahao/Documents/my_bestseller
Lab 8
在 Documents 下:
cp chapters/mystery_chapter[1-2] my_bestseller/editer
Lab 9
将7 8 chapter 移动到 vocation 中 不用通配符
cp Documents/chapters/mystery_chapter7 my_bestseller/vocation
cp Documents/chapters/mystery_chapter8 my_bestseller/vocation
Lab 10
一个命令,改变工作目录到2季的电视剧集的位置,然后链接(而不是复制)本季的第一集的“vocation”目录。
mv season* 可以移动
ln -s /home/用户/Documents/season /season1 /home/用户/Documents/my_bestseller/vocation/season1.ln
生成一个链接。。。
Lab 11
With one command, change the working directory to "vacation", then list its previous working directory shortcut. This will succeed if the last directory change was accomplished with one command. Link the episode 2 file into "vacation". Return to "vacation" using the shortcut again
一个命令,改变工作目录的“vocation”,然后列出其先前的工作目录的快捷方式。这将如果最后的目录的变化与一个命令成功完成。2集文件链接到“vocation”。返回“vocation”,再次使用的快捷方式
Lab 12
Chapters 5 and 6 may need a plot change. To prevent these changes from modifying original files, copy, not link, both files into "plot_change". Move up one directory to "vacation's" parent directory, then use one command from there
chapter5和chapter6可能需要一个情节的变化。为了防止这些变化修改原始文件,复制,不链接,移动两个文件到“plot_change”。一个目录移动到“vocation”的子目录,然后用一个命令从实现
Lab 13 To track changes, save each version as a new file name to include the date. Change to the "plot_change" directory. Copy "mystery_chapter5.odf",appending the current timestamp (as the number of seconds since the epoch) to ensure a unique file name. See the solution for syntax. Also make a copy appending the current user ($USER) to the file name.
跟踪变化,保存每个版本作为一个新的文件名包含日期。改为“plot_change”目录。复制“mystery_chapter5。ODF”,将当前的时间戳(如以来的秒数时代)以确保一个独特的文件名。看语法的解决方案。也使一份添加当前用户(用户名)为文件名。
Lab 14
The plot changes were not successful. Delete the "plot_change" directory. First, delete all of the files in the "plot_change" directory. Change directory up one level because the directory cannot be deleted while it is the working directory. Try to delete the directory using the "rm" command without the recursive option. This attempt should fail. Now use the "rmdir" command, which will succeed.
剧情的变化是不成功的。删除“plot_change”目录。第一,删除所有的文件在“plot_change”目录。将目录更改到上一级目录不能因为在工作目录中删除。尽量不使用递归选项“RM”命令删除目录。这种尝试会失败。现在使用的“删除”命令,将成功。
英文原版:第四章!
UNIT 4
Creating, Viewing, and Editing Text Files
www.westos.org
Objectives
Redirect the text output of a program to a file
or to another program.
Edit existing text files and create new files
from the shell prompt with a text editor.
Copy text from a graphical window to a text
file using a text editor running in the
graphical environment.
www.westos.org
Standard input, standard output, and standard
error
Channels (File Descriptors)
www.westos.org
Redirecting output to a file
Output Redirection Operators
www.westos.org
Examples for output redirection
[student@desktopX ~]$ date > /tmp/saved-timestamp
[student@desktopX ~]$ tail -n 100 /var/log/dmesg > /tmp/last-100-boot-
messages
[student@desktopX ~]$ cat file1 file2 file3 file4 > /tmp/all-four-in-one
[student@desktopX ~]$ ls ~/.* > /tmp/my-configuration-file-names
[student@desktopX ~]$ echo "new line of information" >> /tmp/many-lines-of-
information
[student@desktopX ~]$ diff previous-file current-file >> /tmp/tracking-changes-
made
[student@desktopX ~]$ find /etc -name passwd 2> /tmp/errors
[student@desktopX ~]$ find /etc -name passwd > /tmp/output 2> /tmp/errors
[student@desktopX ~]$ find /etc -name passwd > /tmp/output 2> /dev/null
[student@desktopX ~]$ find /etc -name passwd &> /tmp/save-both
[student@desktopX ~]$ find /etc -name passwd >> /tmp/save-both 2>&1
www.westos.org
Constructing pipelines
Redirection controls channel
output to or from files while
piping sends channel output to
another process
Tee
www.westos.org
Practice: I/O Redirection and Pipelines Quiz
Questions
1.Display command output to terminal, ignore all errors.
2.Send command output to file; errors to different file.
3.Send output and errors to the same new, empty file.
4.Send output and errors to the same file, but preserve existing file
content.
5.Run a command, but throw away all possible terminal displays.
6.Send command output to both the screen and a file at the same
time.
7.Run command, save output in a file, discard error messages.
www.westos.org
Answer
2>/dev/null
>file 2>file2
&>file
>>file 2>&1
&>/dev/null
| tee file
>file 2>/dev/null
www.westos.org
Editing Text Files from the Shell Prompt
Vim
– Vim is an improved version of the vi editor
distributed with Linux and UNIX systems. Vim is
highly configurable and efficient for practiced
users, including such features as split screen
editing, color formatting, and highlighting for
editing text.
www.westos.orgMoving between Vim modes
command mode
insert mode
exit mode
www.westos.orgCommand mode
:help
:set
ctrl + v
ctrl+w -s
ctrl+w -v
ctrl+w -c
:sed 's/words/replace/g'
y
– yy,y[x]y
d
– dd,d[x]d
c
– cc,c[x]c
p
www.westos.orgInsert mode
A
a
I
i
O
o
S
s
www.westos.org
Exit mode
:q
:q!
:wq
:wq!
www.westos.org
The help for vim
vimtutor
[student@serverX ~]$vimtutor
www.westos.org
Editing files with gedit
Applications → Accessories → gedit
File → New (Ctrl-n)
File → Save (Ctrl-s)
File → Open (Ctrl-o)
Ctrl-x
Ctrl-c
Ctrl-v
www.westos.org
The help for gedit
gedit man page
[student@serverX ~]$ yelp help:gedit
www.westos.org
Lab
Redirect a long listing of all content in student's home directory, including
hidden directories and files, into a file named editing_final_lab.txt. Your home
directory files may not exactly match those shown in the example graphics.
Theis lab edits arbitrary lines and columns. The important outcome is to
practice the visual selection process.
Edit the file using Vim, to take advantage of visual mode.
Remove the first three lines, since those lines are not normal file names. Enter
line-based visual mode with upper case V
Remove the permission columns for group and world on the first line. In this
step, enter visual mode with lower case v, which allows selecting characters
on a single line only.
www.westos.orgLab
Remove the permission columns for group and world on the remaining lines.
This step will use a more efficient block selection visual mode to avoid having
to repeat the single line edit multiple times. This time, enter visual mode with
the control sequence Ctrl-v, which allows selecting a block of characters on
multiple lines
Remove the group owner column, leaving only one "student" column on all
lines. Use the same block selection technique as the last step.
Remove the time column, but leave the month and day on all lines. Again, use
the block selection visual mode.
Remove the Desktop and Public rows. This time, enter visual mode with upper
case V, which automatically selects full lines.
Save and exit. Make a backup, using the date (in seconds) to create a unique
file name.
www.westos.orgLab
Mail the file contents as the message, not an p_w_upload, to the user student
Append a dashed line to the file to recognize the beginning of newer content.
Append a full process listing, but only for processes owned by the current
user student and running on the currently used terminal. View the process
listing and send the listing to the file with one command line.
欢迎评论,提出观点。 转载请说明出处,谢谢~
如果大家想了解更多请关注微信公众号“IT那些事”(ID: haoyuwl)