Shell Lessons for Archivists: Reference

Key Points

What is the shell?
  • The shell is powerful

  • Knowing where you are in your directory structure is key to working with the shell

  • The shell can be used to copy, move, and combine multiple files

Counting and mining with the shell
  • The shell can be used to count elements of documents

  • The shell can be used to search for patterns within files

  • Command can be used to count and mine any number of files

  • Commands and flags can be combined to build complex queries specific to your work

Working with free text
  • Shell tools can be combined to powerful effect

Shell Cheat Sheet


Shell: Basics

pwd - print working directory

ls - list contents of a directory

cd change directory

cd pathname - takes you to the directory specified by pathname

cd ~ - takes you to your home directory


Shell: Interacting with Files

mkdir make a directory

cat print to shell or send file or files to output

head output first 10 lines of a file or files

tail output last 10 lines of a file or files

mv rename or move a file or files. Syntax for renaming a file: mv FILENAME NEWFILENAME

cp make a backup copy of a file or files. Syntax: cp FILENAME NEWFILENAME

> redirect output. Syntax with cat: cat FILENAME1 FILENAME2 > NEWFILENAME

>> redirect output by appending to the filename specified. Syntax with cat: cat FILENAME1 FILENAME2 >> NEWFILENAME

rm remove a file or files. NB: USE WITH EXTREME CAUTION!!!

rmdir -r will delete a directory, even if it is not empty.

rmdir -r-i will delete a directory, even if it is not empty, but will ask you to confirm each deletion.


Shell: Wildcards

? a placeholder for one character or number

* a placeholder for zero or more characters or numbers

[] defines a class of characters

Examples


Shell: Counting and Mining

wc word count

sort sort input

grep global regular expression print