Basic Commands and Filesystem Overview

An overview of the Linux Filesystem and seven frequently-used Linux commands and examples of how to use them. For additional information about any of these commands, log onto an EECS machine and type

man command

Replace “command” with the actual command for which you want the manual page, for example man ls.

The filesystem structure of Linux is much different from Windows. It is good to know a few of these differences before you start.

General Overview

In Windows, drives are mounted completely separately with drive letters. In Linux, drives are mounted in the filesystem. / is the root direcory of your boot drive filesystem. All mounted drives and filesystems in Linux exist somewhere under /. All of the default directories in / (known as standard subdirectories) have a meaning and intended use to keep the filesystem organized. Some examples are as follows:

Directory Purpose
/ The root of the filesystem.
/bin Stores essential programs such as shells, ls, etc.
/etc Stores configurations for Linux, daemons, etc
/var Stores variable data like log files, etc.
/home Stores user home areas, like C:\\Users in Windows.
/dev Stores device files.

File Paths

In a Linux shell, there are two types of paths. There are absolute paths (beginning in /) that define a full path from the root directory and relative paths (paths that don't begin with /) that are relative to your current directory. Example:

/home/netid > cp some_file Documents
# this copies some_file from your current directory into the Documents directory in your current directory

/home/netid > mv classes/cosc102/my_file.log /tmp
# this moves the file my_file.log (absolute path /home/netid/classes/cosc102/my_file.log) to the absolute path /tmp)

ls

The ls command lists directory contents.

Command Effects
ls Lists the contents of the current working directory.
ls dir-name Lists the contents of the dir-name directory.
ls -a Lists the contents of the current working directory, including files that begin with a dot. (Dotfiles are not listed unless the -a option is used.)
ls -l Lists the contents of the current working directory in long format (including file owner, permissions, etc.).

cd

The cd command changes the current (working) directory.

Command Effects
cd Changes to your home directory.
cd foo Changes to the foo directory.
cd .. Changes to the parent directory (i.e., move up one directory).

cp

The cp command copies files and directories.

Command Effects
cp src-file dest-file Creates/overwrites src-file into dest-file.
cp src-file dest-dir Copies/overwrites src-file into dest-dir/src-file.
cp -R src-dir dest-dir Copies all files and subdirectories within the src-dir directory into the dest-dir directory. (The -R stands for “recursive”.)
cp -i src dest Copies the file/directory src to the file/directory dest, but prompts if any files or directories would be overwritten. (The -i stands for “interactive”.)

mv

The mv command moves or renames files and directories.

Command Effect
mv old-file new-file Renames the file old-file to new-file.
mv src-file dest-dir Moves the file src-file into dest-dir/src-file.
mv old-dir new-dir
mv old-dir existing-dir Moves the old-dir directory into the existing-dir directory.
mv -i src dest Moves or renames src to dest, but prompts if any files or directories would be overwritten. (The -i stands for “interactive”.)

rm

The rm command removes (i.e., deletes) files. (To remove directories, use rmdir if the directory is empty.)

Command Effects
rm foo Deletes the file foo.
rm -r dir Deletes the foo directory, including all of its files and subdirectories. (The -r stands for “recursive”.)
rm -i file Deletes the file foo, but prompts before actually deleting it. (The -i stands for “interactive”.)

mkdir

The mkdir command makes a new directory.

Command Effects
mkdir foo Creates a new directory named foo.

du

The du command displays the amount of disk usage for specific files and directories.

Command Effects
du -s foo Summarizes the disk usage of a file/directory foo in KB.
du -sh . Summarizes the disk usage of the current directory (represented by . in human-readable format (prints sizes using appropriate sizes such as KB, MB, GB) (-h stands for human-readable.)

There is more information about using du to get under your disk quota in Disk Quotas.