Session 2. Basic UNIX commands (II)
1. Looking inside files: % cat [concatenate] % more file [show file: Space,Enter,b] % head file [first lines] % tail file [last lines] % wc file [word counts] % diff file1 file2 [compare files] % od -c file [display character map] % fold -n file [print the file using n chars/line] % cat file1 file2 [concatenate files] % cat file1 [show file] % head -n file [first n lines] % tail -n file [last n lines]
2. Compressing files and directories: % gzip file [compress file] % gzip -d file.gz [uncompress file] % tar -cvf
file.tar
directory[create a tar-file from dir] % tar -xvf
file.tar[create a dir from tar-file] % tar -zcvf
file.tar.gz
directory[create and compress a tar-file] % tar -zxvf
file.tar.gz[uncompress a tar-file and create the dir]
3. I/O redirection: % command > out_file [standard output to file] % command >> out_file [append] % command < in_file [standard input from file] % command 2> err_file [standard error to file (bash)] % command >& err_file [standard error to file (tcsh)] % ls > ls.out [output redirection] % cat > mytext.out [use C-d to finish]
4. Process management (multitasking): % command [foreground, C-z, C-c] % command & [background] % ps [process status] % kill -9 pid [cancel a process] % top [system info] % nice command [set priority]
Practice 2. Basic UNIX commands (II)
Type the following commands (tutorial):
- % cd
- % pwd
- % mkdir work2
- % cd work2
- % mkdir books
- % cd books
- % cat > Quijote2.txt
- Type the following text [before C-d]:
"La razón de la sinrazón que a mi razón se hace, de tal manera mi razón enflaquece, que con razón me quejo de la vuestra fermosura"
- % more Quijote2.txt
- % cat Quijote2.txt Quijote2.txt
- % cat Quijote2.txt Quijote2.txt > 2Quijote2.txt
- % more 2Quijote2.txt
- % mkdir images
- Save this picture in the images directory
- % ls
- % cd ..
- % tar -cvf books.tar books
- % ls
- % mv books old_books
- % tar -xvf books.tar
- % ls books; ls old_books
- ls z
- ls z 2> ls.err
- more ls.err
- ls b* c* > ls.out 2> ls.err
- more ls.*
- % emacs books/Quijote2.txt + C-z
- % ps (search the emacs PID)
- % bg
- % kill -9 emacs_PID
- % ps
- % emacs books/Quijote2.txt &
- % emacs books/Quijote2.txt &
- % ps
- % jobs
Enrique Blanco © 2004 -- eblanco@imim.es