tar -cjf file7.tar.bz2 file4 file5 file6
tar -cf file7.tar file4 file5 file6
bzip2 file7.tar
tar -cjf file7.tar.bz2 file4 file5 file6
tar -cf file7.tar file4 file5 file6
bzip2 file7.tar
To tar all .cc and .h files into a tar file named foo.tgz use:
tar cvzf foo.tgz *.cc *.h
This creates (c) a compressed (z) tar file named foo.tgz (f) and shows the files being stored into the tar file (v). The .tgz suffix is a convention for gzipped tar files, it’s useful to use the convention since you’ll know to use z to restore/extract.
It’s often more useful to tar a directory (which tars all files and subdirectories recursively unless you specify otherwise). The nice part about tarring a directory is that it is untarred as a directory rather than as individual files.
tar cvzf foo.tgz cps100
will tar the directory cps100 (and its files/subdirectories) into a tar file named foo.tgz.
To see a tar file’s table of contents use:
tar tzf foo.tgz
To extract the contents of a tar file use:
tar xvzf foo.tgz
This untars/extracts (x) into the directory from which the command is invoked, and prints the files being extracted (v).
If you want to untar into a specified directory, change into that directory and then use tar. For example, to untar into a directory named newdir:
mkdir newdir
cd newdir
tar xvzf ../foo.tgz
You can extract only one (or several) files if you know the name of the file. For example, to extract the file named anagram.cc from the tarfile foo.tgz:
tar xvzf foo.tgz anagram.cc
(Unix command line)
SYNOPSIS:
scp [-p] [-v] [-r] [[username@]host:]file … [[username@]host:]file_or_dir
Copies files over the network securely; uses ssh for data transfer, using the same authentication and providing the same security as ssh.
EXAMPLES of USAGE
(The “.colorado.edu” isn’t necessary if
both computers are on the same domain.
Typing a username isn’t necessary if you have
the same username on both computers.)
1. “Putting” a single file
ucsu> scp mydata.dat newton.colorado.edu:NewData.txt
copy file “mydata.dat” from your current computer/directory to your home directory on newton.colorado.edu,
naming the copy on newton “NewData.txt”.
ucsu> scp mydata.dat newton.colorado.edu:
same thing, but the copied file on newton is named the same as the original (mydata.dat) by default
ucsu> scp mydata.dat amath:/www/courses/8100/2005Spr/lab2.dat
copy file to a specific directory on amath, giving the file a new name there
goldhill.ucar.edu> scp mydata.dat smithjz@amath.colorado.edu:ncar.dat
copy file from your account on goldhill to your home directory on amath,
where your username is different (smithjz)
2. “Getting” a single file
ucsu> scp newton:mydata.dat ./mydata.dat
copies file “mydata.dat” from the your home directory on newton to
your current working directory on ucsu
ucsu> scp newton:mydata.dat ./
same thing — it is enough just to indicate the directory (“./” = my current directory), and
the copied file will be named the same as the original, by default
ucsu> scp smithjz@newton.colorado.edu:research/MYC/mydata.dat ./
gets the file from my “research/MYC” subdirectory (relative to smithjz’s home directory on newton)
3. “Putting” an entire directory
ucsu> scp -r research newton:MyRsrch/09/
copy directory “research” recursively (i.e., the directory and all its contents) from ucsu
into a new directory “MyRsrch/09/” in your home directory on newton
(the directory “MyRsrch” must already exist).
Sometimes a better alternative is to create a tar file, then copy over
only that single tar file and unpack it on the remote host.
4. “Getting” an entire directory
ucsu> scp -r smithj@euclid.ucla.edu:MyRsrch/09 ./r9/
copy directory “MyRsrch/09/” recursively (i.e., the directory and all its contents) from
euclid.ucla.edu (where you are “smithj” into a new directory “r9/” in your current working directory on ucsu.
Sometimes a better alternative is to ssh to the remote computer, bundle the
files you want into a single tar file, scp that file over, and unpack it where you want the files.
OPTIONS:
-r This option specifies that scp should copy directories recursively — copies all the files & subdirectories,
plus the contents of the subdirectories themselves, etc. The operation does not follow symbolic links.
-p Tells scp to preserve file attributes and timestamps.
-v Makes scp verbose.
Some examples of using UNIX find command.
Contents:
Introduction
Search for file with a specific name in a set of files (-name)
How to apply a unix command to a set of file (-exec).
How to apply a complex selection of files (-o and -a).
How to search for a string in a selection of files (-exec grep …).
Introduction
The find command allows the Unix user to process a set of files and/or directories in a file subtree.
You can specify the following:
• where to search (pathname)
• what type of file to search for (-type: directories, data files, links)
• how to process the files (-exec: run a process against a selected file)
• the name of the file(s) (-name)
• perform logical operations on selections (-o and -a)
Search for file with a specific name in a set of files (-name)
find . -name “rc.conf” -print
This command will search in the current directory and all sub directories for a file named rc.conf.
Note: The -print option will print out the path of any file that is found with that name. In general -print wil print out the path of any file that meets the find criteria.
How to apply a unix command to a set of file (-exec).
find . -name “rc.conf” -exec chmod o+r ‘{}’ \;
This command will search in the current directory and all sub directories. All files named rc.conf will be processed by the chmod -o+r command. The argument ‘{}’ inserts each found file into the chmod command line. The \; argument indicates the exec command line has ended.
The end results of this command is all rc.conf files have the other permissions set to read access (if the operator is the owner of the file).
How to apply a complex selection of files (-o and -a).
find /usr/src -not \( -name “*,v” -o -name “.*,v” \) ‘{}’ \; -print
This command will search in the /usr/src directory and all sub directories. All files that are of the form ‘*,v’ and ‘.*,v’ are excluded. Important arguments to note are:
• -not means the negation of the expression that follows
• \( means the start of a complex expression.
• \) means the end of a complex expression.
• -o means a logical or of a complex expression.
In this case the complex expression is all files like ‘*,v’ or ‘.*,v’
The above example is shows how to select all file that are not part of the RCS system. This is important when you want go through a source tree and modify all the source files… but … you don’t want to affect the RCS version control files.
How to search for a string in a selection of files (-exec grep …).
find . -exec grep “www.athabasca” ‘{}’ \; -print
This command will search in the current directory and all sub directories. All files that contain the string will have their path printed to standard output.
If you want to just find each file then pass it on for processing use the -q grep option. This finds the first occurrance of the search string. It then signals success to find and find continues searching for more files.
find . -exec grep -q “www.athabasca” ‘{}’ \; -print
This command is very important for process a series of files that contain a specific string. You can then process each file appropriately. An example is find all html files with the string “www.athabascau.ca”. You can then process the files with a sed script to change those occurrances of “www.athabascau.ca” with “intra.athabascau.ca”.