Linux常用管理命令(二)

(1)练习命令行模式下的常用命令:
man:命令帮助
ALT-Fx:虚终端切换
常用命令:cat、ps、chmod、chown、kill、ln、who、whoami、date、uname等

root@ubuntu:/# cat sample.txt   #cat 命令用于连接文件并打印到标准输出设备上。
High 
A
A
High aaa bbb ccc High
root@ubuntu:/# ps   #ps命令用于显示当前进程 (process) 的状态。
  PID TTY          TIME CMD
 2351 pts/0    00:00:00 su
 2359 pts/0    00:00:00 bash
 2506 pts/0    00:00:00 ps
xushicheng@ubuntu:/$ ls -l /testchmod
-rw-r--r-- 1 root root 0 2019-05-27 05:12 /testchmod
xushicheng@ubuntu:/$ sudo chmod 777 testchmod    #chmod给文件设置相应权限
xushicheng@ubuntu:/$ ls -l /testchmod
-rwxrwxrwx 1 root root 0 2019-05-27 05:12 /testchmod
xushicheng@ubuntu:/$ sudo chown root testchown   #利用 chown 将指定文件的拥有者改为指定的用户或组
xushicheng@ubuntu:/$ su
Password: 
root@ubuntu:/# ps   # su命令用于变更为其他使用者的身份,除 root 外,需要键入该使用者的密码。
  PID TTY          TIME CMD
 2622 pts/0    00:00:00 su
 2631 pts/0    00:00:00 bash
 2641 pts/0    00:00:00 ps
root@ubuntu:/# kill 2622   #kill命令用于删除执行中的程序或工作。
root@ubuntu:/# 
Session terminated, killing shell... ...killed.
xushicheng@ubuntu:/$
root@ubuntu:/# ln -s testln link_testln    //将testln与link_testln建立软链接
root@ubuntu:/# ls
bin    etc         link_testln  opt         sbin     testchmod  usr
boot   home        lost+found   proc        selinux  testchown  var
cdrom  initrd.img  media        root        srv      testln     vmlinuz
dev    lib         mnt          sample.txt  sys      tmp
root@ubuntu:/# ln testln link2_testln    //将testln与link2_testln建立硬链接
root@ubuntu:/# ls
bin    etc         link2_testln  mnt   sample.txt  sys        tmp
boot   home        link_testln   opt   sbin        testchmod  usr
cdrom  initrd.img  lost+found    proc  selinux     testchown  var
dev    lib         media         root  srv         testln     vmlinuz
root@ubuntu:/#
root@ubuntu:/# who
xushicheng tty1         2019-05-27 05:05
xushicheng tty7         2019-05-27 04:10 (:0)
xushicheng pts/0        2019-05-27 05:32 (:0.0)
root@ubuntu:/# whoami
root
root@ubuntu:/# date
Mon May 27 05:47:10 PDT 2019
root@ubuntu:/# uname
Linux

(2) 编辑器vi的使用:使用vi建立并修改一个文本文件

root@ubuntu:/# vi testvi
root@ubuntu:/# cat testvi
Hello Vi,vi is the best edit...
root@ubuntu:/# vi testvi
root@ubuntu:/# cat testvi
Hello Vi,Vi is the best edit...

(3) 档案管理
gzip
找一个文件对它进行使用gzip压缩。

root@ubuntu:/# touch testgzip
root@ubuntu:/# vi testgzip
root@ubuntu:/# ls
bin    home          lost+found  root        sys        testvi
boot   initrd.img    media       sample.txt  testchmod  tmp
cdrom  lib           mnt         sbin        testchown  usr
dev    link2_testln  opt         selinux     testgzip   var
etc    link_testln   proc        srv         testln     vmlinuz
root@ubuntu:/# gzip testgzip
root@ubuntu:/# ls
bin    home          lost+found  root        sys          testvi
boot   initrd.img    media       sample.txt  testchmod    tmp
cdrom  lib           mnt         sbin        testchown    usr
dev    link2_testln  opt         selinux     testgzip.gz  var
etc    link_testln   proc        srv         testln       vmlinuz
root@ubuntu:/#

tar
找一个文件对它进行使用tar压缩和解压缩。

root@ubuntu:/# touch testtar
root@ubuntu:/# vi testtar
root@ubuntu:/# ls
bin    home          lost+found  root        sys          testtar  vmlinuz
boot   initrd.img    media       sample.txt  testchmod    testvi
cdrom  lib           mnt         sbin        testchown    tmp
dev    link2_testln  opt         selinux     testgzip.gz  usr
etc    link_testln   proc        srv         testln       var
root@ubuntu:/# tar cvfz mytesttar.tgz testtar
testtar
root@ubuntu:/# ls
bin    initrd.img    mnt            sbin       testgzip.gz  var
boot   lib           mytesttar.tgz  selinux    testln       vmlinuz
cdrom  link2_testln  opt            srv        testtar
dev    link_testln   proc           sys        testvi
etc    lost+found    root           testchmod  tmp
home   media         sample.txt     testchown  usr
root@ubuntu:/# tar xvfz mytesttar.tgz
testtar

unzip
找一个文件对它进行使用unzip解压缩。

root@ubuntu:/# touch testunzip
root@ubuntu:/# vi testunzip
root@ubuntu:/# ls
bin    initrd.img    mnt            sbin       testgzip.gz  usr
boot   lib           mytesttar.tgz  selinux    testln       var
cdrom  link2_testln  opt            srv        testtar      vmlinuz
dev    link_testln   proc           sys        testunzip
etc    lost+found    root           testchmod  testvi
home   media         sample.txt     testchown  tmp
root@ubuntu:/# zip mytestunzip testunzip
  adding: testunzip (stored 0%)
root@ubuntu:/# ls
bin    initrd.img    mnt              sample.txt  testchown    tmp
boot   lib           mytesttar.tgz    sbin        testgzip.gz  usr
cdrom  link2_testln  mytestunzip.zip  selinux     testln       var
dev    link_testln   opt              srv         testtar      vmlinuz
etc    lost+found    proc             sys         testunzip
home   media         root             testchmod   testvi
root@ubuntu:/# unzip mytestunzip
Archive:  mytestunzip.zip
replace testunzip? [y]es, [n]o, [A]ll, [N]one, [r]ename: A
 extracting: testunzip               
root@ubuntu:/# ls
bin    initrd.img    mnt              sample.txt  testchown    tmp
boot   lib           mytesttar.tgz    sbin        testgzip.gz  usr
cdrom  link2_testln  mytestunzip.zip  selinux     testln       var
dev    link_testln   opt              srv         testtar      vmlinuz
etc    lost+found    proc             sys         testunzip
home   media         root             testchmod   testvi

(4) 网络命令
telnet、ftp、talk

root@ubuntu:/# telnet www.baidu.com
Trying 183.232.231.174...
Trying 183.232.231.172...
telnet: Unable to connect to remote host: Connection timed out
root@ubuntu:/# ftp ls 134.175.56.227
ftp: ls: Unknown host