Posts Tagged ‘unix命令’

Want to use sed(1) to edit a file in place?  Well, to replace every ‘e’ with
an ‘o’, in a file named ‘foo’, you can do:
        sed -i.bak s/e/o/g foo
And you’ll get a backup of the original in a file named ‘foo.bak’, but if you
want no backup:
        sed -i ” s/e/o/g foo

You can use aliases to decrease the amount of typing you need to do to get
commands you commonly use.  Examples of fairly popular aliases include (in
Bourne shell style, as in /bin/sh, bash, ksh, and zsh):
        alias lf="ls -FA"
        alias ll="ls -lA"
        alias su="su -m"
In csh or tcsh, these would be
        alias lf ls -FA
        alias [...]

If you are running xterm, the default TERM variable will be ‘xterm’.  If you
set this environment variable to ‘xterm-color’ instead, a lot of programs will
use colors.  You can do this by
        TERM=xterm-color; export TERM
in Bourne-derived shells, and
        setenv TERM xterm-color
in csh-derived shells.

To find out the hostname associated with an IP address, use
        dig -x IP_address
                — Dru <genesis@istar.ca>

Need to see the calendar for this month? Simply type "cal".  To see the
whole year, type "cal -y".
                — Dru <genesis@istar.ca>

To change an environment variable in /bin/sh use:
        $ VARIABLE="value"
        $ export VARIABLE

To search for files that match a particular name, use find(1); for example
        find / -name "*GENERIC*" -ls
will search ‘/’, and all subdirectories, for files with ‘GENERIC’ in the name.
        –  Stephen Hilton <nospam@hiltonbsd.com>

If you want df(1) and other commands to display disk sizes in
kilobytes instead of 512-byte blocks, set BLOCKSIZE in your
environment to ‘K’.  You can also use ‘M’ for Megabytes or ‘G’ for
Gigabytes.  If you want df(1) to automatically select the best size
then use ‘df -h’.

Want to know how many words, lines, or bytes are contained in a file? Type
"wc filename".
                — Dru <genesis@istar.ca>