Linux 常用命令

shell

移动光标
  • Ctrl – a :移到行首
  • Ctrl – e :移到行尾
  • Ctrl – r :(reverse-i-search)`’: 查找历史命令
  • Ctrl - h :删除上一个字符
  • Ctrl - d : 退出当前会话
  • Ctrl - k : 清除光标之后的命令
type [command]
  • type cd

查看是否是内部命令

User System

useradd
useradd username
useradd
  • id username // 显示指定用户id相关信息
  • id //显示当前用户id 相关信息
passwd
passwd username
userdel
userdel username

File System

ls

第一个字符是文件类型。如果是“-”,表示普通文件;如果是 d表示目录

第二个字段是硬链接(hard link)数目,

# ls -l
drwxr-xr-x 6 root root    4096 Oct 20  2017 apt
-rw-r--r-- 1 root root     211 Oct 20  2017 hosts

file
  • file //查看文件后缀及其属性
tar
  • First option must be a mode specifier:

    • -c Create
    • -r Add/Replace
    • -t List
    • -u Update
    • -x Extract
  • Common Options:

    • -b # Use # 512-byte records per I/O block
    • -f Location of archive
    • -v Verbose
    • -w Interactive
  • example

    • tar -zcvf filename.tar.gz filename //压缩
    • tar -xzvf filename.tar.gz //解压 .tar.gz
    • tar -xvf filename.tar //解压 .tar
zip
  • zip -r file.zip DirectoryName
mkdir
  • mkdir -p //循环创建目录
tee

标准输出到某个文件

screen
  • screen -ls //列出所有窗口
  • screen -list // 列出所有窗口
  • screen -S [sockName] //重新打开一个窗口
  • screen -R name // Reattach if possible, otherwise start a new session.
  • Ctrl + a +d //离开当前窗口 detach
  • screen -r [session] //Reattach to a detached screen process.
more
  • ./configure --help | more
less
  • ./configure --help | less
tail
  • tail -10 /etc/passwd
  • tail -10 /etc/group
  • tail -10 /etc/shadow
ln
  • ln -snf b soft

更新软链接

vim

vim 一个远程文件

vim scp://root@192.168.1.23//root/.ssh/authorized_keys

SoftWare Management

dpkg

Debian/Ubuntu 体系

  • dpkg -l //列出来所有安装的软件
  • dpkg -i <.deb file name> //安装软件
  • dpkg -r //删除 -r remove
  • dpkg -L packagename // 列出软件包的所有文件
  • dpkg -s packgename // 软件包状态
apt

Debian/Ubuntu 体系

  • /etc/apt/sources.list
  • apt list 根据名称列出软件包
  • apt search 搜索软件包描述
  • apt remove 删除软件包而保留软件的配置文件
  • apt purge 同时清除软件包和软件的配置文件
  • apt update 更新可用软件包列表
  • apt edit-sources 编辑信息源文件

    个人一般选择vim

apt-key
  • apt-key list 列出已保存在系统中key。
  • apt-key add keyname 把下载的key添加到本地trusted数据库中。
  • apt-key add -

    从标准输入中将key添加到本地trusted数据库中,-表示标准输入。

  • apt-key del keyname 从本地trusted数据库删除key。
  • apt-key update 更新本地trusted数据库,删除过期没用的key
rpm -qa

Redhat/Centos 体系

  • rpm -qa //查询所有 query all
  • rpm -e //e erase 擦除
yum

Centos

  • /etc/yum.repos.d/CentOS-Base.repo
  • yum install java-11-openjdk.x86_64 //安装
  • yum erase java-11-openjdk.x86_64 //删除

System Info

poweroff

关机

date

查看系统时间

lscpu

查看cpu 信息

Architecture:        x86_64 //CPU架构
CPU op-mode(s):      32-bit, 64-bit
Byte Order:          Little Endian
CPU(s):              4  //核数
On-line CPU(s) list: 0-3 
Thread(s) per core:  1
Core(s) per socket:  4
Socket(s):           1
NUMA node(s):        1
Vendor ID:           GenuineIntel
CPU family:          6
Model:               55
Model name:          Intel(R) Celeron(R) CPU  J1900  @ 1.99GHz  //英特尔目前的赛扬处理器
Stepping:            8
CPU MHz:             1965.612
CPU max MHz:         2415.7000
CPU min MHz:         1332.8000
BogoMIPS:            3998.40
Virtualization:      VT-x
L1d cache:           24K
L1i cache:           32K
L2 cache:            1024K
NUMA node0 CPU(s):   0-3
Flags:               fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology tsc_reliable nonstop_tsc cpuid aperfmperf tsc_known_freq pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 cx16 xtpr pdcm sse4_1 sse4_2 movbe popcnt tsc_deadline_timer rdrand lahf_lm 3dnowprefetch epb pti tpr_shadow vnmi flexpriority ept vpid tsc_adjust smep erms dtherm ida arat
查看系统版本
  • uname -a

包含主机名 内核版本 等信息 没有系统版本

  • cat /proc/version

比 uname -a 多系统版本号

  • cat /proc/sys/kernel/hostname

查看主机名

查看release name
  • lsb_release -a
  • lsb_release -cs
  • cat /etc/lsb-release
  • cat /etc/os-release
修改主机名
  • hostname xxx

临时修改主机名

  • vim /etc/hostname

永久修改主机名

查看apache版本
  • /usr/sbin/httpd -v
查看内存使用情况
  • free
  • free -h

所有的信息都是从/proc/meminfo读出来的

              total        used        free      shared  buff/cache   available
Mem:           3.9G        2.0G        128M        5.6M        1.7G        1.6G
Swap:          947M          0B        947M
              total        used        free      shared  buff/cache   available
Mem:        4039640     2144564      129152        5680     1765924     1628508
Swap:        969964           0      969964
cat /proc/meminfo
MemTotal:        4039640 kB
MemFree:          129440 kB
MemAvailable:    1628628 kB
Buffers:          147656 kB
Cached:          1506656 kB
SwapCached:            0 kB
Active:          2485272 kB
Inactive:        1249300 kB
Active(anon):    1786608 kB
Inactive(anon):   299332 kB
Active(file):     698664 kB
Inactive(file):   949968 kB
Unevictable:           0 kB
Mlocked:               0 kB
SwapTotal:        969964 kB
SwapFree:         969964 kB
Dirty:               564 kB
Writeback:             0 kB
AnonPages:       2080288 kB
Mapped:           272320 kB
Shmem:              5680 kB
Slab:             130608 kB
SReclaimable:     111444 kB
SUnreclaim:        19164 kB
KernelStack:        9008 kB
PageTables:        13256 kB
NFS_Unstable:          0 kB
Bounce:                0 kB
WritebackTmp:          0 kB
CommitLimit:     2989784 kB
Committed_AS:    3241088 kB
VmallocTotal:   34359738367 kB
VmallocUsed:           0 kB
VmallocChunk:          0 kB
HardwareCorrupted:     0 kB
AnonHugePages:         0 kB
ShmemHugePages:        0 kB
ShmemPmdMapped:        0 kB
CmaTotal:              0 kB
CmaFree:               0 kB
HugePages_Total:       0
HugePages_Free:        0
HugePages_Rsvd:        0
HugePages_Surp:        0
Hugepagesize:       2048 kB
DirectMap4k:       81792 kB
DirectMap2M:     4112384 kB
DirectMap1G:     2097152 kB
df -h

显示目前在Linux系统上的文件系统的磁盘使用情况统计

du -sh *

查看当前目录下的所有文件的空间占用

sysctl

configure kernel parameters at runtime
sysctl is used to modify kernel parameters at runtime.

Network System

ip link

查看网卡

ifconfig
  • 配置enpls0网卡的子网卡 虚拟IP
    • ifconfig enp1s0:0 192.168.3.77 netmask 255.255.255.0 up
    • ifconfig enp1s0:0 192.168.3.77 netmask 255.255.255.0 up
ssh
  • ssh root@ip -p [port]
  • ssh -A //开启身份认证代理转发
ssh-add
  • ssh-add -L //显示ssh-agent中的公钥
  • ssh-add -l //显示ssh-agent中的密钥
  • ssh-add -d [path] //删除密钥
  • ssh-add -D 删除所有的密钥
ssh-copy-id
  • ssh-copy-id -i ~/.ssh/id_rsa.pub user@hostname
  • ssh-copy-id -i ~/.ssh/id_rsa.pub -p port user@hostname
-i identity_file
             Use only the key(s) contained in identity_file (rather than looking for identities via ssh-add(1) or in
             the default_ID_file).  If the filename does not end in .pub this is added.  If the filename is omitted,
             the default_ID_file is used.
scp
  • scp -P [port]
nslookup www.baidu.com

DNS 解析

nc -vuz ip port
  • nc -vuz 10.153.91.4 3478

UDP 端口

wget
  • wget -O filename www.baidu.com //保存文件当中
  • wget -O - www.baidu.com //输出到终端
curl ifconfig.me

查看外网ip

netstat -rn

查看路由信息

route -n

Kernel IP routing table

配置路由
  • ip route add 10.176.48.0/20 via 10.173.32.1 dev eth0

就说明要去 10.176.48.0/20 这个目标网络,要从 eth0 端口出去,经过 10.173.32.1。

  • ip route add 101.201.212.114/32 via 192.168.3.1 dev enp1s0
删除路由
  • route del –host 192.168.168.110 dev eth0

performance

iostat
-U   // Display system load averages.  This is on by default, unless -d is
           specified.

-w   // Pause wait seconds between each display.  
    If no repeat count is specified,
    the default is infinity.
uptime

当前时间、系统运行时间、当前用户数。
1分钟、5分钟、15分钟的平均负载

DESCRIPTION
     The uptime utility displays the current time, the length of time the sys-
     tem has been up, the number of users, and the load average of the system
     over the last 1, 5, and 15 minutes.
vmstat

查看内存使用情况

pidstat
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值