This Linux quick reference has been compiled by current and former members of the EECS IT Support staff as a guide for the most basic Linux commands. For more detailed information about some of these commands, see our section of Linux Topics.
The file foo.c in the current (working) directory
There is a directory within the current directory named pgms, which contains a file named foo.c (pgms/foo.c is called a relative path.)
The full path to the file foo.c based on the root of the file system
Your home (login) directory
The home directory for the username
The working (current) directory
The parent directory of the current one
The parent of the parent directory
Match a single character
Match zero or more characters
Matches "fo" followed by a single character, followed by ".c". Examples: "foa.c", "fob.c", "foc.c", "fo1.c", "fo1.c", etc.
Matches "foo." followed by zero or more characters. Examples: "foo.txt", "foo.exe", "foo.", "foo.png", etc.
command > myfile
Redirects the output of command to the file name myfile instead of the terminal (standard output). If myfile already exists, its contents will be replaced.
command >> myfile
Similar to >, except the output of command is appended to the current contents of the file myfile.
command < myfile
The input to command now comes from the file myfile instead of from the keyboard (standard input).
cmd1 | cmd2
"Pipes" the output of cmd1 to the input of cmd2.
Logs everything displayed on the terminal to the file myfile. The logging is terminated with exit.
To change your EECS account password, run eecs-passwd. See the Passwords page for more details.
Creating a file
cat > myfile
Allows you to enter text with the keyboard to be stored in the file named myfile. After entering the desired text, press Ctrl+D
Launches the Vi (ViM) text editor, given a file name of myfile
Creating a directory
Creates a directory (within the current directory) named dir2
Displaying file contents
Displays entire contents of the file myfile at once. Note that to scroll this content, your terminal program (e.g., Gnome Terminal on Linux, PuTTY on Windows, Terminal on Mac) must be able to handle the scrolling.
Displays contents of the file myfile one page (full screen) at a time
Displays contents of the file myfile in a full screen view, is scrollable with the up and down arrow keys.
Performs a line-by-line comparision of the files file1 and file2. The differences are displayed in the shell window.
Performs a byte-by-byte comparison of the files file1 and file2. The differences are displayed in the shell window.
Changing access modes
Changes the modes of both files file1 and file2 to mode
chmod -R modedir
Changes the modes of all files and directories within the dir directory to mode
Here are the mode settings:
Users affected: u: user (owner) g: group o: other (world)
Actions: +: add permission -: remove permission
Access types: r: read w: write x: execute
For example, chmod go-rwx foo.c removes read, write, and execute permissions for "group" and "other" users for the file foo.c.
Listing files and directories
Lists the contest of the current (working) directory
Lists the contents of the current directory, including dotfiles
Lists the contents of the current directory in long format (shows access modes)
Moving (or renaming) files and directories
Renames the file src-file to dest-file
Moves the file src-file into the dest-dir directory
Renames the src-dir directory to dest-dir. Alternately, if dest-dir already exists, move the src-dir directory into the dest-dir directory.
mv -i srcdest
Moves src to dest but prompts before overwriting existing files/directories
Makes a copy of the file src-file and names the copy dest-file
Copies the file src-file into the dest-dir directory
cp -R src-dirdest-dir
Copies the src-dir directory and all of its contents into the dest-dir directory
cp -i srcdest
Copies src into dest, but prompts before overwriting existing files
Deleting files and directories
Deletes (removes) the file named myfile
Deletes the empty directory named mydir
rm -r mydir
Deletes the mydir directory and all of its contents
rm -i myfile
Deletes the file myfile, but prompts before doing so
Compresses the file myfile, replacing it with the file named myfile.gz
Uncompresses the file myfile.gz, replacing it with the file named myfile
Changing the working directory
Changes the current (working) directory to your login (home) directory
Changes to the mydir directory
Displaying the name of the current directory
Displays the absolute path of the current (working) directory
Searching within files
Displays the lines within the file myfile that contains the string hello
Displays the lines within the files file1, file2, etc. that contain the string hello
grep hello *
Displays the lines within any file in the current directory that contain the string hello
grep -v hello *
Displays the lines within any file in the current directory that do not contain the string hello
grep -i hello *
Displays the lines within any file in the current directory that contain the string hello in any letter-case. For example, lines containing Hello, HELLO, and HeLlO would all be displayed.
Process and job control
PID: process identifier.
job-ID: job identifier.
Listing process and jobs
Displays a list of processes and corresponding PIDs
Displays a list of processes, including "hidden" processes, and corresponding PIDs
Displays a list of current jobs and corresponding job-IDs
Stopping (suspending) a job/process
To stop (suspend) a job/process, type Ctrl+Z. The suspended process will still be listed in the list of active processes, even though it has been suspended from active execution.
Running a job in the background
Launches Firefox as a background process (note the ampersand). The browser window will still appear; however, your shell will continue to accept commands.
Suspending a process will also run that process in the background. Here's an example: