This is a list of useful Unix commands.
A directory is a folder.
Current working directory
The current working directory is printed just before the command prompt (usually
Alternatively, use the command
~/test $ pwd ~/test
cd command changes the working directory.
When used with an argument, it changes to that directory:
~ $ cd test ~/test $ cd .. # .. is shorthand for "the parent directory" ~ $
When used without an argument, it changes to the home directory (
~/test $ cd ~ $
ls lists the files in the current working directory.
ls -a lists all files in the current working directory (including hidden files).
To create a directory in the current directory, use the command
~ $ ls # nothing in the directory right now ~ $ mkdir test ~ $ ls test ~ $ mkdir test2 ~ $ ls test test2
To delete a directory (along with all its contents), use the command
~ $ ls test test2 ~ $ rm -r test ~ $ ls test2
To create an empty file, use the
~ $ ls test ~ $ touch my_file ~ $ ls my_file test
To create a file with predetermined text, use
echo text > file:
~ $ echo testing > my_file ~ $ cat my_file testing
This is called output redirection because the output of the command
echo testing is sent to a file instead of being displayed on the screen.
To view the contents of a file, use the
cat command. See example above.
To delete a file, use the
~ $ ls my_file test ~ $ rm my_file ~ $ ls test
To copy a file, use the
~ $ ls my_file test ~ $ cat my_file testing ~ $ cp my_file new_file ~ $ ls my_file new_file test ~ $ cat new_file testing
An example of copying a file from another directory:
~ $ ls my_file test ~ $ cp ~cs61a/lib/shakespeare.txt . # '.' is shorthand for "the current directory" ~ $ ls my_file shakespeare.txt test
To rename a file, use the
mv command, where the first argument is the file you want to rename and the second argument is the new file name:
~ $ ls my_file test ~ $ mv my_file new_name ~ $ ls new_name test
To move a file to another directory, use the
mv command, where the first argument is the file you want to move and the second argument is the destination directory:
~ $ ls my_file test ~ $ mv my_file test ~ $ ls test ~ $ cd test ~ $ ls my_file
man command tells you how to use a Unix command. For example,
man cp will bring up a page inside of the terminal. The
NAME field will give a brief description of what the command does, and the
DESCRIPTION will have a host of extra options you can run the command with.
You can navigate forward through the
man page with the
Return key and you can quit with
|Editing Python Files|
|Connecting from home|
A list of available instructional servers can be found here: http://inst.eecs.berkeley.edu/cgi-bin/clients.cgi?choice=servers. Commonly used servers include
Remote login (
To remotely connect to your instructional account, use the
ssh (secure shell) command. Use this command with your
cs61a login and the server of your choice:
To connect to the
cs61a-aa account and start a terminal session:
You can also execute single commands via
ssh, instead of opening an entire session:
ssh email@example.com glookup
Transferring files (
To copy files remotely to or from an instruction account, use the
scp (secure copy) command.
To copy a file from an instructional machine to a local directory:
scp firstname.lastname@example.org:target_file local_directory
To copy a file from a local directory to an instructional machine:
scp local_directory/local_file email@example.com:target_directory
To copy an entire directory from a local directory to an instructional machine:
scp -r local_directory firstname.lastname@example.org:target_directory