This is a collection of a few Linux/Mac commands that you can use from the terminal.
When you are working on the command line you are always in a working directory. Print your current working directory with the command pwd
.
I will use $
to designate the command line prompt.
The cd
command will change your current working directory. Change into your cs110
folder like so:
$ cd cs110
To go back a directory, use
$ cd ..
You can change directories along a longer path by separating directory names with a forward slash:
$ cd cs110/exercise01
The ls
command lists files and directories. When run without any arguments it will list the contents of the current working directory. Here is example output of ls
in a directory with some files:
$ ls
a.out hello_world hello_world.c
To list all files including hidden files:
$ ls -a
. .. .git a.out hello_world hello_world.c
The .
is an alias for the current directory, and ..
is an alias for the parent directory of the current directory.
If you would like to preview the content a a file you an display it in the terminal window using less
.
$ less hello_world.c
The up and down arrows will scroll the file and pressing q
will exit less
.
You can create a file using the touch
command.
$ touch code.c
You can create a folder using the mkdir
command. Note that you should avoid using the spaces in folder and file names and it is wise to keep the names of your files and folders all lowercase. The Linux operating system is case sensitive. So the file foobar.txt
is not the same as Foobar.txt
.
$ mkdir project_folder
If you need to move a file or folder to another location, you can use the mv
command.
mv myfile.txt souce_folder/
The mv
command is interesting as it is also how you can rename a file or folder.
my myfile.txt new_filename.txt
If you have created a file by accident or need to discard a file you no longer need, you can delete a file, using rm
.
$ rm a.out
WARNING!! rm
does NOT move files to a trash or recycle bin, it deletes them permanently. Make sure you know what you are removing when you use rm
!