160 likes | 249 Views
Further Command line…. Nic Bertrand. CEH IT Support, GRID & Bioinformatics. Content. Compression, archiving utilities Input/Output/Error redirection Pipes Who is using that file? (lsof, fuser). Compression/Uncompression.
E N D
Further Command line… Nic Bertrand CEH IT Support, GRID & Bioinformatics
Content • Compression, archiving utilities • Input/Output/Error redirection • Pipes • Who is using that file? (lsof, fuser)
Compression/Uncompression • Linux supports the compression of a wide range of archiving formats:.zip, .tar, .gz, .Z, .bz2
Tar Most common use: Uncompress an archive: Tar xvf archive.tar Tar xvzf archive.tar.gz Tar xvjf archive.tar.bz2 Check an archive: Tar tf archive.tar Tar tzf archive.tar.gz
tar -- tape Archiving Utility • Creating an archive: Tar cvf archive.tar *.txt Built-in gzip/bzp2 function: tar cvzf archive.tar.gz *.txt tar cvjf archive.tar.bz2 *.txt
Gotchas with tar… • never use absolute paths when creating an archive... e.g. don’t do: tar cvf home_archive.tar /home • Check the content of a tar file using tar tf
Moving file tree using tar • cd /sourcedirtar cf - . | (cd /destdir && tar xpf -)
gzip • Compressing: gzip file-> file.gz.gz is compressed • Uncompressing:gzip -d file.gz or gunzip file.gz
Other compression formats Software Common extension compress/uncompress .Z zip/unzip .zip bzip2/bunzip2 .bz2 Warnings: Linux does not support windows self-extractable .exe zip archives Bio-Linux does not support ARJ archives “out of the box”
Checking file types: file • Used to determine the file typeexamples:binary, ASCII text, GNU tar format… Examples: feeding an binary ‘text’ file (word document) into clustalw or blastall will not work…
Input/output redirection • write standard output to file Myprog > output.txt • Append standard output to file Myprog >> output.txt • Standard error to standard output Myprog >outputfile 2>&1
More I/O redirection • Normal mode: • myprog > output.txt (send stdout to file) • myprog 2> error.txt (send stderr to file) • myprog > allout.txt 2>&1 (send stdout and stderr to file) • myprog < inputfile (take stdin from file) • myprog 2> /dev/null (chuck stderr into oblivion!) • Append: • myprog >> output.txt (send stdout to end of file) • myprog 2>> error.log (send stderr to end of file) • myprog >> allout 2>&1 (send stdout and stderr to end of file) • myprog <<x (take stdin until "x" occurs) • Pipes: • myprog | myprog2 (pipe stdout of myprog to stdin of myprog2) • myprog 2>&1 | myprog2 (pipe stdout and stderr of myprog to myprog2)
Getting info on what/who is using a file/device/socket • Crucial info if: You want to unmount device, partition and and you get a frustrating ‘umount: device is busy’ LSOF and FUSER are useful tools
lsof: list open files • lsof /mnt/cdromwhat/who is using the cdrom? • lsof –i :505 what is using TCP port 505?
fuser: identify processes using files or sockets • man fuser • list all process accessing port: fuser ssh/tcp • fuser -mk /home/user1 lists all processes using /home/user1 and terminates them!
Exercises 1. list processes that access the /var partition 2. list processes that use the ssh port a. using fuser b. using lsof3. 3. Launch Artemis. Consult the man page for fuser and figure out a way to send a kill signal to all process that use /usr/software What happens? 4. list all manual pages relevant to password 5. email the man passwd page to your email account 6. cd ~manager/examples/further_cli/tar/Compress all the blast reports (.blastp) files into a tar.gz file 7. cd ../compressedexpand compressed.tar file in current directory 8. Compress/gzip all .prot files. What sort of compression ratio do you get? Can you alter/improve this?