Commands Glossary

Last modified: Aug 29, 2023
Contents:

This is a glossary of the Linux commands covered in this course.

Notations:

1 On Your Own PC

Command Example Explanation & 1st Introduction
ssh yourCSLoginName@server ssh cs_jdo001@linux.cs.odu.edu Log in to a remote server
ssh -A yourCSLoginName@server ssh -A cs_jdo001@linux.cs.odu.edu Log in to a remote server, authorizing SSH keys

2 Linux

Command Example Explanation & 1st Introduction
echo echo $TERM prints whatever its arguments really stand for
exit exit Log out of your current SSH session
export TERM=xxx export TERM=vt100 set your terminal type
whoami whoami prints your user name
file path file foo.txt Indicate what kind of data is stored in a file.
cd path cd ~/playing change your current working directory
ls ls [list]](doc:files) the files in your current working directory
ls path ls /usr list the files at that path
ls -F path ls -F ~ list the files at that path with simple indicators of whether they are directories, links, executable commands, or just “ordinary” files
pwd pwd prints your current working directory
cp path1 path2 ... destination cp /usr/include/math.h /usr/include/stdio.h ~/playing Copy one or more files to a destination. The paths must point to ordinary files, not directories.
If there is more than one path, the destination must be a directory. All of the files listed in the paths are copied into that directory.
If there is only one path, the destination may be an existing file or directory or it might not exist. If it is an existing file, this command overwrites it with the contents of the path file. If it is an existing directory, the path file is copied into that directory. If the destination does nto exist, a file is created with with the name indicated in the destination and the contents of the path copied into it.
cat path1 path2 ... cat ~/playing/math.h List the contents of one or more files to the screen, as if they had been joined together (or concatenated).
ls -a path ls -a . list the files at that path including all “hidden” files (anems starting with ‘.’)
ls -l path ls -l ~/playing list the files at that path with information indicating whether they are directories and indicating what permissions people have o access those files and directories.
mkdir path mkdir ~/playing/cards create a directory
more path mkdir ~/playing/math.h List the contents of a file, one “page” at a time. Use the space bar to move forward, ‘b’ to move back, and ‘q’ to quit.
mv filepath1 filepath2 mv foo.txt ~/playing/bar.txt | [Move](doc:basicCommands) and rename the file at the first path to the second. (The second path must not be an existing directory.) | |mv path1 path2destination|mv ~/playing/math.h ~/playing/stdio.h ~/playing| [Move](doc:basicCommands) one or more files into a destination directory. | |rm path1 path2|rm ~/playing/math.h| [Delete](doc:basicCommands) one or more files. | |rmdir path|rmdir ~/playing/cards| [Delete](doc:basicCommands) a directory (must be empty). | |tree path|tree ~/playing` produce a visual display of an entire “tree” of directories and files

3 File and Directory Manipulation

cd directory
Changes your current working directory to the indicated directory, which may be absolute or relative. Basic File Manipulation
chmod permission files
Set the permissions on a set of files. File Protection
cp
Copies one or more files.

Common variants:

  • cp file1 file2

    Copies file1 as file2. file2 may be in a different directory. If file2 already exists, it is replaced by this copy.

  • cp file path

    Copies file as path. This variant allows you to copy a file and rename the copy at the same time.

  • cp files directory

    Copies all of the listed files , placing the copies in the given directory.

  • cp -r files directory

    Copies all of the listed files, …, placing the copies in the given directory. Normally, cp will work only on ordinary files but will ignore any directories in the list of things to be copied. The -r option causes any directories (and their contents) to be copied as well.

find directory instructions
Searches the indicated directory and any subdirectories within it for files. The instructions may serve to limit the files found (e.g., search for files with a given name or that have been modified after a given date) or may indicate commands to run on those files. Commands That Launch Other Commands

ls : Lists the files in directories Basic File Manipulation

Common variations: 

* `ls` _path_

    Lists all the files matching the indicated _path_. If that
    path is a directory, lists all the files within that
    directory. You can provide multiple paths in the same command,
    or omit the path entirely (in which case the contents of your
    current working directory will be listed).

* `ls -a` _path_

    By default, file names beginning with "." are considered
    "hidden" and not shown by the `ls` command. The `-a` (for
    "**a**ll") option causes these files to be shown as well.

* `ls -l` _path_

    This is the "long" form of `ls`. It displays additional
    information about each file, such as the size and date on
    which the file was last modified.


* `ls -F` _path_

    Adds a little bit of extra information to each file name. If
    the file is an executable program, its name is marked with an
    "*". If the file is a directory, its name is marked with "/".


Note that options can be combined. For example,
you can say `ls -la` to get the long extra information
including normally hidden files.
mkdir new-path
Creates a directory. Basic File Manipulation

E.g.,

mkdir ~/newDirectory

would create a newDirectory inside your home directory.

mv
Moves and/or renames files. You must give one or more files to be moved or renamed. If you give one file, you can then supply the path and new file name. If you give multiple files, you cannot rename them but must supply a path to a directory where you want them moved. Basic File Manipulation

Common variants:

  • mv file-path1 file-path2

    Renames file-path1 as file-path2. file2 may be in a different directory.

    If a the file file-path2 already exists, and is not a directory, it will be replaced by the moved/renamed file.

  • mv file-path directory-path

    Moves file-path, without renaming the file, into the directory directory-path. That directory must already exist, otherwise this is treated as the first variant above.

  • mv file-path1 file-path2directory

    Moves multiple files to the given directory (without renaming them).

pwd
Prints your current working directory. Basic File Manipulation
rm file1filen
Deletes the listed files. Be very careful using wildcards with this command. rm * will delete everything in the current working directory!
rm -i file1filen
Deletes the listed files, but firsts asks permission to delete each one.
rm -r file1filen
Deletes the listed files. If any of these files is a directory, it deletes that directory and everything in it as well.
rmdir directory
Deletes a directory (if empty).
umask number
Sets the default permissions for newly created files. File Protection

4 Text File Manipulation

cat file1filen
Lists the contents of each of the listed files to stnadard output (by default, your screen). Redirection and Pipes
emacs
Edit a text file, creating an empty one at the given path if it does not already exist. Editing in Text Mode

Common variants:

  • emacs -nw file

    Edit in the current window, used mainly in text-mode sessions.

  • emacs file &

    Edit in a separate window – used mainly in graphics-mode (X) sessions.

grep regular-expression files
Examines each line of text wihtin the files to see if they match the pattern given as the regular-expression. The matching lines are printed to the output. Wild Cards Typing Unix Commands Searching Lines with grep

Common variations:

  • grep -i …

    Upper/lower case is ignored when matching alphabetic characters.

  • grep -l …

    Do not list the lines that match the pattern, but list all files contianing at least one matching line.

  • grep -v …

    Lists the lines that do not match the pattern.

  • If no file paths are given, grep searches through standard input (by default, text typed at the keyboard). This variation is usually combined with redirection or pipes.

more file1filen
Lists files one screen at a time, pausing after each screen-full. Hit the space bar to advance to the next screen. Typing Unix Commands

Hit “b” to go backwards, and “q” to quit. You can search for strings by hitting “/” followed by whatever you want to search for.

A related program is less, which used to do a lot more than more. The original version of more used to be limited to moving forward and quitting, so less was invented to offer more features such as moving backwards and searching. But, over the years, enough of these features have been copied from less into more that now less may not do much more than more, though it certainly does no less.

nano file
Edit a text file, creating an empty one at the given path if it does not already exist. Editing in Text Mode
sed editing-instructions file
Applies the editing instructions to each line of the file, writing out the resulting changed version of the file.

The most common editing instruction is the “substitute” instruction, s/pattern/replacement/, which tells sed to scan each line of the input for text that matches a regular expression pattern and replaces matching text with replacement.
Rewriting lines with sed

Common variations:

  • sed s/_pattern_/_replacement_/i file

    Ignores upper/lower case when matching alphabetic characters.

  • sed s/_pattern_/_replacement_/g file

    If a single line matches the pattern more than once, replaces all matching text. With the g flag, only the first match in each line is replaced.

  • If no file name is given, sed searches through standard input (by default, text typed at the keyboard). This variation is usually combined with redirection or pipes.

vim file
Edit a text file, creating an empty one at the given path if it does not already exist. Editing in Text Mode

Common variants:

  • vim -g file &

    Edit in a separate window. You must be in a graphics mode (X) session.

5 Session Control

exit
Shut down the current shell. If this shell is the one you got at log-in, this command logs you out. Logging In to Remote Linux Machines
rlogin machine
Logs you in to another machine on the network. Use this if the machine you are on seems to be running slowly and the who command indicates that there are lots of others on the same machine.
who
Lists everyone logged into the same machine that you are using. Logging In to Remote Linux Machines Typing Unix Commands
wc files
Lists the number of characters, words, and lines in a text file. Redirection and Pipes

Common variations:

  • wc -l files

    Lists only the number of lines.

  • If no file paths are given, wc looks instead at the standard input.

6 Interacting with remote machines

wget URL
Fetches a file for which you have an internet URL, depositing that file in your current directory
scp localFilePath _yourName@machineName:remoteFilePath_
Copies a file from your current machine to a remote one. remoteFilePath must be given as an absolute path.
scp _yourName@machineName:remoteFilePath_ localFilePath
Copies a file from a remote machine to your current one. remoteFilePath must be given as an absolute path.
ssh _yourName@machineName_
Logs in to a remote machine and allows you to issue commands to it. Logging In to Remote Linux Machines

7 Miscellaneous

date
prints the current date and time. Commands That Launch Other Commands
echo parameters
Prints its parameters. Typing Unix Commands

This can be useful as a way of seeing what the command shell does to various special characters before invoking a command. E.g.,

echo I am $USER
echo *
man command
Prints the help (manual) pages for the command. Typing Unix Commands
xargs command
Accepts a list of file paths from standard input and issues the command on each of them. Commands That Launch Other Commands