Linux admin random notes

Notes relating to Linux admin topics.

Just a collection of morsels I dug up and don’t want to lose track of.

Convert man page to text

[2005-xx-xx] Output from the man command is mostly plain text, so you’d think that:

man somepage > textfile.txt

… would work. However, man page output includes backspace-overtype sequences, such as for underlines, (and possibly for bold), so the result of the above is poor-to-unreadable.

Instead, to get man pages to turn into text nicely:

man something | col -b > man_something.txt

Ie: Pipe man page to col, use -b option to subvert overtyping backspace chars. (2009-02-08: Sadly this doesn’t replace the sometimes-used non-ASCII single-quotes.)

Disk consumption


“disk usage”

Roll-up of space used by directory branch:

Total in one dir only (-d option specifies depth: -d 0, where 0=zero)

du -d 0 -h [somedir]

Dir, and subtotals of top dirs within (-d 1)

du -d 1 -h [somedir]

“disk free”

Summary of space used/free by device

df -h

Examples of find command


Find files with names or paths matching certain patterns. (Note the dots, meaning start at current dir)

find . -name "*xyz.txt"

find . -path "*/somedir/*/*xyz.txt"

Find all links
find . -type l

Interesting grep variations


grep [options] PATTERN [FILE…]
grep [options] [-e PATTERN | -f FILE] [FILE…]

grep <pattern> <filepattern>
is the basic command.

  • <filepattern> can specify wildcard characters.
  • Put quotes on <pattern> if it has spaces.
  • Use -e <pattern> if <pattern> has leading hyphen
  • Ignore case: -i

Beyond that, we frequently want to apply grep to recurse directories, and this requirement apparently has a long history of controversy, as it requires being able to specify name patterns for the directories to be drilled into and the files to be inspected. Further, one might want patterns to include, or to exclude dirs or files. Traditionally this was dealt with using find and xargs which involves a substantial cognitive overload trying to figure out and then remember needed options, what needs to be quoted against shell expansion and so on.

Anyhow, as of Centos 5.2 which includes GNU grep 2.5.1, grep’s recursive capabilities appear to be:

  • -R or -r option tells to recurse directories. Directories recursed and files inspected both have to match <filepattern>, which is stupid.
  • Instead, add –include=<includepattern> or –exclude=<excludepattern> as the way to spec the files to be examined. The trailing <filepattern> continues to spec directories to search (but untested by me is whether that dir spec applies just to the top level (as it would if expanded by the shell) or whether you can pass the spec to grep. One probably needs to guard both patterns against shell expansion and see if that does the right thing.

See man page for more.

Create a link


I use this just infrequently enough that I forget the argument order.

ln -s   existing_file_or_dir    name_for_link

(I guess it’s sort of the same order as cp or mv… so long as you’re thinking straight.)

Relating to configure (for install-from-source).

Some docs:


Post a Comment

Required fields are marked *


%d bloggers like this: