rm
Safely
rm: remove regular file 'thesis/quotations.txt'?
The -i
option will prompt before every removal. The Unix shell doesn't have a trash bin, so all the files removed will disappear forever. By using the -i
flag, we have the chance to check that we are deleting only the files that we want to remove.
mv ../analyzed/sucrose.dat ../analyzed/maltose.dat .
Recall that ..
refers to the parent directory (i.e. one above the current directory) and that .
refers to the current directory.
We start in the /Users/jamie/data
directory, and create a new folder called recombine. The second line moves (mv
) the file proteins.dat
to the new folder (recombine
). The third line makes a copy of the file we just moved. The tricky part here is where the file was copied to. Recall that ..
means "go up a level", so the copied file is now in /Users/jamie
. Notice that ..
is interpreted with respect to the current working directory, not with respect to the location of the file being copied. So, the only thing that will show using ls
(in /Users/jamie/data
) is the recombine folder.
proteins-saved.dat
is located at /Users/jamie
proteins.dat
is located at /Users/jamie/data/recombine
proteins-saved.dat
is located at /Users/jamie
If given more than one file name followed by a directory name (i.e. the destination directory must be the last argument), cp
copies the files to the named directory.
If given three file names, cp
throws an error because it is expecting a directory name as the last argument.
cp: target 'morse.txt' is not a directory
.
The solution is 3.
*
) followed by the letter t
, then zero or more characters (*
) followed by ane.pdb
. This gives ethane.pdb
methane.pdb
octane.pdb
pentane.pdb
.*
) followed by the letter t
, then a single character (?
), then ne
. followed by zero or more characters (*
). This will give us octane.pdb
and pentane.pdb
but doesn't match anything which ends in thane.pdb
.??
) between t
and ne
. This is the solution.ethane.
.cp *calibration.txt /backup/calibration
cp 2015-11-* ~/send_to_bob/all_november_files/
cp *-23-dataset* ~send_to_bob/all_datasets_created_on_a_23rd/
.
mv *.dat analyzed
Jamie needs to move her files fructose.dat
and sucrose.dat
to the analyzed directory. The shell will expand *.dat
to match all .dat
files in the current directory. The mv
command then moves the list of .dat
files to the "analyzed" directory.
The first set of commands achieves this objective. First we have a recursive copy of a data folder. Then two rm
commands which remove all files in the specified directories. The shell expands the '*
' wild card to match all files and subdirectories.
The second set of commands have the wrong order: attempting to delete files which haven't yet been copied, followed by the recursive copy command which would copy them.
The third set of commands would achieve the objective, but in a time-consuming way: the first command copies the directory recursively, but the second command deletes interactively, prompting for confirmation for each file and directory.