Unix commands are built in instructions that can be invoked from a Unix terminal. Unix commands are built into Unix and Unix-Like operating systems, and are used to perform very specific tasks which operate on the operating system. There are many commands used to navigate/use unix file systems with command line interpreters. Lists of most of the commands available can be found in sections 3.2/5.1/5.2/5.3/5.4 of An Introduction to the Linux Command Shell For Beginners. These lists are quite extensive. The following table contains the most commonly used commands.
Command | Description |
---|---|
pwd | Print working directory - Prints the file path to the current working directory. |
ls / ls <path> | List - When used alone displays the contents of the current working directory. When used with <path> displays the contents of the directory found at <path>. |
cd / cd <path> | Change directory - When used alone switches to the home directory. When used with <path> changes from the current working directory to <path>. |
touch <path>/<file> | Create File - Creates the <file> under <path>. This command will not create directories. This command only works on Unix/Linux/Mac. |
rm <path>/<file> | Remove File - Removes the <file> under <path>. This command will not remove directories. |
rm -rf <path> | Remove File - USE WITH CAUTION Removes the directory at <path>. This command will permanently delete the directory and all contents within it. |
cat <path> | Concatenate - Displays the contents of the file at <path>. |
head <path> | Display beginning of file - Displays first 10 lines of the file located at <path>. |
tail <path> | Display end of file - Displays last 10 lines of the file located at <path>. |
mkdir <path> | Make directory - Makes a new directory at <path>. |
cp <path> <destPath> | Copy - Copies the file at <path> to <destPath>. |
mv <path> <destPath> | Move - Moves the file from <path> to <destPath>. |
Note: <file>/<path>/<destPath> must be valid files/paths from the current working directory.
For the following examples use the following desktop as a reference for the questions:
Each of the following examples is a continuation from the previous example.
alex@imac desktop % pwd /Users/alex/desktop alex@imac desktop %
alex@imac desktop % ls blog led portfolio.pem programs alex@imac desktop %
/programs
directory.alex@imac desktop % ls programs main.cpp alex@imac desktop %
home
directory.alex@imac desktop % cd alex@imac ~ %
alex@imac ~ % pwd /Users/alex alex@imac ~ %
programs
directory contained in the desktop
directory.alex@imac ~ % cd desktop/programs alex@imac programs %
new
alex@imac programs % ls main.cpp alex@imac programs % touch new alex@imac programs % ls main.cpp new alex@imac programs %
This will cause a new file to display in the GUI:
newDir
with the file new
in it.alex@imac programs % touch newDir/new touch: newDir/new: No such file or directory alex@imac programs % mkdir newDir alex@imac programs % ls main.cpp new newDir alex@imac programs % touch newDir/new alex@imac programs % ls newDir new alex@imac programs %
new
file from the current directory (/programs
):alex@imac programs % ls main.cpp new newDir alex@imac programs % rm new alex@imac programs % ls main.cpp newDir alex@imac programs %
newDir
and all of it's contents:alex@imac programs % ls main.cpp newDir alex@imac programs % rm newDir rm: newDir: is a directory
NOTE: DO NOT PERFORM THIS STEP ON ANY DIRECTORY UNLESS YOU WANT TO LOSE ALL OF THE DATA IN THE DIRECTORY PERMANENTLY. THIS DELETE IS UNRECOVERABLE
alex@imac programs % rm -rf newDir alex@imac programs % ls main.cpp alex@imac programs %
main.cpp
alex@imac programs % cat main.cpp #include <iostream> using namespace std; int main() { cout << "Hello " << "Alex's " << "Blog" << endl; return 0; } alex@imac programs %
main.cpp
.alex@imac programs % head main.cpp #include <iostream> using namespace std; int main() { cout << "Hello " << "Alex's " << "Blog" << endl; alex@imac programs %
main.cpp
.alex@imac programs % tail main.cpp int main() { cout << "Hello " << "Alex's " << "Blog" << endl; return 0; } alex@imac programs %
programs
directory to it's parent directory.alex@imac programs % cd .. alex@imac desktop % ls blog led portfolio.pem programs alex@imac desktop %
/programs/main.cpp
to the current directory and name the new file new.cpp
.alex@imac desktop % cp programs/main.cpp new.cpp alex@imac desktop % ls blog led portfolio.pem programs new.cpp alex@imac desktop %
/programs/main.cpp
to the current directory and keep the original name.alex@imac desktop % mv programs/main.cpp main.cpp alex@imac desktop % ls programs alex@imac desktop % ls blog led portfolio.pem programs new.cpp main.cpp alex@imac desktop %
See Above Table For Common Linux Commands
Write the command to display the full path of your current working directory.
You are not sure which directory you're in. Write a command to find out.
Write a command to list the files in the current directory.
Write a command to list the files in a directory named documents
.
Write a command to list the files in /usr/local/bin
.
Write the command to go to your home directory.
Write the command to change into a directory called downloads
.
Write the command to navigate from the current directory into ../projects/python
.
Write a command to create a file named notes.txt
in the current directory.
Write a command to create a file named data.csv
inside a folder called output
.
Write a command to delete a file named temp.txt
.
Write a command to delete a file called old_logs.txt
from the logs
directory.
Write a command to create a folder named backups
.
Write a command to create a nested directory structure archive/2025/july
.
Write a command to delete a folder named test
that is currently empty.
Write a command to remove the empty folder old_drafts
.
Write a command to copy draft.txt
into the final
directory.
Write a command to copy a.txt
and rename it as b.txt
.
Write a command to rename draft.txt
to final.txt
.
Write a command to move report.pdf
into the archive
folder.
Create a file called newfile.txt
and then list the contents of the current directory.
Create a folder called docs
and move resume.pdf
into it.
Create a file named test.py
and then rename it to main.py
.
Navigate to a folder called projects
and then list its contents.
Delete the file old.txt
and then print your current directory path.
Make a directory called code
, change into it, and create a file named app.js
.
Copy image.png
into the images
folder, then list the contents of that folder, and then move image.png
into archive/images
.
Create a file log.txt
, move it into a folder called logs
, and then print the working directory.
Create a folder drafts
, make a file inside it called essay.txt
, and then remove that file.
Create project
, add a file readme.md
, rename it to README.md
.
Make a directory portfolio
, create index.html
inside it, list the directory contents, and rename index.html
to home.html
.
Create temp
, create a file temp.txt
inside, move it to another folder archive
, and then delete the original folder temp
.
Change into scripts
, create run.sh
, copy it to backup
, and print your current directory.
Make folder A
, move into it, create a file a.txt
, and delete it.
Make folder test
, create file t.txt
, rename to test.txt
, move it to done
.
Create a folder named logs
, create a file called error.log
in it, list the contents, rename error.log
to err.log
, move it to archive/logs
, and display your current path.
Change into codebase
, create a file main.cpp
, copy it to src
, rename it to main_v2.cpp
, move it to build
, and print current directory.
Make a directory backup
, move into it, create db.sql
, copy it into archives
, delete original, remove backup
, return to original directory.
Create classwork
, create three files: lab1.txt
, lab2.txt
, lab3.txt
, list the directory, delete lab3.txt
, move the rest to submitted
.
Create a folder projects/2025
, go into it, create idea.txt
, rename it proposal.txt
, copy to submissions
, delete original.
Write the command(s) to make three folders a
, b
, and c
, then place an empty file file.txt
in each.
Create a new file in your current directory and then move it to a subdirectory two levels down.
Copy all files from old_projects
to new_projects
, then list the contents of new_projects
.
Navigate to the home directory, make a folder called scripts
, enter it, and create a shell script file named start.sh
.
Make a directory x/y/z
in one command, then add a file to the deepest folder.