ocp培训第一天

redhat  2days

Oracle sql 2days

----------------------------------------

环境:Red Hat Enterprise Linux 5.6

package:fonts-chinese-3.02-12.el5.noarch.rpm

                   telnet-server-0.17-38.el5.i386.rpm
                   vsftpd-2.0.5-10.el5.i386.rpm

                   xinetd-2.3.14-10.el5.i386.rpm

电脑是windows系统,使用虚拟机;

---------------------------------------------装linux时候必须指定/目录和swap空间大小

VMware Workstation

root/zte123  shjd/shjd123

1、RedHat  Training Course.ppt

--------------------------------------------

/home/shjd  --绝对路径

home/shjd --相对路径

2、Linux_Dir.xls

-------------------------------------------

--linux查看ip:ifconfig

Login

telnet XXX.XXX.XXX.XXX

login:(username)

password:(userspassword)

n Logout

exitor logout

Ctrl+d

使用putty,ssh登录

------------------------------------------

查看etc/passwd是文件夹还是文件

cat etc/passwd


root:x:0:1:SuperUser:/root:/bin/bash

用户名:加密后密码:Uid:Gid(bash显示当前是bash模式或sh模式)

name:password:uid:gid:comment:home:shell

----------------------------------

cd ..返回上一层

cd 回到用户的home

cd ~ 回到用户的home

cd ../.. 返回上一层的上一层

cd -    退回

pwd   ---- Display the absolute pathname of the current directory


ls a  ---- Displaying hidden files   (Hiddenfile: a file started with a “.”)
ls Displayinga recursive listing文件夹内的文件也都显示出来
ls Sortsby time stamp instead of by name
ls Displayinga long list
ls -ld 按长格式显示当前目录

    -rwxr-xr-x   4    usernobody 1024 Feb 22 09:20 a.txt

  文 属   属  其         硬    属     属         大      最后一次         文件                              链

  件             它           接                         小       修改时间        

  类  主  组  人           数    主     组                                 

  型  权  权  权

       限  限  限

ls Displaying file types( 文件类型在文件后面加个‘.file_type’

文件类型:目录文件 

                  可执行文件 

                  文本文件  (none)

-读权限

-写权限,对目录来说,可生成文件与子目录或删除文件与子目录

-执行权限,对目录来说,可进入该目录

-没有权限   

         -rw-r--r

     属 

            它

  主  组  人

其中 属主-生成文件时登录的人,权限最高, u表示

      属组-系统管理员分配的同组的一个或几个人, g表示

      其它人-除属主,属组外的人, o表示

      所有人-包括属主、属组及其它人, a表示


chmod修改文件权限

    chmod g-r file1

    chmod u+x,go+r file1

    chmod a=rw file1

    chmod -R 修改文件夹权限

或者用数字来修改权限

chmod 777 filename 相当于chmod a=rwx filename

 chmod ---to modify the owner of a file or a director
$chmod username.groupname filename
$chmod -R username.groupname directorname
 

 

groupadd & useradd

添加的组id默认为500以外

$groupadd test 添加test组

$useradd -g test tester 添加tester用户

$passwd tester 为tester用户添加密码

----cd home 新增的用户在home下

ls  查看用户

一个用户可以被多个组管理

$usermod -G groupname username user 添加到一个 group

groupdel

    $groupdel groupname

userdel (可删除用户帐号与相关的文件。若不加参数,则仅删除用户帐号,而不删除相关文件。)

   $userdel [-r] username (-r  删除用户登入目录以及目录中所有文件。)

 

usermod 修改user的/etc/password和shadow的信息

usermod -G group user 把user添加到一个新的group中

newgrp gourp 切换到另外一个所属组中

id 显示用户以及所属群组的实际与有效ID。若两个ID相同,则仅显示实际ID。若仅指定用户名称,则显示目前用户的ID。

用法: id [-gGnru][--help][--version][用户名称]

参  数:
 -g或--group  显示用户所属群组的ID。
 -G或--groups  显示用户所属附加群组的ID。
 -n或--name  显示用户,所属群组或附加群组的名称。
 -r或--real  显示实际ID。
 -u或--user  显示用户ID。
 -help  显示帮助。
 -version  显示版本信息。

--------------------------------------

pwck grpck 检查/etc/passwd、group的信息
为什么要存在shadow文件?pwconv pwunconv

--------------------------------------

touch--creat new ,empty files or update access and modification times
 
touch filename(s)

--------------------------------

mkdir

Create directories using either an absolute or a relative pathname
Must have the appropriate permissions to create a directory

用法:

mkdir [-p] directory_name

 mkdir dir1/dir2  (相对路径dir1已存在,否则报错。)
 mkdir dir3 dir4 dir5
 mkdir ~/games
 mkdir -p dir6/dir7/dir8 (-p 确保目录名称存在,如果目录不存在的就新创建一个)

 

cp 

1,Copy files

用法:
 cp  source_file destination_file  (source会把target_file覆盖掉,覆盖前会有提示)
 cp source_file(s) destination_directory 

 cp beans apple
 cp beans apple dir2

2,Copy a directory and its contents to another directory
 用法:

 cp -r source_directory(s) destination_directory

 cp -r dir3 dir4
 cp -r dir3 dir4 /tmp

 

mv

Move or rename files and directories

用法:

 mv source target_file  (source会把target_file覆盖掉,覆盖前会有提示)
 mv source target_directory (source文件被移到目标文件夹中)

 mv nuts beans
 mv /export/home/jerry/brands  ~
 mv dir5 dir6

rm & rmdir

1,Remove files

用法:
 rm filename(s)
 rm file1 file2 file3
 rm file1

2,Removing Directories

用法:
 rmdir directory_name(s)
 rm -r directory_name(s)
 rmdir empty_dir
 rm –r dir6
注:rmdir (一个或多个)空目录名    (删除空目录)
       rm -r (一个或多个)目录名      (递归删除非空目录)

du

View the size of the file or director.

用法:

查看文件大小:du -h filename

查看文件夹大小:du -hs dirname

 

tar

打包:tar -cvf ***.tar filename

解压:tar -xvf ***.tar [-C] dir (-C转到指定目录)

查看包中详细信息:tar -tvf ***.tar

说明:c ---creat

           v ---verbose

           f ----file 使用档名,请留意,在f之后要立即接档名,不要再加参数

           x ---extract

history

 Display the history of executed commands
用法:

$ history
    [root@localhost ~]$ history
    1  vi f1
    2  vi f2
    3  cp f1 f2
To execute the history command
    [root@localhost ~]$ !num

 

sort

uniq

diff

wc

cat

more

head 

tail
find

grep

--------------------------

可通过以下方式查看命令的用法

man,info,whatis,help

The Linux Manpages describes information about the system’s on-line commands, system calls, file formats, and system maintenance
用法:

man name
man –k keyword

Scrolling in Manpages
   Spacebar Scroll through a manual page one screen at a time
用法:

Return      Scroll through a manual page one line at a time
b   Move back one screen
f                Move forward one screen
q   Quit the man command
/string Search forward for information
n   Find the next occurrence of string

 

--------------------------

metacharacters

 

*

Represents zero or more characters

例:

ls d*  列出所有d开头的文件

 

Represents any single character

例:

ls d? 列出所有以d开头,文件名为2位的文件

ls z?.txt 列出所有以d开头,文件名为2位的txt文件

 

[ ]

match a set or range of characters to a single character position

例:

ls [b-f]b*

ls [fF]*a?c

注:ls [a-F] 列出aAbBcCdDeEfF的相关文件

-------------------------------

date 显示当前时间

cal  显示本月日历(cal 2013 显示2013年日历)

pwd  显示当前所在目录

-------------------------------

tab

type Tab to complete command lines:

1,For the command name,it will complete a command name;

2,For an argument ,it will complete a file name.

用法:

$xte<tab>

$xterm

$ls myf<tab>

$ls myfile.txt

------------------------------------------

text viewer or editor

cat

1,Displays the contents of a text file on screen
2,Is often used to join two or more files into one large file

例:

cat file

cat file1 file2    (file1和file2的内容都显示)

 

more

Displays the contents of a text file one screen at a time 一次把文件内容都显示出来

例: 

more filename(s) 

 

Spacebar  Scroll to the next screen
Return  Scroll one line at a time
b    Move back one screen
f                Move forward one screen
h    Display a Help menu of more features
q    Quit and return to the shell prompt
/string Search forward for string
n    Find next occurrence of string

head and tail

head: Display the first 10 lines of a file
   Use -n to change number of lines displayed
tail: Display the last 10 lines of a file
   Use -n to change number of lines displayed
   Use -f to "follow" subsequent additions to the file,Very useful for monitoring log files!

用法: [root@localhost ~]$ head  -10  file
            [root@localhost ~]$ tail  -10  file
            [root@localhost ~]$ tail  –f  file  文件有写入东西即显示出来

---------------------------

vi-line和command-line的转换

vi-〉command : 先按esc,然后输入对应的命令  (:和/和?都可)

 

command->vi :先 vi filename,用 i,a,o,O都可进入编辑

----------------------------

vi编辑使用的相关命令:

1,position

   向上  k         向下  j
   向左  h         向右  l
   行首  ^         行尾  $
   文件尾  G    文件首  1G
   第N行  nG
   屏幕头  H     屏幕中  M
   屏幕底  L
   下翻  Ctrl+f   上翻  Ctrl+b

2,input

  i 在光标当前位置插入
 a 在光标所在位置后插入
 o 在光标所在行下插入一空行
 O  在光标所在行上插入一空行

 <Esc> 退出插入状态

3,deleting text

 x 删除一个字符
 dw 删除当前词
 3dw 删除三个词
 dd 删除当前行
 5dd 删除从当前行开始的五行
 :5,10d  删除第5行到第10行

4,changing text

   r 替换一个字符
   cw 替换一个单词
   cc 替换一行
   C 替换从光标至行尾

 

5,coping and pasting text

yw   拷贝词
yy   拷贝行(或Y)
dw   剪切词
dd   剪切行
p  当前行下粘贴
:1,2co3  拷贝行1,行2在行3之后
:4,5m6  移动行4,行5在行6之后

 

6,saving and quitting files

 :w  存盘
 :w newfile 存成新文件
 :wq   存盘退出Vi(或ZZ,或:x)
 :q!   强行退出不存盘

7,advanced editing options

~            改变大小写
J            把当前行和下一行连起来
u            废除刚才的编辑操作(undo)
:set nu            显示行代码 (:set nonu)
:21            光标停在指定行
21G            光标停在指定行 (G 到文件尾,1G 到文件头)
/串            从当前行往下查找
?串            从当前行往上查找
n            查找继续

 

8,find

 find [directory...] [criteria...]
 May only search directories where the user has read and execute permission
 CWD is used if no starting directory given
  All files are matched if no criteria given

方法:

find /home -name snow.png
   Search for files named snow.png
find -iname snow.png
   Case-insensitive search for files named snow.png,Snow.png, SNOW.PNG, etc
find -user joe -group joe
   Search for files owned by the user joe and the group joe
find -perm 755
   matches if mode is exactly
find /etc -type d
   all dirs in /etc

9,grep

Prints lines of files or STDIN where a pattern is matched
  $ grep 'john' /etc/passwd
  $ date --help | grep year
Use -i to search case-insensitively
Use -n to print line numbers of matches
Use -v to print lines not containing pattern (例:$grep -v 'john'  /etc/passwd   结果中去掉了带john的那些行)

10,other text command

cut
     cut是一个选取命令,就是将一段数据经过分析,取出我们想要的。一般来说,选取信息通常是针对“行”来进行分析的,并不是整篇信息分析的。
cut [-b n] [file] 或 cut [-c n] [file] 或 cut [-df] [file]
主要参数

-b :以字节为单位进行分割。

-c :以字符为单位进行分割。

-d :自定义分隔符,默认为制表符。

-f :与-d一起使用,指定显示哪个区域。
cat /etc/passwd | cut -b 1

 cut -c 1 text.txt

cat /etc/passwd|cut -d : -f 1

sort

sort将文件的每一行作为一个单位,相互比较,比较原则是从首字符向后,依次按ASCII码值进行比较,最后将他们按升序输出。
-u 就是在输出行中去除重复行。

 -r 默认的排序方式是升序,-r改成降序,

-o 把排序结果输出到原文件中,用重定向可就不行了。
sort -r number.txt > number.txt

 sort -r number.txt -o number.txt

 

uniq

uniq的作用是过滤重复部分显示文件内容,这个命令读取输入文件,并比较相邻的行。在正常情况下,第二个及以后更多个重复行将被删去,行比较是根据所用字符集的排序序列进行的。
-c 参数显示文件中每行连续出现的次数。

-d选项仅显示文件中连续重复出现的行。

-u选项显示文件中没有连续出现的行。

 

diff

为逐行比较两个文本文件,列出其不同之处。它对给出的文件进行系统的检查,并显示出两个文件中所有不同的行,不要求事先对文件进行排序。

 例:   diff userinfo userinfo.bak
  会显示出userinfo中哪些行不一样,存放在userinfo.bak中,位置要自己找

 

wc

 - c 统计字节数。

 - l 统计行数。

 - w 统计字数。

  行数、字数、字节数、文件名


  wc filename
  显示 行数、字数、字节数、文件名


 

 

standard I/O and pipes

 

---------------

$ cat  <  file
$ cat  < file1  >  file2 
----------------

     >  Redirect STDOUT to file
    2> Redirect STDERR to file
    &> Redirect all output to file
File contents are overwritten by default. >> appends.

注:script 记录所有的操作,做完要记得exit

This command generates output and errors when run as non-root:
   $ find /etc -name passwd
Operators can be used to store output and errors:
   $ find  /etc -name passwd  >  find.out
   $ find  /etc -name passwd  2>  find.out
   $ find  /etc -name passwd  &>  find.out
Write the contents to file
   $ echo  “Hello, World”  >  ~/hello.txt
   $ echo  “Hello, Bay”  >>  ~/hello.txt
Clean the contents of file
   $ cat  /dev/null > ~/hello.txt   或>~/hello.txt

 

Pipes (the | character) can connect commands:
    command1   |  command2
  Sends STDOUT of command1 to STDIN of command2 instead of the screen.
  STDERR is not forwarded across pipes
Used to combine the functionality of multiple tools
  command1 | command2 | command3... Etc

 

$ ls -l /etc | more
$ cat /etc/passwd  |  grep root
$ echo “test print” | lpr  交给打印机打印

Changing Identities

 

su - creates new shell as other users

who:显示关于登录到本地系统的所有当前用户的信息。 格式:用户名  伪终端号  登陆时间  本地ip地址。
who am i:是显示关于你真实用户ID的信息。
whoami:只显示有效用户的登录名称。

homework:


 day_01.word

 

echo &HOME

 

questions

为什么要存在shadow文件?

---------------

$ cat  <  file
$ cat  < file1  >  file2 
---------------

 


 


 


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值