Codecademy Logo

Command Line for the Raspberry Pi

pwd Print Working Directory

The shell command pwd displays the file path from the root directory to the current working directory.

$ pwd
/Users/sonny/Downloads

mkdir Make Directory

The shell command mkdir is used to make a new directory in the filesystem according to its argument. If a file path is given, the new directory will be placed at the end. Otherwise, it will create a new directory in the current working directory.

$ mkdir new-directory
$ ls
old-directory new-directory

ls List

The shell command ls is used to list the contents of a directory. If no arguments are given, it will list the contents of the current working directory.

$ ls Desktop
resume.pdf
photo.png

cd Change Directory

The shell command cd is used to move throughout the filesystem of a computer. It accepts a variety of arguments:

  • Full file paths.
  • Names of children of the current directory.
  • .. the parent of the current directory.
$ cd some-directory
$ cd ..

Filesystem Structure

A computer’s filesystem organizes the data stored by a computer, so that it can be easily retrieved by the user.

Files are generally represented in a tree-like structure, in which any parent directory can have any number of children. The root directory is then found at the base of the tree.

The Command Line

The command line allows a user to navigate the filesystem and run built-in programs or custom scripts. In Unix, the command line interface is called Bash, and the shell prompt is the $.

$

cp Copy

The shell command cp is used to copy files or directories.

The basic argument structure is cp source destination, where the source is the file/directory to copy to the destination file/directory.

$ cp file1 file1_copy
$ cp file1 file2 destination_folder

Command Options

Options can be used to modify the behavior of shell commands. Shell command options are commonly represented by a single letter preceded by a -. For example, -l, -a, and -d could all be options that follow a shell command.

mv Move

The shell command mv is used to move a file into a directory. Use mv with the source file as the first argument and the destination directory as the second argument.

$ mv index.html website/

rm Remove

The shell command rm is used to delete files and directories. The -r flag deletes a directory and all of its files and directories (rm -r).

$ rm -r bad_selfies

ls List Command Options

The shell command ls is used to list the contents in a directory. It can be combined with the following command options:

  • -a: lists all contents, including hidden files and directories.
  • -l: lists all contents, in long format.
  • -t: lists all contents, by the time they were last modified.
$ ls -a
$ ls -l
$ ls -t

Learn more on Codecademy