Session 1. Basic UNIX commands


Syntax:

command option(s) filename(s)

1. Simple commands:


% date [today's date]
% cal [calendar]
% whoami [user's identity]
% who [logged users]
% hostname [computer's identity]
% man command [help about command]




2. Browsing the file system:


% pwd [print work directory]
% ls [list]
% cd dir [change directory]
  
% cd [back to home directory]
% ls -alh [list all/long/human-readable]
% ls *.doc [matches any string]
% ls chapter? [matches any single character]
% ls chapter[1-3] [range]




3. File system management:


% cp old new [copy]
% mv old new [rename, move]
% rm file [remove]
% mkdir dir [dir creation]
% rmdir dir [dir remove]
  
% cp -r dir1 dir2 [directory copy]
% rm -i file [interactive]
% rm -rf dir [remove all: attention!!]




4. Protection and permissions:


% chmod bits element [change permissions]
  
% chmod 644 file [set RW-R--R--]
% chmod g+w file [set W for group]
% chmod 744 dir [access directory permissions]




5. File edition:


% emacs file [emacs reference card]


Practice 1. Basic UNIX commands


Type the following commands (tutorial):

  1. % cd

  2. % pwd

  3. % mkdir work1

  4. % cd work1

  5. % mkdir docs

  6. % mkdir images

  7. Save this picture in the images directory

  8. % cd docs

  9. % emacs Quijote.txt

  10. Write the following text:
    "En un lugar de la Mancha, de cuyo nombre no quiero acordarme, no ha mucho que vivía un hidalgo de los de lanza en astillero, adarga antigua, rocín flaco y galgo corredor"

  11. Search the word "hidalgo"

  12. Replace the word "hidalgo" for "caballero andante"

  13. Save the file [C x+s]

  14. Insert a new line at the beginning of the file

  15. Save the file and exit [C x+c]

  16. % pwd

  17. % ls

  18. % ls ..

  19. % ls ../..

  20. % ls -lh Quijote.txt

  21. % chmod 600 Quijote.txt; ls -lh Quijote.txt

  22. % chmod g+r Quijote.txt; ls -lh Quijote.txt

  23. % cd ..

  24. % ls docs/Q*

  25. % ls images/*.jpg

  26. % mv images pictures

  27. % ls

  28. % cd ..

  29. % cp -r work1 work1_backup

  30. % rmdir work1_backup

  31. % ls

  32. % man rmdir

  33. % rm -rf work1_backup

  34. % ls

  35. % history



Enrique Blanco © 2004 -- eblanco@imim.es