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):

  1. % cd

  2. % pwd

  3. % mkdir work2

  4. % cd work2

  5. % mkdir books

  6. % cd books

  7. % cat > Quijote2.txt

  8. 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"

  9. % more Quijote2.txt

  10. % cat Quijote2.txt Quijote2.txt

  11. % cat Quijote2.txt Quijote2.txt > 2Quijote2.txt

  12. % more 2Quijote2.txt

  13. % mkdir images

  14. Save this picture in the images directory

  15. % ls

  16. % cd ..

  17. % tar -cvf books.tar books

  18. % ls

  19. % mv books old_books

  20. % tar -xvf books.tar

  21. % ls books; ls old_books


  22. ls z

  23. ls z 2> ls.err

  24. more ls.err

  25. ls b* c* > ls.out 2> ls.err

  26. more ls.*


  27. % emacs books/Quijote2.txt + C-z

  28. % ps (search the emacs PID)

  29. % bg

  30. % kill -9 emacs_PID

  31. % ps

  32. % emacs books/Quijote2.txt &

  33. % emacs books/Quijote2.txt &

  34. % ps

  35. % jobs



Enrique Blanco © 2004 -- eblanco@imim.es