bjghzly 发表于 2018-8-19 09:58:31

在linux下,如何将shell里输出的信息写入到文件里呢?

在linux下,如何将shell里输出的信息写入到文件里呢?  通过下面的两个管道符可以实现些功能。
  >               将信息写入文件
  >>             在现有文件中追加信息
  如:
  linux-a9c6:~ # ps -A
  PID TTY          TIME CMD
  1 ?      00:00:01 init
  2 ?      00:00:00 kthreadd
  3 ?      00:00:00 migration/0
  4 ?      00:00:02 ksoftirqd/0
  5 ?      00:00:00 watchdog/0
  6 ?      00:00:00 migration/1
  7 ?      00:00:06 ksoftirqd/1
  8 ?      00:00:00 watchdog/1
  9 ?      00:00:00 events/0
  10 ?      00:00:00 events/1
  11 ?      00:00:00 cpuset
  12 ?      00:00:00 khelper
  13 ?      00:00:00 netns
  14 ?      00:00:00 async/mgr
  15 ?      00:00:00 kintegrityd/0
  16 ?      00:00:00 kintegrityd/1
  17 ?      00:00:00 kblockd/0
  18 ?      00:00:00 kblockd/1
  19 ?      00:00:00 kacpid
  20 ?      00:00:00 kacpi_notify
  21 ?      00:00:00 ksuspend_usbd
  22 ?      00:00:00 khubd
  23 ?      00:00:00 kseriod
  24 ?      00:00:00 kondemand/0
  25 ?      00:00:00 kondemand/1
  26 ?      00:00:00 khungtaskd
  27 ?      00:00:00 pdflush
  28 ?      00:00:00 pdflush
  29 ?      00:00:00 kswapd0
  30 ?      00:00:00 aio/0
  31 ?      00:00:00 aio/1
  32 ?      00:00:00 crypto/0
  33 ?      00:00:00 crypto/1
  36 ?      00:00:00 kpsmoused
  64 ?      00:00:00 ata/0
  65 ?      00:00:00 ata/1
  66 ?      00:00:00 ata_aux
  67 ?      00:00:00 scsi_eh_0
  68 ?      00:00:00 scsi_eh_1
  69 ?      00:00:00 scsi_eh_2
  70 ?      00:00:00 scsi_eh_3
  71 ?      00:00:01 scsi_eh_4
  72 ?      00:00:00 scsi_eh_5
  619 ?      00:00:00 kjournald2
  715 ?      00:00:00 udevd
  1125 ?      00:00:00 kmmcd
  1145 ?      00:00:00 kmemstick
  1306 ?      00:00:00 usbhid_resumer
  1429 ?      00:00:00 hd-audio0
  1528 ?      00:00:00 kauditd
  1542 ?      00:00:00 kstriped
  1627 ?      00:00:00 kjournald2
  2089 ?      00:00:00 acpid
  2106 ?      00:00:00 klogd
  2110 ?      00:00:00 syslog-ng
  2111 ?      00:00:01 dbus-daemon
  2134 ?      00:00:00 gdm
  2142 ?      00:00:00 startpar
  2298 ?      00:00:00 gdm-simple-slav
  2325 tty7   00:16:08 Xorg
  2517 ?      00:00:00 nmbd
  2704 ?      00:00:00 rpcbind
  2732 ?      00:00:00 kconservative/0
  2734 ?      00:00:00 kconservative/1
  2746 ?      00:00:01 hald
  2800 ?      00:00:00 console-kit-dae
  2863 ?      00:00:00 hald-runner
  2875 ?      00:00:00 hald-addon-inpu
  2902 ?      00:00:00 hald-addon-gene
  2921 ?      00:00:02 hald-addon-stor
  2923 ?      00:00:00 hald-addon-cpuf
  2924 ?      00:00:00 hald-addon-acpi
  2997 ?      00:00:00 dbus-launch
  3069 ?      00:00:00 avahi-daemon
  3148 ?      00:00:00 cupsd
  3172 ?      00:00:00 mysqld_safe
  3213 ?      00:00:04 mysqld
  3321 ?      00:00:00 devkit-power-da
  3323 ?      00:00:00 devkit-daemon
  3571 ?      00:00:00 httpd2-prefork
  3600 ?      00:00:00 mono
  3601 ?      00:00:00 httpd2-prefork
  3602 ?      00:00:00 httpd2-prefork
  3603 ?      00:00:00 httpd2-prefork
  3604 ?      00:00:00 httpd2-prefork
  3605 ?      00:00:00 httpd2-prefork
  3691 ?      00:00:00 nscd
  3734 ?      00:00:00 sshd
  3772 ?      00:00:00 smartd
  3802 ?      00:00:00 smbd
  3815 ?      00:00:00 master
  3849 ?      00:00:00 smbd
  3861 ?      00:00:00 cron
  3943 ?      00:00:00 gdm-session-wor
  3976 tty1   00:00:00 mingetty
  3977 tty2   00:00:00 mingetty
  3978 tty3   00:00:00 mingetty
  3982 tty4   00:00:00 mingetty
  3983 tty5   00:00:00 mingetty
  3986 tty6   00:00:00 mingetty
  4023 ?      00:00:00 gnome-keyring-d
  4039 ?      00:00:00 gnome-session
  4138 ?      00:00:02 scim-launcher
  4145 ?      00:00:00 scim-launcher
  4184 ?      00:00:00 gpg-agent
  4185 ?      00:00:00 ssh-agent
  4196 ?      00:00:00 dbus-launch
  4197 ?      00:00:00 dbus-daemon
  4200 ?      00:00:01 gconfd-2
  4204 ?      00:00:02 gnome-settings-
  4212 ?      00:00:00 gvfsd
  4217 ?      00:00:00 gvfs-fuse-daemo
  4226 ?      00:00:11 metacity
  4230 ?      00:00:21 gnome-panel
  4231 ?      00:00:34 nautilus
  4237 ?      00:00:00 gvfs-hal-volume
  4239 ?      00:00:00 gvfs-gphoto2-vo
  4244 ?      00:00:00 bluetooth-apple
  4245 ?      00:00:00 python
  4251 ?      00:00:00 gnome-volume-co
  4252 ?      00:00:00 gpk-update-icon
  4267 ?      00:01:32 pulseaudio
  4271 ?      00:00:00 nm-applet
  4281 ?      00:00:00 gnome-power-man
  4282 ?      00:00:00 bluetoothd
  4296 ?      00:00:00 bluetooth
  4302 ?      00:00:00 gconf-helper
  4309 ?      00:00:00 krfcommd
  4365 ?      00:00:00 bonobo-activati
  4419 ?      00:00:00 nm-system-setti
  4429 ?      00:00:00 gvfsd-trash
  4446 ?      00:00:01 tomboy
  4448 ?      00:00:01 mini_commander_
  4466 ?      00:00:00 gvfsd-burn
  4485 ?      00:00:01 scim-bridge
  4490 ?      00:00:00 mount.ntfs-3g
  4503 ?      00:00:00 mount.ntfs-3g
  4510 ?      00:00:00 mount.ntfs-3g
  4520 ?      00:00:00 mount.ntfs-3g
  4527 ?      00:00:02 gnome-screensav
  4532 ?      00:00:00 gvfsd-computer
  4845 ?      00:00:04 wineserver
  4848 ?      00:00:00 services.exe
  4850 ?      00:00:00 winedevice.exe
  4858 ?      00:00:01 iexplore.exe
  4860 ?      00:00:00 explorer.exe
  7980 ?      00:00:00 scim-helper-man
  7981 ?      00:00:03 scim-panel-gtk
  8299 ?      00:00:00 pickup
  8308 ?      00:00:00 qmgr
  8793 ?      00:00:00 firefox
  8798 ?      00:05:23 firefox
  9070 ?      00:00:00 gnome-terminal
  9071 ?      00:00:00 gnome-pty-helpe
  9072 pts/0    00:00:00 bash
  9097 pts/0    00:00:00 ps
  linux-a9c6:~ # ps -A > /root/1.txt
  linux-a9c6:~ # ls | find 1.txt
  1.txt
  linux-a9c6:~ #

页: [1]
查看完整版本: 在linux下,如何将shell里输出的信息写入到文件里呢?