pwd
This command name stands for "print working directory".
It displays on the terminal the absolute path name of the current (working) directory.
It is useful to locate where you are currently in the Unix tree.
# print working directory
pwd
ls
This command stands for "list".
It displays the content of a directory.
By default, the content is listed in lexicographic order.
# list the content of the current directory
ls
ls .
# list content of the parent directory
ls ..
# list the contens of your home directory from anywhere
ls ~
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
and mv
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
and rm
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
cd
This command name stands for "change directory".
It changes your current working directory to the specified location.
The last visited directory is referred to with a hyphen ("-").
# go to root directory of the system and print the working directory
cd /
pwd
# go to the home directory and print the working directory
cd ~
pwd
# change directory using the absolute path and print the working directory
cd /net/bmc-pub14/data/
pwd
find
Searches directories to find a directory or file.
find ~ -name arrayDat*
grep
Searches a file for a specific pattern.
Can be used similarly to find, but it also searches file contents.
grep -r "arrayDat*" .