douqin231881 2015-12-22 20:35
浏览 46

对连接的设备的命令行输出进行排序

im working with PHP on my Raspberry PI, and im trying to find a file on a USB drive, this will be in a cron job for every minute...

The file has a name that i will know every time (settings.txt) and i have the required output to figure out what drives i have.. Now i cant figure out how to sort them...

Im writing them all to a text file but they are not spaced with on every line and not with \t between them... how is it possible to get the value of "Mounted On" ?

Output:

Filesystem     1K-blocks    Used Available Use% Mounted on
/dev/root        3648564 3479396    152784  96% /
devtmpfs          469756       0    469756   0% /dev
tmpfs             474060     452    473608   1% /dev/shm
tmpfs             474060    6928    467132   2% /run
tmpfs               5120       4      5116   1% /run/lock
tmpfs             474060       0    474060   0% /sys/fs/cgroup
/dev/mmcblk0p1     65480   20256     45224  31% /boot
tmpfs              94812      48     94764   1% /run/user/1000
/dev/sda1       15625744 5330752  10294992  35% /media/kristian/D81C-745F

Device info: OS: Ubuntu Mate 15.** PHP: 5.6

  • 写回答

2条回答 默认 最新

  • doucuodan0897 2015-12-22 20:40
    关注

    I'd use awk for this. It splits by space by default. For my Mac it was $9 and for one of my Centos boxes it's $6. Just depends on which column your value is. Looks like it's a $6.

    df  | awk '{print $6}'                                                                       
    
    Mounted
    /
    /tmp
    /usr/local
    /var
    /dev
    /Volumes/MobileBackups
    /Volumes/AppCode
    /Volumes/LaCie
    
    评论

报告相同问题?

悬赏问题

  • ¥15 mmocr的训练错误,结果全为0
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀