Linux下的常用命令若干

目录:

控制操作符 ;/ &&/ ||

tar -C

mkdir -p

查看 IP

pgrep

ps/ top/ pstree/

ctrl-c/ ctrl-z/ jobs/ kill/ fg/ bg

ln

history

df/du/磁盘相关

source

---------------------------------------------------------------------------

ASCII编码

$ man ascii

 For convenience, let us give more compact tables in hex and decimal.

          2 3 4 5 6 7       30 40 50 60 70 80 90 100 110 120
        -------------      ---------------------------------
       0:   0 @ P ` p     0:    (  2  <  F  P  Z  d   n   x
       1: ! 1 A Q a q     1:    )  3  =  G  Q  [  e   o   y
       2: " 2 B R b r     2:    *  4  >  H  R  \  f   p   z
       3: # 3 C S c s     3: !  +  5  ?  I  S  ]  g   q   {
       4: $ 4 D T d t     4: "  ,  6  @  J  T  ^  h   r   |
       5: % 5 E U e u     5: #  -  7  A  K  U  _  i   s   }
       6: & 6 F V f v     6: $  .  8  B  L  V  `  j   t   ~
       7: ´ 7 G W g w     7: %  /  9  C  M  W  a  k   u  DEL
       8: ( 8 H X h x     8: &  0  :  D  N  X  b  l   v
       9: ) 9 I Y i y     9: ´  1  ;  E  O  Y  c  m   w
       A: * : J Z j z
       B: + ; K [ k {
       C: , < L \ l |
       D: - = M ] m }
       E: . > N ^ n ~
       F: / ? O _ o DEL

-----------------------------------------------------------------

日历查看

$ cal
      May 2014        
Su Mo Tu We Th Fr Sa  
             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  
-----------------------------------------------------------------------

查看文件的16进制

xxd: make a hexdump or do the reverse

$ xxd goagent 
0000000: 2321 2f62 696e 2f73 680a 230a 2320 676f  #!/bin/sh.#.# go
0000010: 6167 656e 7420 696e 6974 2073 6372 6970  agent init scrip
0000020: 740a 230a 0a23 2323 2042 4547 494e 2049  t.#..### BEGIN I
0000030: 4e49 5420 494e 464f 0a23 2050 726f 7669  NIT INFO.# Provi
0000040: 6465 733a 2020 2020 2020 2020 2020 676f  des:          go
0000050: 6167 656e 740a 2320 5265 7175 6972 6564  agent.# Required
0000060: 2d53 7461 7274 3a20 2020 2024 7379 736c  -Start:    $sysl
0000070: 6f67 0a23 2052 6571 7569 7265 642d 5374  og.# Required-St
0000080: 6f70 3a20 2020 2020 2473 7973 6c6f 670a  op:     $syslog.




-----------------------------------------------------------------------

&&:当上一个命令返回0退出状态,才执行下一条命令

||:当上条命令返回非0退出,才执行下一条命令

---------------------------------------------------------------------------

解压文件到指定目录

$ tar xvf -C tmp/a/b/c newarc.tar.gz

---------------------------------------------------------------------------

mkdir 创建目录树

~ $ mkdir -p tmp/a/b/c

$ mkdir -p project/{lib/ext,bin,src,doc/{html,info,pdf},demo/stat/a}

-------------------------------------------------------------------------

ifconfig.me 是家网站

shawn@EP43:~$ curl ifconfig.me
112.65.201.240

-------------------------------------------------

pgrep

--------------------------------------------------------------------------
ps/  top/


ps -l : 当前环境bash的进程
shawn@EP43:~/program$ ps -l
F S   UID   PID  PPID  C PRI  NI ADDR SZ WCHAN  TTY          TIME CMD
0 S  1000  3122  3114  0  80   0 -  7026 wait   pts/1    00:00:00 bash
0 R  1000  4733  3122  0  80   0 -  3484 -      pts/1    00:00:00 ps
0 T  1000 28784  3122  0  80   0 - 109002 signal pts/1   00:00:01 python
0 S  1000 32586     1  0  80   0 -  7829 poll_s pts/1    00:01:14 adb


ps aux:列出系统所有进程
shawn@EP43:~/program$ ps aux
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root         1  0.0  0.0  24480  2032 ?        Ss   09:03   0:00 /sbin/init
root         2  0.0  0.0      0     0 ?        S    09:03   0:00 [kthreadd]
...
shawn    32586  0.8  0.0  31316  1156 pts/1    Sl   18:01   1:14 adb -P 5037 for
shawn    32721  1.0  2.9 1311152 120768 ?      Sl   18:09   1:26 /usr/lib/chromi


top:动态显示进程状况
    -d [刷新秒数间隔]
    -p [pid]
在 top 執行過程當中可以使用的按鍵指令:
? :顯示在 top 當中可以輸入的按鍵指令;
P :以 CPU 的使用資源排序顯示;
M :以 Memory 的使用資源排序顯示;
N :以 PID 來排序喔!
T :由該 Process 使用的 CPU 時間累積 (TIME+) 排序。
k :給予某個 PID 一個訊號  (signal)
r :給予某個 PID 重新制訂一個 nice 值。
q :離開 top 軟體的按鍵。


free -m
shawn@EP43:~/program$ free -m
             total       used       free     shared    buffers     cached
Mem:          3951       3588        362          0         55       1061
-/+ buffers/cache:       2471       1479
Swap:         8198         23       8175






---------------------------------------------------------------------------------------------
ctrl-c/ ctrl-z/ jobs/ kill/ fg/ bg


Ctrl-c:中断当前执行的命令,有时未必有响应。
Ctrl-z:挂起(suspend)当前执行的命令,使其进入背景中 stopped状态
jobs:查看背景中的状态
     参数:-l  :除了列出 job number 與指令串之外,同時列出 PID 的號碼;
               -r  :僅列出正在背景 run 的工作;
               -s  :僅列出正在背景當中暫停 (stop) 的工作。
shawn@EP43:~$ jobs -l
[1]  14042 Stopped                 ping www.googlesource.com
[2]- 14043 Stopped                 vim
[3]+ 14044 Stopped                 ping www.google.cn




fg/bg:将背景中的进程放入前景/背景
例子:   fg %n
              bg +/-


kill :
選項與參數:
        -l  :這個是 L 的小寫,列出目前 kill 能夠使用的訊號 (signal) 有哪些?
        signal :代表給予後面接的那個工作什麼樣的指示囉!用 man 7 signal 可知:
        -1 :重新讀取一次參數的設定檔 (類似 reload);
        -2 :代表與由鍵盤輸入 [ctrl]-c 同樣的動作;
        -9 :立刻強制刪除一個工作;
        -15:以正常的程序方式終止一項工作。與 -9 是不一樣的。

=======================================================

ln

Usage: ln [OPTION]... [-T] TARGET LINK_NAME   (1st form)
  or:  ln [OPTION]... TARGET                  (2nd form)
  or:  ln [OPTION]... TARGET... DIRECTORY     (3rd form)
  or:  ln [OPTION]... -t DIRECTORY TARGET...  (4th form)
In the 1st form, create a link to TARGET with the name LINK_NAME.
In the 2nd form, create a link to TARGET in the current directory.
In the 3rd and 4th forms, create links to each TARGET in DIRECTORY.


ln的文件保持同步性


-s, --symbolic              make symbolic links instead of hard links

软链接,占空间小,可跨分区

无则为硬链接,占用和target文件同样大小的空间,不可跨分区


例子:

ln -s test  test.link

-----------------------------------------------------------------------------------------------------------


history 

查看历史命令记录

https://linuxtoy.org/archives/history-command-usage-examples.html

使用 HISTTIMEFORMAT 显示时间戳

当你从命令行执行 history 命令后,通常只会显示已执行命令的序号和命令本身。如果你想要查看命令历史的时间戳,那么可以执行:


# export HISTTIMEFORMAT='%F %T '
# history | more
1  2008-08-05 19:02:39 service network restart
2  2008-08-05 19:02:39 exit
3  2008-08-05 19:02:39 id
4  2008-08-05 19:02:39 cat /etc/redhat-release

注意:这个功能只能用在当 HISTTIMEFORMAT 这个环境变量被设置之后,之后的那些新执行的 bash 命令才会被打上正确的时间戳。在此之前的所有命令,都将会显示成设置 HISTTIMEFORMAT 变量的时间。[感谢 NightOwl 读者补充]

使用 Ctrl+R 搜索历史

Ctrl+R 是我经常使用的一个快捷键。此快捷键让你对命令历史进行搜索,对于想要重复执行某个命令的时候非常有用。当找到命令后,通常再按回车键就可以执行该命令。如果想对找到的命令进行调整后再执行,则可以按一下左或右方向键。


# [Press Ctrl+R from the command prompt, which will display the reverse-i-search prompt]
(reverse-i-search)`red‘: cat /etc/redhat-release
[Note: Press enter when you see your command, which will execute the command from the history]
# cat /etc/redhat-release
Fedora release 9 (Sulphur)


----------------------------------------------------------------------------------------------------

df

以磁盘分区为单位查看文件系统,可以加上参数查看磁盘剩余空间信息,

命令格式:df -hl

参数:  

-h  human-readable

-l local


sahwn@EP43:~/workdir$ df -hl

Filesystem      Size  Used Avail Use% Mounted on
/dev/sda13       17G  4.6G   12G  29% /
udev            2.0G  4.0K  2.0G   1% /dev
tmpfs           791M  916K  790M   1% /run
none            5.0M     0  5.0M   0% /run/lock
none            2.0G  452K  2.0G   1% /run/shm
/dev/sda11      180M   56M  116M  33% /boot
/dev/sda14       37G   29G  5.8G  84% /home



---------------------------------------------------------------------

du

Usage: du [OPTION]... [FILE]...
  or:  du [OPTION]... --files0-from=F

Summarize disk usage of each FILE, recursively for directories.


Arguments:

-h  human readable

-s  summarize, like  --max-depth=0

-m like --block-size=1M

--max-depth=N    print the total for a directory (or file, with --all)
                          only if it is N or fewer levels below the command
                          line argument;


du -sh [目录名] 返回该目录的大小

du -sm [文件夹] 返回该文件夹总M数


du 统计文件大小相加
df  统计数据块使用情况


-----------------------------------------------------------------------

查看硬盘的分区 #sudo fdisk -l

查看IDE硬盘信息 #sudo hdparm -i /dev/hda

查看SATA硬盘信息 #sudo hdparm -I /dev/sda 或 #sudo apt-get install blktool #sudo blktool /dev/sda id

查看硬盘剩余空间 #df -h #df -H

查看目录占用空间 #du -hs 目录名

优盘没法卸载 #sync fuser -km /media/usbdisk

---------------------------------------------------------------------------------------


source

source也被称作点( . )命令, 通常用于立即执行刚更改的文件,而不必退出重新登录。

比如更改了 .bashrc的内容后。


用法:

source filename或 .  filename

也可以把多个shell命令写入一个文件,然后用source执行。


source script_file  和 . script_file的区别:

前者是在当前shell中执行,后者新开一个shell。

比如script中定义了一个变量,使用前者后,可在当前shell中使用之。



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值