The Knowledge of Linux-.-Day01

来源:互联网 发布:淘宝卖家怎么设置特价 编辑:程序博客网 时间:2024/05/17 04:43
  1. 怎么管理虚拟机

    rht-vmctl start desktop    //启动desktop虚拟机
    rht-vmctl poweroff desktop    //关闭虚拟机
    rht-vmctl view desktop      //显示虚拟机
    rht-vmctl reset desktop        //重置虚拟机

  2. 登录虚拟机
       student      key:student
       root            key:redhat

  3. 怎么加入中文输入法

    Applications  ->System Tools  ->Settings  ->Region&Language

  4. Linux是一个操作系统的内核
    常见Linux:  centos,ubuntu,redhat,kail…
    应用于服务器,Linux内核的安卓系统
    开源,稳定

  5. 学习网站
    牛客网,慕课网,网易云课堂,学堂在线
    申请博客:5lcto,csdn

  6. shell
    保护操作系统;与操作系统进行交互
    the bash shell:

    [用户名 分隔符 主机名 当前工作目录]身份提示符
    eg. [kiosk@foundation121 Desktop]$
         [root@foundation121 ~]#

        身份提示符:
       root   #
       普通用户  $
        切换用户:

        su -l 用户名

        虚拟控制台:
   Ctrl+Alt+F(1|7)      进入图形
   Ctrl+Alt+F(2~6)  进入虚拟控制台
   
        四个工作界面:
   Ctrl+Alt+方向键   互相切换
   
7. 命令基本格式
    命令一般格式:
          命令 参数 目标
    命令帮助:
        - -help    或 whatis     或 man

    []       可省略
    …      可加多个
    <>    必须添加

    常用命令:
    date,passwd,cal,gedit,cat,head,tail,wc,file,history

-date-
Usage: date [OPTION]…[+FORMAT]
  or: date [-u|–utc|–universal] [MMDDhhmm[[CC]YY][.ss]]
Display the current time in the given FORMAT,or set the system date.
eg. date +%F    //full date;same as %Y-%m-%d
      date +%y        //last two digits of year(00..99)
      date +%Y    //year
这里写图片描述

这里写图片描述

-passwd-
Usage: passwd [options] [LOGIN]
eg. passwd -S student       //report passwd status on the named account (root only)
      passwd -l student        //lock the password of the named account (root only)
      passwd -u student       //unlock the password of the named account (root only)
      passwd -d student       //delete the password for the named account (root only)
      passwd -n 1 student        //minimum password lifetime (root only)
      passwd -x 99999 student   //maximum password lifetime (root only)
      passwd -w 4 student       //number of days warning users receives before password expiration (root only)
      passwd -i 6 student        //number of days after password expiration when an account becomes disabled (root only)
这里写图片描述

这里写图片描述

这里写图片描述

这里写图片描述

-chage-
Usage: chage [options] LOGIN
eg. chage -d 0 student        //set date of last passwd change to LAST_DAY.
      chage -m 3 student       //set minimum number of days before password change to MIN_DAYS
      chage -M student          //set minimum number of days before password change to MAX_DAYS
      chage -W 5 student       //set expiration warning days to WARN_DAYS
      chage -I 10 student       //set password inactive after expiration to INACTIVE.
练习 下面用chage命令实现:
1). 实现让student第一次登陆系统时修改密码
chage -d 0 student
2). 实现让student用户不能频繁修改密码,即此次修改密码三天后才能再次修改密码
chage -m 3 student
3). 设置student用户密码警告期为5;
chage –warndays 5 student
4). 设置student用户非活跃期为10;
chage -I 10 student

-gedit-
Usage: gedit [OPTION…] [FILE] [+LINE[:COLUMN]]
eg. gedit westos

-cat-
Usage: cat [OPTION]… [FILE]…
Concatenate FILE(s) to standard output.
eg. cat westos

-head-
Usage: head [OPTION]…[FILE]…
Print the first 10 lines of each FILE to standard output.
With more than one file,precede each with a header giving the file name.
With no FILE,or when FILE is -,read standard input.
eg. head -n 3 westos        //print the first NUM lines instead of the first 10;
             with the leading ‘-‘,print all but the last NUM lines of each file.

-tail-
Usage: tail [OPTION]…[FILE]…
Print the last 10 lines of each FILE to standard output.
With more than one FILE,precede each with a header giving the file name.
With no FILE,or when FILE is -,read standard input.
eg. tail -n 3 westos        //output the last NUM lines, instead of the last 10;
            or use -n +NUM to output starting with line NUM.

-wc-
Usage: wc [OPTION]… [FILE]…
    or: wc [OPTION]… –files0-from=F
Print newline, word, and byte counts for each FILE, and a total line if more than one FILE is specified.
A word is a non-zero-length sequence of characters delimited by white space.
With no FILE, or when FILE is -, read standard input.
eg. wc -l westos      //print the newline counts.
      wc -m westos    //print the character counts.
      wc -w westos     //print the word counts.
      wc -L westos      //print the maximum display width.
      wc -c westos      //print the byte counts.
练习 下面用wc命令实现:
1). 查看文件的行数;
wc -l westos
2). 查看文件的字符数;
wc -m westos
3). 查看文件的单词数;
wc -w westos
4). 查看文件的字节数;
wc -c westos
5). 查看文件中最长行的长度(字符数);
wc -L westos

-file-
Usage: file [OPTION…] [FILE…]
Determine type of FILEs.
eg. file westos

8.关机

poweroff 或 shutdown -h now 或 init()

重启

reboot 或 shutdown -r now 或 init 6

9.常用快捷键总结

ctrl+ a        //光标移动到所在行行首
ctrl+ e        //光标移动到所在行行尾
ctrl+ u        //删除光标所在位置以左的内容
ctrl+ k        //删除光标所在位置及其以右的内容
ctrl+ r         //搜索以前执行过的命令
ctrl+ 左|右       //光标移动到上一个或下一个单词的第一位
ctrl+ c         //终结当前程序
ctrl+ d         //删除光标所在位置的内容
ctrl+ shift + t      //打开一个新的终端选项卡
ctrl+ shift + n      //打开一个shell
ctrl+ alt + l        //锁定
ctrl+ alt +上|下     //切换工作页面
ctrl+ shift + pageup  //标签页向右移动
ctrl+shift + pagedown //标签页向左移动

10.对于文件
增加
    gedit
    vim (先按i,进入插入模式,编辑内容,退出时按Esc,:wq)
    touch
删除
    rm -f (-f指强制删除文件)
修改
      移动

mv westos   /mnt
mv /mnt/westos   / root/Desktop/westos1

      复制

cp westos1   /mnt/
cp westos1   /mnt/westos2

      重命名
        mv可实现重命名

      文件内容的修改
        gedit 或 vim

查看:

ls   westos1

    cat,head,tail,file,wc

练习 对于文件的操作
1).在student用户的桌面上创建一文件westosfile,内容任意,至少5行;

vim /home/student/Desktop/westosfile

2).复制文件到root用户的Downloads目录中;

cp /home/student/Desktop/westosfile /root/Downloads/

3).移动root用户的Downloads目录的westosfile文件到/mnt目录下;

mv /root/Downloads/westosfile /mnt/

4).对/mnt目录下的文件westosfile文件重命名为mywestos;

mv /mnt/westosfile /mnt/mywestos

5).删除上述操作所产生的所有文件;

rm -f /home/student/Desktop/westosfile
rm -f /mnt/mywestos

11.对于目录
增加
      mkdir
      mkdir -p         //no error if existing, make parent directories as needed

删除
      rm -fr
      rmdir(只能删除空目录)

修改
目录内容的修改(add/delete dir or fi
目录路径

cd ~           //当前用户的家目录
~student    //student用户的家目录
.                  //当前目录
..                 //当前目录的上一级目录
-                  //回到当前目录上一次所在目录
cp -r            //复制目录
mv               //移动或重命名

查看

ls -R             //list subdirectories recursively
ls -a             //do not ignore entries starting with .
ls -A             //do not list implied . and ..
ls -t              //sort by modification time, newest first
ls -s              //print the allocated size of each file, in blocks
ls -l               //use a long listing format
ls -d              //list directories themselves, not their contents
pwd               //查看当前目录

练习 对于目录的操作
1).切换用户到student用户;

su -l student

2).切换目录到/home/student/Downloads下;

cd /home/student/Downloads

3).在当前目录新建文件hello1/yyy,编辑三行内容;

mkdir hello1
vim hello1/yyy

4).显示该文件的第一行和最后一行;

head -n 1 hello1/yyy
tail -1 hello1/yyy

5).复制目录hello1到/home/student/Desktop目录下;

cp -r hello1 /home/student/Desktop
ls /home/student/Desktop

6).一条命令切换到/home/student/Desktop目录下;

cd /home/student/Desktop

7).将复制过来的目录重命名为hello2;

mv   hello1/   hello2

12.正则表达式

{}     //针对已经存在和未存在的文件均生效,{1..5},{1,3,5}
[]       //只针对已经存在的文件,[1-5],[135],[!34],[^34]
*        //0个或多个字符
?        //代表单个字符
[[:lower:]]   //代表单个小写字母
[[:upper:]]   //代表单个大写字母
[[:alpha:]]   //代表单个字母
[[:digit:]]     //代表单个数字
[[:space:]]    //代表单个空格
[[:alnum:]]   //代表单个数字或字母
[[:punct:]]    //代表单个符号

作业
1.用student用户登陆系统图形界面开机后出现一个登陆界面,选择student用户,输入密码登陆。

2.打开一个bash
方法一:应用程序->收藏->终端 点击打开即可
方法二:单击右键
方法三:Ctrl+Shift+n

3.修改student的密码,把密码更新成”westos“

passwd student

4.显示当前系统时间

date

5.显示当前系统时间,显示格式为:”小时:分钟:秒 AM/PM”(AM/PM为上下午标识)

date +%r

6.显示“/usr/bin/clean-binary-files”的文件类型

file   /usr/clean-binary-files

7.统计“/usr/bin/clean-binary-files”的文件大小

ls   -s    /usr/bin/clean-binary-files

8.用快捷方式在shell中调用已经执行过的第4条命令

!4

9.用快捷方式执行最近一条含有”date”关键字的命令

(reverse-i-search)`’:date +%r

10.用命令和正则表达式按照要求建立文件
*)用一条命令建立12个文件WESTOS_classX_linuxY(X的数值范围为1-2,Y的数值范围为1-6)
*)这些文件都包含在root用户桌面的study目录中

touch   WESTOS_class{1,2}_linux{1..6}   /root/Desktop/study

*)用一条命令建立8个文件redhat_versionX(x的范围为1-8)
*)redhat_virsionX这些文件都包含在/mnt目录中的VERSION中

touch   redhat_version{1..8}   /mnt/VERSION

11.管理刚才信建立的文件要求如下
*)用一条命令把redhat_versionX中的带有奇数的文件复制到桌面的SINGLE中

cp   /mnt/VERSION/*{1,3,5,7}*   /root/Desktop/SINGLE

*)用一条命令把redhat_versionX中的带偶数数的文件复制到/DOUBLE中

cp   /mnt/VERSION/*{2,4,6,8}*   /root/Desktop/DOUBLE

*)用一条命令把WESTOS_classX_linuxY中class1的文件一动到当前用户桌面的CLASS1中

mv   /root/Desktop/study/WETOS_class{1}*   /root/Dektop/CLASS1

*)用一条命令把WESTOS_classX_linuxY中class2的文件一动到当前用户桌面的CLASS2中

mv   /root/Desktop/study/WETOS_class{2}*   /root/Dektop/CLASS2

12.备份/etc目录中名字带有数字并且以.conf结尾的文件到桌面上的confdir中;

cp    /etc/*[[:digit:]]*.conf     /root/Desktop/confdir

1 0
原创粉丝点击