Editing the Unix Tree
Make sure to run all of the copy commands below, as we'll be using files from the Ostrom server later in the course.
mkdir
This command name stands for "make a directory".
It creates a new folder (or directory). If no path is specified, the new directory is created in the current directory.
# start in your home directory
cd ~
# create a directory named "unixclass"
# with a subdirectory named "testdir"
mkdir unixclass
mkdir unixclass/testdir
# change current directory directly to "testdir"
cd unixclass/testdir
# go to the parent directory (i.e. unixclass)
# and print the working directory
cd ..
pwd
touch
This command creates an empty file with the given name.
# Go to /home/<your username>/unixclass
cd ~/unixclass
# Create an empty file named "hello.txt"
touch hello.txt
# List the files in the directory to verify that worked
ls
cp
andmv
These commands stand for "copy" and "move," respectively.
They copy / move files and directories to the specified location.
Wildcards symbols such as "*" or "?" are commonly used to copy multiple files with a single command.
The symbol "*" stands for any number of alphanumeric characters.
The symbol "?" stands for a single alphanumeric character.
# Start in ~/unixclass
cd ~/unixclass
# copy the file named arrayDat.txt into your unix_class directory
cp /net/ostrom/data/dropbox/arrayDat.txt .
ls
# copy all the files with suffix "array”
# into the current directory
cp /net/ostrom/data/dropbox/array* .
ls
# copy any file whose extension is "txt"
cp /net/ostrom/data/dropbox/*.txt .
ls
# copy all files
cp /net/ostrom/data/dropbox/* .
ls
rmdir
andrm
rmdir
only removes empty directories,rm
removes both directories and files.rm
needs-r
flag to remove directories.
# Start in ~/unixclass
cd ~/unixclass
# Create a temporary directory
mkdir trash
# create copies of arrayDat.txt in the temporary directory
cp arrayDat.txt trash/arrayDat1.txt
cp arrayDat.txt trash/arrayDat2.txt
cp arrayDat.txt trash/arrayDat3.txt
cp arrayDat.txt trash/arrayDat4.txt
ls trash
# Try to delete the directory with `rmdir`
rmdir trash
# Try to delete the directory with `rm -r`
rm -r trash
Last updated
Was this helpful?