复习_简单命令

来源:互联网 发布:windows怎么安装服务 编辑:程序博客网 时间:2024/05/21 11:03

shell

shell的中文解释有壳的意思,所以,shell的作用就是像壳一样保护内核,使用者需要通过shell来与内核沟通,从而让计算机完成用户想要完成的事情。shell保护内核防止用户操作不当,让内核崩溃。shell也为用户提供了一个操作系统的接口。

 

系统的合法shell和/etc/shells

linux中不知一个shell,从/etc/shells文档中可以查看有多少个可以使用的shell

[root@server1 ~]# cat /etc/shells

/bin/sh

/bin/bash ##linux预设的shell

/sbin/nologin ##用户无法使用bash或其他shell来登录系统

/bin/dash ##the Debian Almquist Shell,是一个符合posix标准的shell,主要特点是小型化,效率高

[root@server1 ~]#

 

当用户登入的时候,系统就会给用户一个shell来工作,而这个登入取得的shell就记录在/etc/passwd中

[root@server1 ~]# cat /etc/passwd

root:x:0:0:root:/root:/bin/bash ##最后一个数据就是用户登入后取的的预设shell

bin:x:1:1:bin:/bin:/sbin/nologin

daemon:x:2:2:daemon:/sbin:/sbin/nologin

adm:x:3:4:adm:/var/adm:/sbin/nologin

lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin

sync:x:5:0:sync:/sbin:/bin/sync

..........

#######################################################

1、命令提示符

[root@server1 ~]#

root ##开启shell的用户

@ ##分隔符

server1 ##主机名,表示shell开启在那台主机中

~ ##表示在系统的什么位置,~表示家目录

# ##表示是以超级用户登陆,普通用户是$

 

2、切换用户:

[root@server1 ~]# su - 系统已存在的用户

 

3、退出当前用户:

ctrl + D(death) 或 logout

 

4、修改shell提示符:

[root@server1 ~]# echo $PS1

[\u@\h \W]\$

[root@server1 ~]# PS1='[\u**\h \w]\$'

[root**server1 ~]#PS1='[\u@\h \w]\$'

[root@server1 ~]#

 

PS1是一个环境变量,也就是命令提示字符,可以自己修改

\d :可显示出[星期 月 日]的日期格式,如:“Mon Feb 2”

\H :完整的主机名。如:www.server1.com

\h :仅取主机名在第一个小数点之前的名字,如:www

\t :显示时间,为24小时格式的[HH:MM:SS]

\T :显示时间,为12小时格式的[HH:MM:SS]

\A :显示时间,为24小时格式的[HH:MM]

\@ :显示时间,为12小时格式的[am/pm]

\u :目前使用者的帐号名称,如:root

\v :BASH的版本信息

\w :完整的工作目录名称,由根目录写起的目录名称,但家目录会以~取代

\W :利用basename函数取的工作目录名称,所以仅会列出最后一个目录名称

\# :下达的第几个指令

\$ :提示字符

[root@server1 ~]# PS1='[\u@\h\w\A #\#]\$'

[root@server1~01:47 #4]#PS1='[\u@\h\w \A #\#]\$'

[root@server1~ 01:48 #5]#PS1='[\u@\h \w \A #\#]\$'

[root@server1 ~ 01:48 #6]#

 

5、图形界面与非图形界面

crtl +Alt + F1/F7 ##返回图形界面

crtl +Alt +F(2..6) ##切换到虚拟控制台,即非图形界面

 

6、命令格式:命令 参数 目标 ##命令是系统中可执行的文件,参数是命令功能的指定,目标是命令影响的实体

 

7、帮助:命令 --help

[root@server1 ~]#ls --help ##ls

Usage: ls [OPTION]... [FILE]...

List information about the FILEs (the current directory by default).

Sort entries alphabetically if none of -cftuvSUX nor --sort.

 

Mandatory arguments to long options are mandatory for short options too.

  -a, --all                  do not ignore entries starting with .

  -A, --almost-all           do not list implied . and ..

      --author               with -l, print the author of each file

  -b, --escape               print octal escapes for nongraphic characters

      --block-size=SIZE      use SIZE-byte blocks.  See SIZE format below

  -B, --ignore-backups       do not list implied entries ending with ~

  -c                         with -lt: sort by, and show, ctime (time of last

                               modification of file status information)

                               with -l: show ctime and sort by name

                               otherwise: sort by ctime

  -C                         list entries by columns

      --color[=WHEN]         colorize the output.  WHEN defaults to `always'

                               or can be `never' or `auto'.  More info below

  -d, --directory            list directory entries instead of contents,

                               and do not dereference symbolic links

列出了ls命令可以使用的参数以及参数所表示的意思,可以单个使用,也可以结合使用,-参数缩写,--参数全拼

[root@server1 ~]#ls

libpcap-1.4.0-4.20130826git2dbcaa1.el6.x86_64.rpm        moosefs-3.0.80.tar.gz

libpcap-devel-1.4.0-4.20130826git2dbcaa1.el6.x86_64.rpm  puppet

moosefs-3.0.80-1.tar.gz                                  rpmbuild

[root@server1 ~]#ls -l

total 1332

-rw-r--r-- 1 root root  134248 Oct 30  2016 libpcap-1.4.0-4.20130826git2dbcaa1.el6.x86_64.rpm

-rw-r--r-- 1 root root  116816 Oct 30  2016 libpcap-devel-1.4.0-4.20130826git2dbcaa1.el6.x86_64.rpm

-rw-r--r-- 1 root root 1097759 Oct 30  2016 moosefs-3.0.80-1.tar.gz

lrwxrwxrwx 1 root root      23 Oct 30  2016 moosefs-3.0.80.tar.gz -> moosefs-3.0.80-1.tar.gz

drwxrwxr-x 3 root root    4096 Nov 14  2016 puppet

drwxr-xr-x 8 root root    4096 Oct 30  2016 rpmbuild

[root@server1 ~]#ls -al

total 1416

dr-xr-x---.  8 root root    4096 Dec 10  2016 .

dr-xr-xr-x. 25 root root    4096 Aug 10 16:55 ..

-rw-------.  1 root root   14016 Dec 10  2016 .bash_history

-rw-r--r--.  1 root root      18 May 20  2009 .bash_logout

-rw-r--r--   1 root root     202 Sep 17  2016 .bash_profile

-rw-r--r--.  1 root root     176 Sep 23  2004 .bashrc

drwx------   3 root root    4096 Oct  1  2016 .cache

drwx------   3 root root    4096 Oct  1  2016 .config

-rw-r--r--.  1 root root     100 Sep 23  2004 .cshrc

..........

 

8、gnome的常规操作

(1)login

for gui

for text ##crtl + Alt + F(2..6)来操作

(2)crtl +Alt +上下键 ##切换workspace

(3)锁屏:crtl +Alt +L

(4)创建快捷键:Application->Tools->Keyboard->Shortcut

(5)如在命令行打开一个新的终端:[root@server1 ~]#gnome-terminal ##需在图形界面下

 

9、系统重新初始化

关机(三个都可以)

[root@server1 ~]#init 0

[root@server1 ~]#poweroff

[root@server1 ~]#shutdown -h now

重启

reboot|init6|shutdown -r now

 

10、简单命令

date命令

[root@server1 ~]#date ##显示当前的时间

Thu Aug 10 17:47:51 CST 2017

[root@server1 ~]#date 11111111.11 ##修改时间,月月天天小时分钟.秒秒[root@server1 [root@server1 ~]#date -d +83day显示向后第83天的日期

Wed Nov  1 17:51:40 CST 2017

[root@server1 ~]#date -d -83day ##显示向前第83天的日期

Fri May 19 17:51:52 CST 2017

[root@server1 ~]#date +%F ##选择以什么形式显示时间

2017-08-10

[root@server1 ~]#date +%m-%d-%Y

08-10-2017

[root@server1 ~]#

[root@server1 ~]#watch -n 1 date ##监控date命令每秒钟执行一次

#############################################

passwd命令

修改密码:passwd username

冻结普账户:passwd -l username

界所冻结普通账户:passwd -u username

############################################

file命令 ##查看文件类型

###########################################

head和tail

head/tail -n filename ##显示文件的前n行或最后n行,默认10行

###############################################

wc命令 ##查看字数、字符数、行数

c, --bytes字节数,一个中文三个字节。

-m, --chars字符数,

-l, --lines行数,

-w, --words单词数,

注意:空格也是字符及字节

##############################################

tab键 ##补全系统中存在的文件名称、命令和参数,按两下提示命令或参数等

[root@server1 ~]#ifc

ifcfg     ifconfig  

[root@server1 ~]#ifc

############################################

历史调用命令

!number ##执行第number条命令

!string ##执行最近一条以string开头的命令

crtl + r +关键字 ##调出最近一条含有关键字的命令,可以使用上下键选择自己想要的命令

上下键 ##从最后一条命令向前查看或向后查看

history ##查看历史

############################################

命令行中使用的快捷键

ctrl+a ##光标移动到行首

ctrl+e ##光标移动到行尾

ctrl+u ##光标所在位置删除到行首

ctrl+k ##光标所在位置删除到行尾

ctrl+左|右 ##光标以单词为单为移动

crtl+c ##中断已输入的命令或执行

crtl+d ##关闭当前环境

################################################################

08/11/2017 01:50:41 AM