欢迎来到starnight_cyber的博客

linux常用命令

  有一部分linux命令已经很熟了,就不多列出来,就记录一些可能用的比较多的,自己不熟的,作为个人笔记,仅服务于自己!

首先要介绍的是whatis、info命令

0、whatis、info: 解析命令的意思

root@kali:~/temp# whatis whoami
whoami (1)           - print effective userid
root@kali:~/temp# whatis ls
ls (1)               - list directory contents

info:详细解析命令的意思(可能有些系统不支持)

1、finger: 显示系统用户信息。

The finger displays information about the system users.
root@kali:~# finger root
Login: root                       Name: root
Directory: /root                        Shell: /bin/bash
On since Thu Dec 15 19:57 (EST) on tty2 from :0
   18 minutes 43 seconds idle
No mail.
No Plan.

2、whereis: 查找指定的二进制文件,源文件和手动文件命令名称。

whereis locates the binary, source and manual files for  the  specified command  names.
root@kali:~# whereis ls
ls: /bin/ls /usr/share/man/man1/ls.1.gz
lz@ubuntu:~/test$ which ls
/bin/ls

3、查看环境变量

root@kali:~# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

4、链接ln

 5、计算文件中的行数、字数、字节数: wc

-c, --bytes            print the byte counts
-m, --chars            print the character counts
-l, --lines            print the newline counts
      --files0-from=F    read input from the files specified by
                           NUL-terminated names in file F;
                           If F is - then read names from standard input
-L, --max-line-length  print the maximum display width
-w, --words            print the word counts
root@kali:~/temp# cat 1.txt | wc -l
13
root@kali:~# wc -l pass.txt
15 pass.txt

6、正则搜索: grep

Globally search a Regular Expression and Print
ls -l | grep '^d'  只把目录列出来

7、开机自启动: chkconfig

chkconfig --list       这个命令会列出所有的服务项
chkconfig mysql on      设置mysql开机启动
chkconfig iptables off   防火墙不自启

8、查看文件: vi、vim、cat、nl、less、more等

cat -n 1.txt    查看文件内容,显示行号,顺序读
tac 1.txt     查看文件内容,显示行号,逆序读
head -n 3 1.txt  查看前三行的内容
tail -n 3 1.txt  查看后三行的内容

9、设置、查看文件隐藏属性: chattr、lsattr

lz@ubuntu:~/test$ ls
lz@ubuntu:~/test$ > 1
lz@ubuntu:~/test$ sudo chattr +i 1    #为文件1增加隐藏属性
lz@ubuntu:~/test$ lsattr 1          #查看文件的隐藏属性
----i--------e- 1
lz@ubuntu:~/test$ sudo rm 1         #即使是root用户也不能删除
rm: cannot remove `1': Operation not permitted
lz@ubuntu:~/test$ sudo chattr -i 1     #需要先删除隐藏属性
lz@ubuntu:~/test$ lsattr 1
-------------e- 1
lz@ubuntu:~/test$ rm 1
lz@ubuntu:~/test$ ls
lz@ubuntu:~/test$ 

10、查看文件类型: file

lz@ubuntu:~/test$ file 1
1: ASCII text

12、lsof

查看端口占用情况:

root@wordpress:~# sudo lsof -i :80
COMMAND  PID     USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
apache2 5754     root    4u  IPv6  45735      0t0  TCP *:http (LISTEN)
apache2 5759 www-data    4u  IPv6  45735      0t0  TCP *:http (LISTEN)
apache2 5761 www-data    4u  IPv6  45735      0t0  TCP *:http (LISTEN)
apache2 5762 www-data    4u  IPv6  45735      0t0  TCP *:http (LISTEN)
apache2 5763 www-data    4u  IPv6  45735      0t0  TCP *:http (LISTEN)
apache2 5764 www-data    4u  IPv6  45735      0t0  TCP *:http (LISTEN)
apache2 5794 www-data    4u  IPv6  45735      0t0  TCP *:http (LISTEN)

查看进程打开了哪些文件或套接字:

root@wordpress:~# sudo lsof -p 5754
lsof: WARNING: can't stat() fuse.gvfsd-fuse file system /run/user/1000/gvfs
      Output information may be incomplete.
COMMAND  PID USER   FD   TYPE DEVICE SIZE/OFF    NODE NAME
apache2 5754 root  cwd    DIR    8,1     4096       2 /
apache2 5754 root  rtd    DIR    8,1     4096       2 /
apache2 5754 root  txt    REG    8,1   662496  395067 /usr/sbin/apache2
...

小命令集锦:

date     显示时间
cal      显示日历
bc       简易计算器
sync     系统同步写入磁盘

...

root@kali:~/temp# ls -lrt    [按时间排序,以列表的方式显示目录项]
root@kali:~/temp# ls | cat -n  [给每项文件前面增加一个id编号]

 查看文件大小:

root@kali:~/temp# du -sh 1.txt 
4.0K	1.txt

统计文件行数:

root@kali:~/temp# wc -l 1.txt

消除重复行:

root@kali:~/temp# sort 1.txt | uniq

统计各行在文件中出现的次数:

root@kali:~/temp# sort 1.txt | uniq -c

找出重复行:

root@kali:~/temp# sort 1.txt | uniq -d

只查看ip:

root@kali:~/temp# ifconfig eth0 | grep inet
        inet 192.168.1.108  netmask 255.255.255.0  broadcast 192.168.1.255
        inet6 fe80::20c:29ff:fef1:854e  prefixlen 64  scopeid 0x20<link>

查看系统位数:

root@kali:~/temp# getconf LONG_BIT
64

查看系统版本:

root@kali:~/temp# lsb_release -a
No LSB modules are available.
Distributor ID:	Kali
Description:	Kali GNU/Linux Rolling
Release:	kali-rolling
Codename:	kali-rolling

查看CPU的个数:

root@kali:~/temp# cat /proc/cpuinfo | grep processor | wc -l
2

查看系统信息的一些命令:
查看系统内核版本:

root@kali:~/temp# uname -a
Linux kali 4.9.0-kali4-amd64 #1 SMP Debian 4.9.30-2kali1 (2017-06-22) x86_64 GNU/Linux
root@kali:~/temp# uname -r
4.9.0-kali4-amd64
root@kali:~/temp# cat /proc/version
Linux version 4.9.0-kali4-amd64 (devel@kali.org) (gcc version 6.3.0 20170516 (Debian 6.3.0-18) ) #1 SMP Debian 4.9.30-2kali1 (2017-06-22)

显示处理器架构:

root@kali:~/temp# uname -m
x86_64

显示CPU 信息:

root@kali:~/temp# cat /proc/cpuinfo

查看内存使用:

root@kali:~/temp# cat /proc/meminfo 

显示网络适配器及统计信息:

root@kali:~/temp# cat /proc/net/dev
Inter-|   Receive                                                |  Transmit
 face |bytes    packets errs drop fifo frame compressed multicast|bytes    packets errs drop fifo colls carrier compressed
    lo: 314275532 1664503    0    0    0     0          0         0 314275532 1664503    0    0    0     0       0          0
  eth0:  906160   12050    0    0    0     0          0         0  5606150    4140    0    0    0     0       0          0

查看已加载的文件系统:

root@kali:~/temp# cat /proc/mounts 

参考链接
  【玩转Linux系列】Linux基础命令

posted @ 2016-12-23 17:32  starnight_cyber  阅读(517)  评论(0编辑  收藏  举报