linux:命令行操作及常用命令使用,linux常用命令
linux:命令行操作及常用命令使用,linux常用命令
1.1命令行操作1.1.1 Shell简介
在学习shell之前我们先来了解什么是Shell,Shell能完成的功能是什么,常见的shell的类型是什么?为什么用使用Shell?
Shell是用户和Linux操作系统之间的接口,在百科中shell俗称壳(用来区别于核),是指“提供使用者使用界面”的命令解析器。类比有DOS中的command和windows常见的cmd。用来接收用户的命令,然后调用相应的应用程序。
这里我们说的是Linux底下的Shell,Linux有很多种的Shell,其中常见的就是我们经常使用的bash。
在企业中部署的服务器亦或是linux大白,大牛使用的Linux系统中,基本使用的都是最小化安装,完全抛弃掉图形化,需要什么工具就yum安装。所以Shell作为操作系统的外核为用户提供使用操作系统的接口,它可以说是命令语言解释器,拥有自己内建的shell命令集,我们在使用tab键的时候,可以弹出补全命令的提示。Shell使得用户在提示符下输入的命令都由shell先解释然后传给Linux核心。
shell是UNIX系统用用户与操作系统交互的最基本工具,实际上shell除了有命令解释执行的功能外,还具有其他的功能: 1)系统环境的设置 2)输入输出的重定向 3)shell程序语言的设计等
不同的Shell在应用中各有所长,以下是几种常见类型的shell。
1)Bourne Shell是UNIX最初使用的shell,并且在每个Unix上都可以使用,Bourne SHell在编程方面相当优秀,但是在处理与用户的交互界面上做的不如其他的Shell,现如今我们常说的bash(Bourne Agair Shell),它就是在Bourne Shell上的基础上增加了许多的特性。
2)C shell 是一种适于编程的 shell, 它的语法与 C 语言很相似,Linux 为喜欢使用 C shell 的人提供了 Tcsh。Tcsh 是 C shell 的一个扩展版本,Tcsh 包括命令行编辑可编程单词补全、拼写校正、历史命令替换、作业控制和类似 C 语言的语法,它不仅和 Bash shell 是提示符兼容,而且还提供比 Bash shell 更多的提示符参数
3)Korn shell 集合了 C shell 和 Bourne shell 的优点并且和 Bourne shell 完全兼容 Linux 系统提供pdkshksh 的扩展。它支持任务控制,可以在命令行上挂起、后台执行、唤醒或终止程序。
3)Korn shell 集合了 C shell 和 Bourne shell 的优点并且和 Bourne shell 完全兼容 Linux 系统提供pdkshksh 的扩展。它支持任务控制,可以在命令行上挂起、后台执行、唤醒或终止程序。
Redhat Linux系统默认Shell是Bash shell,超级用户用#做提示符(root相当于windows的administrator用户,权限很大,在使用上用很大的风险。企业和学习中最好使用普通用户)。在Linux中,普通用户用$做为提示符。我们可以在root用户和普通用户上键入命令完成我们所要达到的任务和学习。
1.1.2Redhat发行版
常见的linux发行版本按照RPM方法安装软件的系统,包括Red Hat,Fedora,SuSE,Centos系统;另外一类是使用Debian的dpkg方式安装软件的,包括Ubuntu、Debain,B2D等等,因为国内使用的都是类Redhat的环境,我上学的时候使用的也是Centos系统,所以以下的学习环境都是在Centos下完成。
版本为Centos7.2
[root@kvm ~]# uname -a Linux kvm 3.10.0-327.el7.x86_64 #1 SMP Thu Nov 19 22:10:57 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
下面我们一起来操作shell是怎么进行的,我们在shell输入以下命令:ls -al
[root@kvm ~]# ls -al total 88 dr-xr-x---. 22 root root 4096 Oct 31 19:22 . dr-xr-xr-x. 17 root root 4096 Oct 30 06:07 .. -rw-------. 1 root root 1619 Oct 22 01:57 anaconda-ks.cfg ................................................ drwxr-xr-x. 2 root root 6 Oct 23 20:48 下载 drwxr-xr-x. 2 root root 6 Oct 23 20:48 公共 drwxr-xr-x. 2 root root 6 Oct 23 20:48 图片 drwxr-xr-x. 2 root root 6 Oct 23 20:48 文档 drwxr-xr-x. 3 root root 33 Oct 31 19:30 桌面 drwxr-xr-x. 2 root root 6 Oct 23 20:48 模板 drwxr-xr-x. 2 root root 6 Oct 23 20:48 视频 drwxr-xr-x. 2 root root 6 Oct 23 20:48 音乐ls -al 该命令可以勒出当前目录下的所有文件和子目录。
我们在登录到linux时,系统会读书/etc/passwd文件来决定要使用哪个shell,例如我使用了root用户显示的就是
[root@kvm ~]# cat /etc/passwd |grep root root:x:0:0:root:/root:/bin/bash使用test用户显示的就是
test:x:1001:1001::/home/test:/bin/bash用户之间的切换使用的是命令 su
[test@kvm root]$ su #单独输入su 会切换到root用户 Password: #输入root密码 [root@kvm ~]# su test #切换到test用户 [test@kvm root]$ #成功切换到test用户
我们可以使用上下箭头上查看我们使用了哪些命令,如果命令较多,我们也可以用history来查看历史命令。
[root@kvm ~]# history 1 vim /etc/locale.conf 2 reboot 3 ls 4 netstat -antp |grep 5901 5 systemctl status vncserver@:1.service 6 systemctl restart vncserver@:1.service 7 vim /etc/libvirt/qemu 8 vim /etc/libvirt/qemu.conf 9 systemctl restart vncserver@:1.service 10 systemctl restart firewalld.service 11 systemctl status firewalld.service 12 systemctl restart firewalld.service 13 systemctl restart vncserver@:1.service
如果只想显示最后n行可以使用 history 可以使用history -n
[root@kvm ~]# history 10
1.1.3Linux 是一个真正的多用户操作系统 这表示它可以同时接受多个用户登录Linux 还允许一个用户进行多次登录。如同我使用的服务器Dell R710,就有两个使用者,我们可以使用putty或者Xshell工具远程进入控制台系统。我们可以使用whoami来看看是谁控制了系统。
[root@kvm ~]# whoami root [root@kvm ~]# su test [test@kvm root]$ whoami test
使用last查看当前登录和过去登录的用户信息
root pts/3 :1 Mon Oct 23 13:29 - down (00:01) root pts/2 192.168.0.2 Mon Oct 23 13:24 - down (00:06) root pts/1 :0 Mon Oct 23 20:56 - down (-7:-25) root pts/0 :0 Mon Oct 23 20:56 - down (-7:-25) root :0 :0 Mon Oct 23 20:56 - 13:31 (-7:-25) reboot system boot 3.10.0-327.el7.x Mon Oct 23 20:55 - 13:31 (-7:-24) root pts/1 :0 Mon Oct 23 20:49 - crash (00:06) root pts/0 :0 Mon Oct 23 20:48 - crash (00:06) root :0 :0 Mon Oct 23 20:48 - 20:49 (00:01) reboot system boot 3.10.0-327.el7.x Mon Oct 23 20:47 - 13:31 (-7:-16) reboot system boot 3.10.0-327.el7.x Mon Oct 23 20:41 - 13:31 (-7:-10) reboot system boot 3.10.0-327.el7.x Mon Oct 23 20:25 - 20:32 (00:06) reboot system boot 3.10.0-327.el7.x Sun Oct 22 02:06 - 02:07 (00:01) reboot system boot 3.10.0-327.el7.x Sun Oct 22 02:01 - 02:07 (00:05)
常见的远程方式一般有talent远程登录(传输明文不安全)常使用的有ssh远程连接和VNC连接。具体后面会讲,我也是想到那写到。
评论暂时关闭