運行簡單的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.