标签 linux 下的文章

“”

用户名ubuntu
最终命令

sudo usermod -aG www-data ubuntu

添加用户到组命令:sudo usermod -aG 组名 用户名

usermod -h
Usage: usermod [options] LOGIN

Options:
  -b, --badnames                allow bad names
  -c, --comment COMMENT         new value of the GECOS field
  -d, --home HOME_DIR           new home directory for the user account
  -e, --expiredate EXPIRE_DATE  set account expiration date to EXPIRE_DATE
  -f, --inactive INACTIVE       set password inactive after expiration
                                to INACTIVE
  -g, --gid GROUP               force use GROUP as new primary group
  -G, --groups GROUPS           new list of supplementary GROUPS
  -a, --append                  append the user to the supplemental GROUPS
                                mentioned by the -G option without removing
                                the user from other groups
  -h, --help                    display this help message and exit
  -l, --login NEW_LOGIN         new value of the login name
  -L, --lock                    lock the user account
  -m, --move-home               move contents of the home directory to the
                                new location (use only with -d)
  -o, --non-unique              allow using duplicate (non-unique) UID
  -p, --password PASSWORD       use encrypted password for the new password
  -R, --root CHROOT_DIR         directory to chroot into
  -P, --prefix PREFIX_DIR       prefix directory where are located the /etc/* files
  -s, --shell SHELL             new login shell for the user account
  -u, --uid UID                 new UID for the user account
  -U, --unlock                  unlock the user account
  -v, --add-subuids FIRST-LAST  add range of subordinate uids
  -V, --del-subuids FIRST-LAST  remove range of subordinate uids
  -w, --add-subgids FIRST-LAST  add range of subordinate gids
  -W, --del-subgids FIRST-LAST  remove range of subordinate gids
  -Z, --selinux-user SEUSER     new SELinux user mapping for the user account

sudo nmcli radio wifi off

也可以简化为

sudo nmcli r wifi off

查看wifi的开关状态

nmcli r wifi 

enabled

查看命令用法

nmcli r help

用法:nmcli radio { 命令 | help }

命令 := { all | wifi | wwan }

all | wifi | wwan [ on | off ]

查看nmcli 用法

nmcli help

Usage: nmcli [OPTIONS] OBJECT { COMMAND | help }

OPTIONS
-a, --ask ask for missing parameters
-c, --colors auto|yes|no whether to use colors in output
-e, --escape yes|no escape columns separators in values
-f, --fields <field,...>|all|common specify fields to output
-g, --get-values <field,...>|all|common shortcut for -m tabular -t -f
-h, --help print this help
-m, --mode tabular|multiline output mode
-o, --overview overview mode
-p, --pretty pretty output
-s, --show-secrets allow displaying passwords
-t, --terse terse output
-v, --version show program version
-w, --wait <seconds> set timeout waiting for finishing operations

OBJECT
g[eneral] NetworkManager's general status and operations
n[etworking] overall networking control
r[adio] NetworkManager radio switches
c[onnection] NetworkManager's connections
d[evice] devices managed by NetworkManager
a[gent] NetworkManager secret agent or polkit agent
m[onitor] monitor NetworkManager changes

要关闭所有网络

nmcli n help

用法:nmcli networking { 命令 | help }

命令 := { [ on | off | connectivity ] }

on

off

connectivity [check]

完全启用/禁用网络

nmcli networking off

仅用于WiFi

nmcli radio wifi off

在两种情况下都on可以重新启用。

首先使用查到无线网卡的名字

ifconfig -a

wlp0s20f3

iwlist 常用命令:
查询帮助信息

iwlist --help 

Usage: iwlist [interface] scanning [essid NNN] [last]

          [interface] frequency 
          [interface] channel 
          [interface] bitrate 
          [interface] rate 
          [interface] encryption 
          [interface] keys 
          [interface] power 
          [interface] txpower 
          [interface] retry 
          [interface] ap 
          [interface] accesspoints 
          [interface] peers 
          [interface] event 
          [interface] auth 
          [interface] wpakeys 
          [interface] genie 
          [interface] modulation 

查询版本信息

 iwlist --version 

iwlist Wireless-Tools version 30

      Compatible with Wireless Extension v11 to v22.

Kernel Currently compiled with Wireless Extension v22.

wlp0s20f3 Recommend Wireless Extension v21 or later,

      Currently compiled with Wireless Extension v22.

搜索wifi热点网络

iwlist wlp0s20f3 scan 

wlp0s20f3 Scan completed :

      Cell 01 - Address: CC:F9:57:D0:F5:85
                Channel:6
                Frequency:2.437 GHz (Channel 6)
                Quality=53/70  Signal level=-57 dBm  
                Encryption key:on
                ESSID:"xxxxxxxxxxxxxxxx"
                Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s; 6 Mb/s
                          9 Mb/s; 12 Mb/s; 18 Mb/s
                Bit Rates:24 Mb/s; 36 Mb/s; 48 Mb/s; 54 Mb/s
                Mode:Master

查询频道信息

iwlist wlp0s20f3 frequen

wlp0s20f3 32 channels in total; available frequencies :

      Channel 01 : 2.412 GHz
      Channel 02 : 2.417 GHz
      Channel 03 : 2.422 GHz
      Channel 04 : 2.427 GHz
      Channel 05 : 2.432 GHz
      Channel 06 : 2.437 GHz
      Channel 07 : 2.442 GHz
      Channel 08 : 2.447 GHz
      Channel 09 : 2.452 GHz
      Channel 10 : 2.457 GHz
      Channel 11 : 2.462 GHz
      Channel 12 : 2.467 GHz
      Channel 13 : 2.472 GHz
      Channel 36 : 5.18 GHz
      Channel 40 : 5.2 GHz
      Channel 44 : 5.22 GHz
      Channel 48 : 5.24 GHz
      Channel 52 : 5.26 GHz
      Channel 56 : 5.28 GHz
      Channel 60 : 5.3 GHz
      Channel 64 : 5.32 GHz
      Channel 100 : 5.5 GHz
      Channel 104 : 5.52 GHz
      Channel 108 : 5.54 GHz
      Channel 112 : 5.56 GHz
      Channel 116 : 5.58 GHz
      Channel 120 : 5.6 GHz
      Channel 124 : 5.62 GHz
      Channel 128 : 5.64 GHz
      Channel 132 : 5.66 GHz
      Channel 136 : 5.68 GHz
      Channel 140 : 5.7 GHz
      Current Frequency:2.437 GHz (Channel 6)
 

查询连接速度

iwlist wlp0s20f3 rate 

wlp0s20f3 unknown bit-rate information.

      Current Bit Rate:39 Mb/s
    

查询热点信息

iwlist wlp0s20f3 ap 

wlp0s20f3 Interface doesn't have a list of Peers/Access-Points
查询重接次数

iwlist wlp0s20f3 retry     

wlp0s20f3 Fixed limit ; min limit:0

                        max limit:255
      Current mode:on
              short limit:7
               long limit:4

查询电源模式

iwlist wlp0s20f3 power

 

wlp0s20f3 Current mode:on
查询功耗

iwlist wlp0s20f3 txpower

wlp0s20f3 unknown transmit-power information.

      Current Tx-Power=22 dBm      (158 mW)

添加 WiFi 连接配置
wpa_passphrase {SSID} {PASSWORD} > /etc/wpa_supplicant/{SSID}.conf

其中 {SSID} 为无线网络的名称(即WiFi名称),{PASSWORD} 为 WiFi 密码。

连接无线网络
wpa_supplicant -i wlan0 -c /etc/wpa_supplicant/{SSID}.conf -B
看到 Successfully 字样就表示连接成功啦!

配置 DHCP 自动分配 IP
dhclient wlan06
查看是否连接成功
ifconfig

看到 wlan0 中已经有正常的 IP 地址了,说明网络连接已经建立。

验证能否正常上网
ping www.baidu.com -c 4

响应正常,说明可以正常上网了!

Referenced from:https://cloud.tencent.com/developer/article/1494772

linux使用shell获取unix时间。
UNIX时间,或称POSIX时间是UNIX或类UNIX系统使用的时间表示方式:从UTC1970年1月1日0时0分0秒起至现在的总秒数,不考虑闰秒。 在多数Unix系统上Unix时间可以透过date +%s指令来检查。

date +%s

1630900618

查看任意时间的unixtime

date -s '2021-09-06 12:00:00' && date +%s
Mon Sep 6 12:00:00 CST 2021
1630900800

查看2004-1-1 00:00:00 的unixtime

date -s '2004-01-01 00:00:00' && date +%s

Thu Jan 1 00:00:00 CST 2004
1072886400

date 格式化时间

date '+%Y-%m-%d %H:%m:%S'

2021-09-06 11:09:48

date '+%F %H:%m:%S'

2021-09-06 11:09:57

date '+%F %T'

2021-09-06 12:00:43

date +%s.%N
where (GNU Coreutils 8.24 Date manual)

+%s, seconds since 1970-01-01 00:00:00 UTC
+%N, nanoseconds (000000000..999999999) since epoch

date +%s.%N

1630907594.542788384