$ cp -p seasonal/summer.csv seasonal/spring.csv backup/
$ mv seasonal/spring.csv seasonal/summer.csv backup/$ mv xxx.csv yyy.csv$ mv can rename directory too, same as rename a file$ mkdir yearly$ mkdir -p yearly/2017$ mv ~/people/agarwal.txt /tmp/scratch~: home/XXX: relative directory$ cat course.txt$ less $ more$head -n 5 seasonal/winter.csv (select first 5 rows)$ ls -R -F /home/repl(R means "recursive",-Fthat prints a/after the name of every directory and a*after the name of every runnable program.)
$ tail -n +7 seasonal/spring.csv (display all but the first six rows ofseasonal/spring.csv)
$man less (less manual)$ cut -f 2-5,8 -d , values.csv
means"select columns 2 through 5 and columns 8,
using comma as the separator".
cut uses -f (meaning "fields") to specify columns
and -d (meaning "delimiter") to specify the separator.$ !head (rerun head command in history)$ history$ !3 runs the 3rd command in historygrepselects lines according to what they contain,
$grep bicuspid seasonal/winter.csvprints lines fromwinter.csvthat contain "bicuspid"
-c: print a count of matching lines rather than the lines themselves-h: do not print the names of files when searching multiple files-i: ignore case (e.g., treat "Regression" and "regression" as matches)-l: print the names of files that contain matches, not the matches-n: print line numbers for matching lines-v: invert the match, i.e., only show lines that don't match
grep -c incisor seasonal/autumn.csv seasonal/winter.csv
paste xxx.csv yyy.csv 最后几行开头多了一列 “,”
head -n 5 seasonal/summer.csv > top.csv pipe:head -n 5 seasonal/summer.csv | tail -n 3The pipe symbol tells the shell to use the output of the command on the left
as the input to the command on the right.wc(short for "word count") prints the number of characters, words, and lines in a file. You can make it print only one of these using-c,-w, or-lrespectively
$ grep 2017-07 seasonal/spring.csv|wc -l 把带2017-07的行都打出来wildcards:*cut -d , -f 1 seasonal/*?matches a single character, so201?.txtwill match2017.txtor2018.txt, but not2017-01.txt.[...]matches any one of the characters inside the square brackets, so201[78].txtmatches2017.txtor2018.txt, but not2016.txt.{...}matches any of the comma-separated patterns inside the curly brackets, so{*.txt, *.csv}matches any file whose name ends with.txtor.csv, but not files whose names end with.pdf.
$ cut -d , -f 2 seasonal/winter.csv | grep -v Tooth | sort -r
flags -n and -r can be used to sort numerically and reverse the order of its output,
while -b tells it to ignore leading blanks
and -f tells it to fold case (i.e., be case-insensitive).
$ grep -v tooth|sort | uniq -c > ttt.csv
stop running: ctrl+C
$ set | grep XXX
$ echo $USER: print the value of USER
$ echo USER: print USER on the screen
$ testing=seasonal/winter.csv : create a variable$ head -n 1 $testing: remember $ to print$ for filetype in gif jpg png; do echo $filetype; done$ for filename in seasonal/*.csv; do echo $filename; done$ datasets=seasonal/*.csv : record datasets$ for filename in $datasets; do echo $filename; done $ for file in seasonal/*.csv; do grep 2017-07 $file | tail -n 1; donemove 带空格的东西:$ mv 'July 2017.csv' '2017 July data.csv'
will open$ nano filename:filenamefor editing (or create it if it doesn't already exist).
Ctrl+K: delete a line.Ctrl+U: un-delete a line.Ctrl+O: save the file ('O' stands for 'output'). You will also need to press Enter to confirm the filename!Ctrl+X: exit the editor.
$ bash teeth.sh > teeth.out
$ cat teeth.out
$ cat teeth.out
$@ (dollar sign immediately followed by at-sign)
to mean "all of the command-line parameters given to the script")$ nano count-records.shincount-records.sh:
tail -q -n +2$@| wc -l
$ bash count-records.sh seasonal/*.csv > num-records.out process a single argument?
column.sh:cut -d , -f $2 $1
$ bash column.sh seasonal/autumn.csv 1 CTRL+Kto cut the line, thenCTRL+Utwice to paste two copies of it.
# Print the first and last data records of each file. for filename in $@ do head -n 2 $filename | tail -n 1 tail -n 1 $filename done
没有评论:
发表评论