language and parsing
Quote: "I'm doing a (free) operating system, just a hobby,..." (Linus Torvalds)
This booklet is designed to help with common tasks on a Linux system. It is designed to be presentable as a series of "recipes" for accomplishing common tasks. These recipes consist of a plain English one-line description, followed by the Linux command which carries out the task. The document is focused on performing tasks in Linux using the 'command line' or 'console'. The format of the booklet was largely inspired by the "Linux Cookbook" www.dsl.org/cookbook
@@ http://github.com/himanshuc/nixhacker/tree/master
a good list of resources
@@ http://www.pixelbeat. href="org/cmdline.html">org/cmdline.html
some command lines recipes
@@ http://www.shell-fu.org/
some command line recipes
@@ http://www.commandlinefu.com/
a very good site with lots of command-line tips
@@ http://dsl.org/cookbook/cookbook_toc.html
A very good Linux User "cookbook" and the primary
inspiration for the booklets on this site.
@@ The UNIX Environment (Andrew Walker, Wiley 1984) @@ The Linux Cookbook (Michael Stutz, No Starch Press) @@ The Unix Programming Environment (Kernighan et al)
@@ http://www.catb.org/~esr/writings/taoup/html/
@@ http://www.faqs.org/docs/artu/
a philosophical book about the unix operating system
by Eric Raymond (2003)
@@ http://www.linfo. href="org/onlinebooks.html">org/onlinebooks.html
a list of online linux books
The traditional Unix help system is called 'man' or 'manual' pages. And they can be good. It is one of the ironies and frustrations of Unix that a man page only really becomes helpful and interesting once one already knows what a program does and how to basically use it.
show the short help description for all programs
whatis -r '.*'
for i in $(ls $(echo $PATH | tr ':' ' ')); do whatis $i; done | less
search for all programs which have something to do with 'java'
whatis -r '.*' | grep java
whatis -r 'java'
whatis -r java
view the 'manual' page for the wc (word/line/character count) command
man wc
Sadly, 'man' pages are often written in a cryptic way and are short on examples. The examples, if there are any, are almost always right at the end of the man page.
view the manual page in 'section' 4. See the list of sections, elsewhere
man 4 command
show what software is available to install, relating to 'page layout'
apt-cache search "page layout"
apt-cache search "page layout" | grep -v '^lib' ##(exclude code libraries))
Search all man pages for the word 'dig'
man -k dig ##(does this search just the short description??)
find documentation for latex packages in pdf format
find /usr/share/doc/ -name '*.pdf' ##(on a debian system, at least)
Those users who have no experience with a Unix-style operating system, but are familiar with the Microsoft Windows operating system will experience a kind of 'culture shock' when they begin to use Linux. This is true even if the user is familiar with using the 'command-line' on a Microsoft computer. This section attempts to point out some of the things which may seem baffling and illogical to the new Linux user.
@@ You cant just download an 'exe' and click on it to run it
However you can easily install new software with
'sudo apt-get install
@@ The folder hierarchy in Linux seems very cryptic and you cant
just put files anywhere
log in to the system with a username of 'bob'
log out of the system
switch to the fourth virtual console
switch from the fourth to the third virtual console, press:
switch from X to the first virtual console, press:
run the hostname tool to find the name of the computer
output the version of the hostname tool
run hostname and specifying that the file 'host.info' be read from
change your password
output your username
see who is currently logged in
see who is currently logged in and what they are doing
display information about recent use of the system
find out when the user 'mjb' last logged in
list the processes in your current shell session
list all the processes that user 'hst' has running on the system
This command is useful for listing all of your own processes
list all of the processes and give their user-names
display a continually updated display of the current system processes
list all the processes containing a reference to an 'sbin' directory
list any processes whose process IDs contain a 13 in them
list the process whose PID is 344
Run skype using your GTK theme
output a list of programs that pertain to consoles
output a list of all tools whose pages in the system manual contain a reference to consoles
list all of the software packages installed on the system
list all of the packages whose name or description contains the text "edit," regardless of case
peruse descriptions of the packages that are available
get a description of the who tool
view the manual page for w
view all of the Info manuals on the system
read the Info documentation for the tar tool
This command opens a copy of The GNU tar Manual in info.
To read the contents of a file written in Info format, give the name of
read 'faq.info', an Info file in the current directory
read 'faq.info', an Info file in the current directory, beginning with the node Text
view the HTML version of the Debian FAQ in the lynx Web browser
The above only works on a Debian flavour of Linux.
view the compressed text version of the Debian FAQ in zless,
repeat the last command entered
The [^|] key moves the last command you typed back to the input line,
and executes it.
retrieve the last command you entered with the string 'grep' in it
put the 3rd-last command you entered with 'grep' in it on the input line
clear the screen and then log out of the system
run the hostname command twice times
redirect standard input for apropos to file 'keywords'
redirect standard output of a command to the file 'commands'
append the standard output of apropos shells to the file 'commands'
redirect the standard error of apropos shell bash to 'command.error'
perform a long task in the background, saving all messages to 'img.txt'
In the command above, both error messages (2>) and all normal
output of the command will be redirected to the 'img.txt' text file
in the users home folder.
append the error output of a command to an existing file 'command.error'
redirect the standard output and standard error to the file 'commands'
view the output of "apropos bash shell shells" in a 'pager' program
A pager program allows you to view output from a program one
(screen) page at a time. (pagers: more/less/most)
run the command apropos shell > shell-commands as a background job
run job 4 in the background
Trivia: running a job in the background is sometimes called "backgrounding"
or "amping off" a job.
bring the most recent background job to the foreground
bring job 3 to the foreground
list your jobs
kill job number 2
to interrupt a running command use [control] c
search your command history for the text 'apropos'
specify the second-to-the-last command in your history
Trivia: '!', the exclamation mark is sometimes called "bang"
run history event number 1 (the last command executed)
create a script of a shell session and save it to the file 'log.1'
create the file 'new.txt' in the current directory
create the file 'new' in the 'work/docs' subdirectory of the current directory
On a Unix-style computer, such as Apple OSX or Linux, files do not
have to have 'extensions' to their names, unlike on Microsoft
Windows.
make a new directory called 'work' in the current working directory
create the 'work/completed/2001' directory
If the 'work' and 'completed' folders do not exist, then
they will be created.
change the current working directory to '/usr/doc'
return to the directory you were last in
determine what the current working directory is
list the contents of 'work', a subdirectory in the current directory
list the contents of the '/usr/doc' directory
list the contents of the directory so that directories and executables are distinguished from other files
output a verbose listing of the '/usr/doc/bash' directory
output a recursive listing of the current folder and sub-folders
list all of the files on the system
list the files in the 'log' directory sorted with newest first
The '/var/log' folder usually contains 'log' files which record
the activities of software running on the computer. Type
'man hier' for more information about the Linux folder structure.
list all files in the current directory (including 'hidden' files)
output a tree graph of your home directory and all its subdirectories
show a just the start of a folder tree for the home folder
[>>0.3
peruse a tree graph of the '/usr/local' directory tree
copy the file 'old' to the file `new'
copy files preserving the file attributes
copy the folder 'reports' verbosely (showing what is being done)
copy a folder tree verbosely, but only copy files which are newer
copy the folder 'public_html', and subfolders, to 'private_html'
The cp '-R' option doesnt copy symbolic links. But the "man" page for cp
states that -r and -R are equivalent
make an archive copy of the directory tree 'public' to 'private'
move the file 'notes' in the current working directory to '../play'
move the file '/usr/tmp/notes' to the current working directory,
This command moves the file '/usr/tmp/notes' to the current working
move the directory 'work' in the current working directory to 'play'
rename the file 'notes' to `notes.old'
remove the file 'notes' in the current working directory
remove the directory 'waste' and all of its contents
remove the directory 'empty'
use tab completion to remove the file 'No Way' in the current directory
delete the file '^Acat' in a directory that also contains the files 'cat' and `dog'
remove the file '-cat' from the current directory
create a hard link from 'seattle' to `emerald-city'
create a symbolic link from 'seattle' to `emerald-city'
list all files in the '/usr/bin' directory that have the text 'tex' anywhere in their name
copy all files whose names end with '.txt' to the `doc' subdirectory
output a verbose listing of all files whose names end with either a '.txt' or '.text' extension, sorting the list so that newer files are listed first
remove all files in the current working directory that begin with a hyphen and have the text 'out' somewhere else in their file name
join text files whose names have an 'a' followed by 2 or more characters
The original files are unchanged, but the joined together text files
are displayed on the screen.
change your shell prompt to 'Your wish is my command: '
change your prompt to the default bash prompt (the current folder)
change the prompt to the current date, space, the hostname, and a '>'
clear the screen every time you log out,
search for games software which are available to install
update the repository cache
Add new repositories to the file '
A linux system is capable of playing, recording and editing
sound (audio) files with a variety of open-source software.
This section only provides what should be a very succint overview
of the most important sound tasks with linux. For more detailed
information, please consult the booklet listed below.
@@ http://bumble.sourceforge.net/books/linux-sound/
A more comprehensive introduction to using audio with the
linux operating system.
Synthesize text as speech
find the duration of the audio file 's.wav' in hours/minutes/seconds
record a 'wav' file from the microphone, saving it to 'hello.wav'
This begins an 8,000 Hz, monaural 8-bit WAV recording, which is not
very good quality.
make a high-fidelity recording from the mic and save it to 'goodbye.wav'
play the MP3 stream at the url
It is a common task to need to convert sound files from one
format to another.
translate an audio file in Sun AU format to a Microsoft WAV file,
convert 'sound.mp3' into a wav file 'new.wav' (a new file is created)
encode an MP3 file from a WAV file called 'september-wind.wav'
join the audio files 'a.wav' and 'b.wav' together and save as 'new.wav'
Find UTF-8 text files misinterpreted as ISO 8859-1 due to Byte
show the current locale (language and character encoding)
show a hexdump of a text file
Convert a file from ISO-8859-1 (or whatever) to UTF-8 (or
Convert filenames from ISO-8859-1 to UTF-8
Detect encoding of the text file 'file.txt'
convert file from utf8 (no bom) to utf16 (with 'bom')
convert all '.php' files to the utf-8 text encoding
find utf-8 encoded text files misinterpreted as iso 8859-1
Fix UTF-8 text files misinterpreted as ISO 8859-1 due to Byte
Convert file type to unix utf-8
Convert one file from ISO-8859-1 to UTF-8.
search for all debian packages which have something to do with spelling
spell check the file 'lecture'
prints a list of badly spelled words
print all misspelled words in all ".txt" files with line numbers
spell check the file 'ch.1.txt', with misspellings to the file 'bad.sp'
check the spelling of a word on the command line
This prints 'Korrect' since it is badly spelled
output a sorted list of the misspelled words from 'lecture.draft'
'ispell' is an older and simpler program than 'aspell'
interactively spell check 'report.txt'
install a British English dictionary for the "ispell" spell checker
check and correct the spelling interactively in document "report.txt"
spell check "file.txt" using a british english dictionary
spell check a document written in spanish (using a spanish dictionary)
show what dictionaries are available locally for ispell
the ispell dictionaries are all called "i[language-name]"
spell check and correct "thesis.tex" which is a LaTeX format document
aspell is a more modern and capable spell checking program
@@ http://aspell.net/
the official site
@@ http://aspell. href="net/man-html/index.html">
show options for aspell and available dictionaries
show locally available dictionaries for aspell
install a British and American English dictionary for aspell
install a spanish dictionary for aspell
show all debian packages and dictionaries for aspell
interactively check the spelling of the file "chapter.txt"
check the spelling of "chapter.txt" using British English spelling
check the spelling of "chapter.txt" using a Spanish dictionary
check spelling in the comments in the shell script (lines starting with "#")
checking the spelling in the tex/latex file "chapter.tex"
show available filters for spell-checking particular types of files
spell check a file skipping (ignoring) lines which start with '>'
create a vim "mapping" to use aspell within vim
spell check a file but only between a "*" character and the end of the line
To print a specific line from a file
set the default pager to be the 'most' program
View non-printing characters with cat
See non printable characters like tabulations, CRLF, LF line
@@ http://www.greenwoodsoftware.com/less
the homepage for less
The humble 'less' program is worthy of a second look. Less allows
one to peruse and search a text file, but not alter it. I am
documenting version 429 (year 2008). Less uses vi-like keys
to move around and search.
view the text file 'doc.txt' one screen page at a time
view the text file 'days.txt' starting at the end
view the file 'long.txt' and make searches within less case-insensitive
view the file 'long.txt', with 'semi' case-insensitive searching
make an alias which will make less always semi case-insensitive
within less turn on or off case-insensitive searching
within less see whether searches are case-sensitive or not
view the output of 'grep' starting at the first line which has 'science' in it
follow the end of the log file 'tcp.log' showing new data as it enters
Search for a word in less
go to the 80% position in the file (that is, 80% towards the end)
display less commands
search multiple files for the text 'tree'
Less bookmarks work in the same way as 'vi' or 'vim' bookmarks
mark the current top-of-screen position in the text file as bookmark 'x'
jump to the bookmark x
save text from current top-of-screen to the bookmark 'x' in file 'save.txt'
jump to where you just were (before going to a bookmark)
edit the current file (but the variable $EDITOR or $VISUAL must be set)
Look up the definition of a word
get help for wordnet
show a list of word senses available for the word 'browse',
output a list of words from the dictionary that begin with the string 'homew'
list words in the dictionary containing the string 'dont' regardless of case
list all words in the dictionary that end with 'ing'
list all of the words that are composed only of vowels
output a list of words that rhyme with 'friend', search '/usr/dict/words' for lines ending with `end':
search the WordNet dictionary for nouns that begin with 'homew'
search the WordNet dictionary for nouns and adjectives that begin with 'homew'
list the definitions of the word 'slope'
output all of the synonyms (same meaning) for the noun 'break'
output all of the synonyms for the verb 'break'
output all of the antonyms (opposite meaning) for the adjective 'sad'
A hypernym of a word is a related term whose meaning is more general
output all of the hypernyms for the noun 'cat'
Debian 'dict'
check file 'dissertation' for clichés or other misused phrases, type:
check file 'dissertation' for clichés or other misused phrases, and write the output to a file called 'dissertation.diction'
If you don't specify a file name, diction reads text from the standard
output all lines containing double words in the file 'dissertation'
check the readability of the file 'dissertation'
Like diction, style reads text from the standard input if no text is given
output all sentences in the file 'dissertation' whose ARI is greater than a value of 20
output all sentences longer than 14 words in the file 'dissertation'
output the number of lines, words, and characters in file 'outline'
output the number of characters in file 'classified.ad'
Use wc with the '-w' option to specify that just the number of words be
output the number of words in the file 'story'
output the combined number of words for all the files with a '.txt' file name extension in the current directory
output the number of lines in the file 'outline'
output a word-frequency list of the text file 'naked_lunch',
output a count of the number of unique words in the text file 'naked_lunch'
rank the files rep.a, rep.b, rep.c in order of relevance to keywords 'saving' and `profit'
output a list of any files containing either 'invitation' or 'request' in the `~/mail' directory, ranked in order of relevancy, type:
output a list of any files containing 'invitation' and not 'wedding' in the `~/mail' directory, ranked in order of relevancy, type:
output a list of any files containing 'invitation' and 'party' in the '~/mail' directory, ranked in order of relevancy
format a text file with lines 80 characters long,
use par instead
split a file into a maximum of 10 files on lines containing
'#200', '#400', '#600' etc with output files called "zz00", "zz01", etc
Concatenate lines of to files, one by one
Merges given files line by line
convert from html to text
remove the newline characters from the text file 'autoexec.bat'
add newline characters to all of '.tex' files in the current directory
@@ http://asis.epfl. href="ch/GNU.MISC/recode-3.6/recode_3.html">
Convert encoding of given files from one encoding to another
see also iconv (older)
show possible conversions with the 'recode' tool
convert latin9 (western europe) character encoding to utf8
convert from the local character set to the latin1 encoding saving to "new.txt"
convert to html
convert from utf8 to html with verbose output
convert from MS Windows utf8 to the local character set
The process of 'patching' a text or code file is very important in the
world of open-source development (and therefore in the development of Linux
itself). Patching allows non-linear changes to be made to a file and is
usually used in conjuction with 'diff'
Use colordiff in side-by-side mode, and with automatic column
Compare a file with the output of a command or compare the output
remote diff with side-by-side ordering.
Diff files on two remote hosts.
show lines that appear in both file1 and file2
find the extra lines in file2
find the extra lines in file1
Compare a remote file with a local file
Generate diff of first 500 lines of two files
compare the files 'manuscript.old' and `manuscript.new'
peruse the files 'olive' and 'green' side by side indicating differences
output a difference report for files 'tree', 'bush', and 'hedge',
update the original file 'manuscript.new' with the patchfile 'manuscript.diff'
Colored diff ( via vim ) on 2 remotes files on your local
vimdiff to remotehost
gnu grep special characters
.. \< - matches beginning of a word
.. \> - matches the end of a word
.. \b - matches a word boundary
.. [:upper:] - matches upper case letters (unicode)
.. [:lower:] - matches lower case letters (unicode)
.. [:space:] - matches space characters
..
,,,
00-
the "--" sequence may be "escaped" in grep. for example: grep "\-\-" file.txt
search interactively and ignoring case all '.txt' files in this folder
search for lines which begin with "#" in the text file "script"
Basic user commands
....
ubuntu login: bob
logout
press [ALT]-[F4]
[ALT]-[<-]
[CTRL]-[ALT]-[F1]
hostname
hostname --version
hostname -F host.info
passwd
whoami
who
w
last | less
last mjb
Note
: The last tool gets its data from the system file '/var/log/wtmp';
the last line of output tells how far this file goes back.
Basic process commands
....
ps
ps -u hst
ps aux ##(there could be a lot of output, even on single user systems)
top
ps aux | grep sbin
ps aux | grep 13
ps -p 344
Basic software commands
....
skype --disable-cleanlooks -style GTK
apropos consoles
man -k consoles
dpkg -l
dpkg -l | grep -i edit
less /var/lib/dpkg/available
whatis who
man w
info
info tar
info -f faq.info
info -n 'Text' -f faq.info
lynx /usr/share/doc/debian/FAQ/debian-faq.html
zless /usr/doc/debian/FAQ/debian-faq.txt.gz
Basic command line usage
....
[^|]
(reverse-i-search)'': grep
[Control]-r
(reverse-i-search)'': grep
clear; logout
hostname; hostname
apropos < keywords
apropos shell bash > commands
apropos shells >> commands
apropos shell bash 2> command.error
find / | xargs file | grep image &>~/img.txt &
apropos shells 2>> command.error
apropos shells &> commands
apropos bash shell shells | less
apropos shell > shell-commands &
bg %4
fg
fg %3
jobs
kill %2
find / -name '*e*'
[control] c
history | grep apropos
[^|] [^|]
!1
script log.1
Simple file commands
....
touch new.txt
touch work/docs/new
mkdir work
mkdir -p work/completed/2001
mkdir --parents work/completed/2001 ##(the same)
Simple folder commands
....
cd /usr/share/doc
cd -
pwd
ls work
ls /usr/doc
ls -F
ls -l /usr/doc/bash
ls -R
ls -R /
ls -t /var/log
ls -a
tree ~ ##(this shows files as well as folders)
tree -d /usr/local | head -20
image/eg-tree.png]
tree -d /usr/local | less
Copying files
....
cp old new
cp -p file.txt new-copy.txt
cp -vr reports ~/new/
cp -vur docs/office ~/docs
cp -R public_html private_html
cp -a public_html private_html
Moving files
....
mv notes ../play
mv /usr/tmp/notes .
mv work play
mv notes notes.old
Note
: to rename multiple files use 'rename'
Deleting files
....
rm notes
rm -R waste
rmdir empty
rm No[TAB] Way
rm -i ?cat ##(rm: remove '^Acat'? y )
rm -- -cat
Symbolic links
....
ln seattle emerald-city
ln -s seattle emerald-city
ls /usr/bin/*tex*
cp *.txt doc
ls -lt *.txt *.text
rm -- -*out*
cat a??*
The bash prompt
....
PS1='Your wish is my command: '
PS1='\w $ '
PS1='\d (\h)>'
clear ##(put this in the file '.bash_logout')
Installing software
apt-cache search game
sudo apt-get update
/etc/apt/sources.list'
Sound
echo "hello world " | festival --tts
soxi -d s.wav
soxi s.wav | grep -i duration ##(the same)
Recording audio
....
rec hello.wav
rec -s w -c 2 -r 44100 goodbye.wav
rec -s w -c 2 -r 44100 goodbye.wav
Playing audio
....
mpg321 http://example.net/broadcast/live.mp3
Converting audio file formats
....
sox recital.au recital.wav
mpg321 -w new.wav old.mp3 ##(the file 'old.mp3' is unchanged)
mpg123 -w new.wav old.mp3 ##(the same)
lame september-wind.wav september-wind.mp3
Editing sound
....
sox a.wav b.wav new.wav
Converting audio files
....
Translation
Unicode
find . -type f | grep -rl $'\xEF\xBB\xBF'
locale
hd file.txt
hexdump file.txt #(the format is a little different)
Text file encodings
tcs -f 8859-1 -t utf /some/file
convmv -r -f ISO-8859-1 -t UTF-8 --notest *
file -i file.txt ##(-i is the 'mime' switch, but it also shows encoding)
recode UTF8..UTF-16LE linux-utf8-file.txt
find . -name "*.php" -exec iconv -f ISO-8859-1 -t UTF-8 {} -o ../newf/{} \;
find -type f | while read a;do [ "`head -c3 -- "${a}"`" == $'\xef\xbb\xbf' ] && echo "match: ${a}";done
perl -i -pe 's/\xef\xbb\xbf//g'
ex some_file "+set ff=unix fileencoding=utf-8" "+x"
iconv --from-code=ISO-8859-1 --to-code=UTF-8 iso.txt > utf.txt
Spell checking
apt-cache search spell
spell lecture
spell -n -o *.txt
spell ch.1.txt > bad.sp
echo 'is this korrect ?' | spell
spell lecture.draft | sort | uniq
Ispell
....
ispell report.txt
sudo apt-get install ibritish
ispell report.txt
##(when a misspelling is found, type the number of the replacement)
ispell -d british file.txt
ispell -d spanish archivo.txt
ls /usr/lib/ispell/
dictionary files: icatalan, ibrazilian ...
ispell -t thesis.tex ##(ispell ignores the latex mark-up codes)
Aspell
net/man-html/index.html
A usage manual for aspell
aspell help | less
aspell dicts
sudo apt-get install aspell-en
sudo apt-get install aspell-es
apt-cache search aspell
aspell -c chapter.txt
aspell check chapter.txt ##(the same)
Aspell with other languages
....
aspell -d british -c chapter.txt
aspell -d en_GB -c chapter.txt ##(this is the same)
aspell -d spanish -c chapter.txt
aspell -d es -c chapter.txt ##(this is the same)
aspell --mode=comment -c script.sh ##(!!doesnt work on my version)
aspell -t -c chapter.tex
aspell filters
aspell dump filters ##(the same)
aspell --mode=email check book.txt
aspell --mode=email -c book.txt ##(the same)
aspell -e -c book.txt
map TT :w!
aspell --add-filter=context --add-context-delimiters="* \0" -c francisco.txt
##(doesnt really work)
Text files
Viewing text files
....
awk 'FNR==5'
update-alternatives --set pager /usr/bin/most
cat -v -t -e
od -c
Less
....
less doc.txt
less +G days.txt
Starting less
....
less -I long.txt
less -i long.txt ##(searches with capital letters are case-sensitive)
alias less='less -i'
-I [enter]
_I
grep tree forest.txt | less +/science
less +F tcp.log ##(this is like 'tail -f' but allows more perusal)
/\bTERM\b
p80
h
Less with multiple files
........
less *.txt (then type) /*tree
Less bookmarks
........
mx ##(any single letter can be used as a bookmark)
'x
|x cat > save.txt
''
v
Analysing language
....
Dictionaries
....
curl dict://dict.org/d:something
Wordnet
....
man wnintro
man wn
wn browse -over
look homew ##(prints something like 'homeward' and `homework' ...)
grep -i dont /usr/dict/words
grep ing^ /usr/dict/words
grep -i '^[aeiou]*$' /usr/dict/words
grep 'end$' /usr/dict/words
wn homew -grepn
wn homew -grepn -grepa
wn slope -over
wn break -synsn
wn break -synsv
wn sad -antsa
wn cat -hypen
diction dissertation | less
diction dissertation > dissertation.diction
diction dissertation | grep 'Double word'
style dissertation
style -r 20 dissertation
style -l 14 dissertation
wc outline
wc -c classified.ad
wc -w story
cat *.txt | wc -w
wc -l outline
tr ' ' '\n' < naked_lunch | sort | uniq -c
tr ' ' '
> ' < naked_lunch | sort | uniq -c | wc -l
rel "(saving & profit)" report.a report.b report.c
rel "(invitation | request)" ~/mail
rel "(invitation ! wedding)" ~/mail
rel "(invitation & party)" ~/mail
Wrapping text lines
....
fmt -w 80 textfile ##(short lines lengthened)
fmt -s -w 80 textfile ##(short lines are not lengthened)
Splitting text files
....
csplit -f zz file.txt "/^#1?[24680]00$/" {8}
##(the split occurs 'before' the line containing the match)
Merging text files
....
join file1.txt file2.txt > file3.txt
paste -d ',:' file1 file2 file3
Converting other formats to text
....
lynx -dump http://url > textfile
links-dump http://url > textfile ##(may render tables)
w3m -dump http://url > textfile ##(may tables better)
fromdos autoexec.bat
dos2unix autoexec.bat ##(the same)
todos *.tex
unix2dos *.tex ##(the same)
Converting character encodings
....
ch/GNU.MISC/recode-3.6/recode_3.html
iconv -f utf8 -t utf16 /path/to/file
recode -l | less
recode iso-8859-15..utf8 report.txt ##(the actual file is changed)
recode ..lat1 < file.txt > new.txt ##(the original file is unchanged)
recode ..HTML < file.txt > file.html
recode -v u8..h < file.txt
recode utf-8/CRLF.. file-to-change.txt
Comparing and patching text files
....
colordiff -yW"`tput cols`" /path/to/file1 /path/to/file2
vimdiff foo.c <(bzr cat -r revno:-2 foo.c)
ssh $HOST -l$USER cat /REMOTE/FILE | sdiff /LOCAL/FILE -
diff <(ssh alice cat /etc/apt/sources.list) <(ssh bob cat /etc/apt/sources.list)
comm -1 -2 <(sort file1) <(sort file2)
diff file1 file2 | grep ^>
diff file1 file2 | grep ^<
ssh user@host cat /path/to/remotefile | diff /path/to/localfile -
diff <(head -500 product-feed.xml) <(head -500 product-feed.xml.old)
diff manuscript.old manuscript.new
sdiff olive green | less
diff3 tree bush hedge > arbol
patch manuscript.new manuscript.diff
vimdiff scp://root@server-foo.com//etc/snmp/snmpd.conf scp://root@server-bar.com//etc/snmp/snmpd.conf
vimdiff tera.py <(ssh -A testserver "cat tera.py")
Searching text
....
cat *.txt | less -I ##(then type '/' to search)
less -I *.txt ##(then type '/*' to search, seems better)
grep '^#'