运行简单的linux命令
简单、常用的命令
- whoami ~ 列出目前登录Linux系统所使用的用户名
- who am i ~ 除了用户名,还显示登录的终端、当前的日期和时间以及所使用的计算机的IP地址
- who ~显示的内容与who am i命令相同,但还包括了系统上工作的其他用户
[dag@dog ~]$ whoami
dag
[dag@dog ~]$ who am i
dag pts/0 2020-05-13 17:02 (:0.0)
[dag@dog ~]$ ssh user@localhost
The authenticity of host 'localhost (::1)' can't be established.
RSA key fingerprint is 27:f4:8e:b3:e0:22:00:ab:e1:e9:8b:c3:24:f2:8a:ef.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'localhost' (RSA) to the list of known hosts.
user@localhost's password:
Permission denied, please try again.
user@localhost's password:
Permission denied, please try again.
user@localhost's password:
Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).
[dag@dog ~]$ who
dag tty1 2020-05-13 16:13 (:0)
dag pts/0 2020-05-13 17:02 (:0.0)
w ~ 所获得的信息比who命令多一些
users ~目前登录系统的全部用户
tty ~目前用户登录系统所使用的终端
[dag@dog ~]$ w
17:05:52 up 54 min, 2 users, load average: 0.00, 0.00, 0.00
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
dag tty1 :0 16:13 53:55 40.83s 0.16s pam: gdm-passwo
dag pts/0 :0.0 17:02 0.00s 0.08s 0.07s w
[dag@dog ~]$ users
dag dag
[dag@dog ~]$ tty
/dev/pts/0
uname ~ 获得有关系统的信息
- 其命令的主要选项包括:
- -r:显示操作系统发布的版本信息
- -n:显示所使用系统的主机名
- -i: 显示硬件平台名
- -s: 显示操作系统名
- -m:显示机器硬件名
- -p: 显示中央处理器的类型
- -a: 显示所有的信息
[dag@dog ~]$ uname
Linux
[dag@dog ~]$ uname -n
dog.super.com
[dag@dog ~]$ uname -i
x86_64
[dag@dog ~]$ uname -n -i
dog.super.com x86_64
[dag@dog ~]$ uname -in
dog.super.com x86_64
[dag@dog ~]$ uname -ni
dog.super.com x86_64
[dag@dog ~]$ uname -rs
Linux 2.6.32-504.el6.x86_64
[dag@dog ~]$ uname -sr
Linux 2.6.32-504.el6.x86_64
[dag@dog ~]$ uname -pmrs
Linux 2.6.32-504.el6.x86_64 x86_64 x86_64
[dag@dog ~]$ uname -a
Linux dog.super.com 2.6.32-504.el6.x86_64 #1 SMP Tue Oct 14 01:47:47 PDT 2014 x86_64 x86_64 x86_64 GNU/Linux
[dag@dog ~]$ uname -all
uname:无效选项 -- l
请尝试执行"uname --help"来获取更多信息。
[dag@dog ~]$ uname --all
Linux dog.super.com 2.6.32-504.el6.x86_64 #1 SMP Tue Oct 14 01:47:47 PDT 2014 x86_64 x86_64 x86_64 GNU/Linux
[dag@dog ~]$ uname --help
date ~ 显示系统当前的日期和时间
cal ~ 显示某月的日历
- 利用参数准确地定义一个命令要做什么
- cal 8 2008:列出2008年8月的日历
clear ~ 清除终端窗口中的显示
[dag@dog ~]$ date
2020年 05月 13日 星期三 17:17:35 CST
[dag@dog ~]$ cal
五月 2020
日 一 二 三 四 五 六
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31
[dag@dog ~]$ cal 8 2008
八月 2008
日 一 二 三 四 五 六
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31
su 和passwd命令
- su ~ 从一个用户切换到另一个用户
- 即可以从普通用户切换到超级用户
- 也可以从普通用户切换到另一个普通用户
- 还可以从root用户切换到一个普通用户
[dag@dog ~]$ su - root
密码:
[root@dog ~]# whoami
root
[root@dog ~]# exit
logout
[dag@dog ~]$ whoami
dag
[dag@dog ~]$ su dog
su: 用户dog 不存在
[dag@dog ~]$ su - dog
su: 用户dog 不存在
[dag@dog ~]$ su - dag
密码:
passwd ~ 修改用户的密码及查看密码的状态等
- 普通用户修改后的新密码不得少于6个字符
- 普通用户只能修改自己的密码
- 以root用户修改时,新密码可以少于6个字符
- root用户可以修改任何用户的密码
- 以-S或–status选项查看用户的密码状态
[root@dog ~]# useradd cat
[root@dog ~]# passwd -S cat
cat LK 2020-05-13 0 99999 7 -1 (密码已被锁定。)
[root@dog ~]# passwd -S dag
dag PS 2020-03-30 0 99999 7 -1 (密码已设置,使用 SHA512 加密。)
[root@dog ~]# passwd cat
更改用户 cat 的密码 。
新的 密码:
无效的密码: 过短
无效的密码: 过于简单
重新输入新的 密码:
passwd: 所有的身份验证令牌已经成功更新。
[root@dog ~]# passwd -S cat
cat PS 2020-05-13 0 99999 7 -1 (密码已设置,使用 SHA512 加密。)
[root@dog ~]# passwd --status dag
dag PS 2020-03-30 0 99999 7 -1 (密码已设置,使用 SHA512 加密。)
You have new mail in /var/spool/mail/root
[root@dog ~]# passwd --status cat
cat PS 2020-05-13 0 99999 7 -1 (密码已设置,使用 SHA512 加密。)
[root@dog ~]# exit
logout
[dag@dog ~]$ passwd -S cat
只有根用户才能进行此操作。
whatis命令与命令的—help选项
[dag@dog ~]$ whatis uname
uname (1p) - return system name
uname (1) - print system information
uname (2) - get name and information about current kernel
uname (3p) - get the name of the current system
[dag@dog ~]$ whatis who
who (1p) - display who is on the system
who (1) - show who is logged on
[dag@dog ~]$ uname --help
用法:uname [选项]...
输出一组系统信息。如果不跟随选项,则视为只附加-s 选项。
-a, --all 以如下次序输出所有信息。其中若-p 和
-i 的探测结果不可知则被省略:
-s, --kernel-name 输出内核名称
-n, --nodename 输出网络节点上的主机名
-r, --kernel-release 输出内核发行号
-v, --kernel-version 输出内核版本
-m, --machine 输出主机的硬件架构名称
-p, --processor 输出处理器类型或"unknown"
-i, --hardware-platform 输出硬件平台或"unknown"
-o, --operating-system 输出操作系统名称
--help 显示此帮助信息并退出
--version 显示版本信息并退出
怎样阅读命令的使用摘要
[dag@dog ~]$ man date
NAME
date - print or set the system date and time
SYNOPSIS
date [OPTION]... [+FORMAT]
date [-u|--utc|--universal] [MMDDhhmm[[CC]YY][.ss]]
DESCRIPTION
Display the current time in the given FORMAT, or set the system date.
-d, --date=STRING
display time described by STRING, not ‘now’
-f, --file=DATEFILE
like --date once for each line of DATEFILE
-r, --reference=FILE
display the last modification time of FILE
-R, --rfc-2822
output date and time in RFC 2822 format. Example: Mon, 07 Aug
利用man命令获取帮助信息
[dag@dog ~]$ man su
NAME
su - run a shell with substitute user and group IDs
SYNOPSIS
su [OPTION]... [-] [USER [ARG]...]
DESCRIPTION
Change the effective user id and group id to that of USER.
[dag@dog ~]$ man 5 passwd
NAME
passwd - password file
DESCRIPTION
Passwd is a text file, that contains a list of the system’s accounts,
giving for each account some useful information like user ID, group ID,
home directory, shell, etc. Often, it also contains the encrypted
passwords for each account. It should have general read permission
(many utilities, like ls(1) use it to map user IDs to usernames), but
write access only for the superuser.
[dag@dog ~]$ man lvm
NAME
lvm — LVM2 tools
SYNOPSIS
lvm [command | file]
DESCRIPTION
lvm provides the command-line tools for LVM2. A separate manual page
describes each command in detail.
利用关键字搜寻Man Pages
[dag@dog ~]$ man -k who
at.allow [at] (5) - determine who can submit jobs via at or batch
at.deny [at] (5) - determine who can submit jobs via at or batch
find_busiest_group (9) - Returns the busiest group within the sched_domain if there is an imbalance. If there isn't an imbalance, and the user has opted for power-savings, it returns a group whose CPUs can be put to idle by rebalancing those tasks elsewhere, if such a group exists
pamfixtrunc (1) - repair a Netpbm image whose file is truncated
w (1) - Show who is logged on and what they are doing
who (1p) - display who is on the system
who (1) - show who is logged on
whoami (1) - print effective userid
[dag@dog ~]$ man -k calend
cal (1) - displays a calendar
cal (1p) - print a calendar
difftime (3p) - compute the difference between two calendar time values
[dag@dog ~]$ man -f who
who (1p) - display who is on the system
who (1) - show who is logged on
[dag@dog ~]$ whatis who
who (1p) - display who is on the system
who (1) - show who is logged on
[dag@dog ~]$ man -f clear
clear (1) - clear the terminal screen
clear (3x) - clear all or part of a curses window
clear [clrtobot] (3x) - clear all or part of a curses window
clear [clrtoeol] (3x) - clear all or part of a curses window
clear [curs_clear] (3x) - clear all or part of a curses window
clear [erase] (3x) - clear all or part of a curses window
clear [wclear] (3x) - clear all or part of a curses window
clear [wclrtobot] (3x) - clear all or part of a curses window
clear [wclrtoeol] (3x) - clear all or part of a curses window
clear [werase] (3x) - clear all or part of a curses window
[dag@dog ~]$ whatis clear
clear (1) - clear the terminal screen
clear (3x) - clear all or part of a curses window
clear [clrtobot] (3x) - clear all or part of a curses window
clear [clrtoeol] (3x) - clear all or part of a curses window
clear [curs_clear] (3x) - clear all or part of a curses window
clear [erase] (3x) - clear all or part of a curses window
clear [wclear] (3x) - clear all or part of a curses window
clear [wclrtobot] (3x) - clear all or part of a curses window
clear [wclrtoeol] (3x) - clear all or part of a curses window
clear [werase] (3x) - clear all or part of a curses window
[dag@dog ~]$ man man
NAME
man - format and display the on-line manual pages
SYNOPSIS
man [-acdDfFhkKtwW] [--path] [-m system] [-p string] [-C config_file]
[-M pathlist] [-P pager] [-B browser] [-H htmlpager] [-S section_list]
[section] name ...
DESCRIPTION
man formats and displays the on-line manual pages. If you specify sec-
tion, man only looks in that section of the manual. name is normally
the name of the manual page, which is typically the name of a command,
function, or file. However, if name contains a slash (/) then man
interprets it as a file specification, so that you can do man ./foo.5
or even man /cd/foo/bar.1.gz.
See below for a description of where man looks for the manual page
files.
MANUAL SECTIONS
The standard sections of the manual include:
利用info命令来获取帮助
Info命令的语法格式如下:
Info
Info命令与man命令相似,但是它提供的信息更详细并且用法更简单
[dag@dog ~]$ info info
Info: An Introduction
*********************
The GNU Project distributes most of its on-line manuals in the "Info
format", which you read using an "Info reader". You are probably using
an Info reader to read this now.
There are two primary Info readers: `info', a stand-alone program
designed just to read Info files (*note Stand-alone Info:
(info-stnd)Top.), and the `info' package in GNU Emacs, a
general-purpose editor. At present, only the Emacs reader supports
using a mouse.
If you are new to the Info reader and want to learn how to use it,
type the command `h' now. It brings you to a programmed instruction
sequence.
To read about advanced Info commands, type `n' twice. This brings
you to `Advanced Info Commands', skipping over the `Getting Started'
chapter.