Basics
Using globs at the command line is very powerful…
And with great power comes great responsibility.
Text Editor, and create a new file.cd to the directory that you
just saved them in.cat command on each file.There are several commands for looking at the content of files.
cat : print contents of all arguments to screenhead : print first 10 lines of all arguments to
screentail : print last 10 lines of all arguments to
screengrep : look for a pattern in all arguments and print
all matches to screenwc : print the number of lines, words, and characters
in the fileless : show the contents of a file in a “pager”If you enter any of the commands without a filename, they will go into “stdin mode”
$ cat
You have to press Ctr-C
demos/01-fine_contents.sh
find commandfind command is a tool for searching for
files.find takes a directory named as an argument
followed by options
finddemos/02-find.sh
cmd > file : whatever the command cmd
outputs will be saved in a file named file. If file exists,
it will be overwritten.cmd >> file : whatever the command
cmd outputs will be appended to the file named
file. If file does not exists, it is created.tail -n 1 *.txt > last_lines.txt will create a file
named last_lines.txt that contains the last line of all
files in the current directory that end with .txttail -n 1 *.bin >> last_lines.txt will
add the last lines of all files in the current directory that
end with .bin to the file last_lines.txt.tail -n 1 *.log > last_lines.txt will
overwrite the file named last_lines.txt
with the last line of all files in the current directory that end with
.logdemos/03-file_redirection.sh
So far we have just been looking at and creating plain text files. What if we want to edit them?
demos/04-text_editors.sh
$(), and insert the
output of the command into the command line as if you typed it in.files.txt contains a list of file
names, then head $(cat files.txt) would run head on all of
the files in the list.demos/05-command_substitution.sh
So far, we have learned to use several different commands
cdrmmvheadtailcatgrepAll of these commands take arguments, and most of them take options.
It can be difficult to remember all of them
man command.$ man grep
simulations/, which contains a directory name
backups.201601/. Go into this directory
data-01.txt?data-02.txt?data-XX.txt that contains the lines
from all the data files in this directorydata-last_lines.txt that contains
just the last line from all the data files in this
directorysimulations/ directory of the sandbox.
run-XXX.out. These files contain the output of some program
that was used to processed data. Some of the runs “failed”, i.e. there
was an error during the processing. When this happened, the processor
printed the word “ERROR”, which is contained in the file. How many of
the run-XXX.out files contain error messages?errors.txt.warnings_and_errors.txt