Commandline Helpers

Axel Beckert



  • Splitting up the commandline
  • Short and long options
  • Typical options
  • Where am I? What's around here?
  • Directories
  • Copying, Moving and Renaming
  • Deleting
  • Displaying files
  • How to get help on the commandline

Splitting up the commandline

Prompt  Command  Options  Parameters
>  mv  -v -i  file1 file2
$  cp  --recursive --preserve  file1 file2 directory
#  rm  -rf  directory

Long and short options

Programs on BSD and traditional Unices often only have one-character options which can be combined

GNU programme often have short (one character, starting with "-") and long variants (word, starting with "--") of its options.

Typical options

Short Long Meaning
-h --help Help
--usage Detailed helo
-v, -V --version Show software version
-v --verbose Give (verbose) output
-f --force Enforce execution
-i --interactive Ask before overwriting or destroying files
-r, -R --recursive Recursively go through directory tree
-p --preserve Keep file metadata (user, permissions, last modification time, etc.) where possible
-d3, -d 3 --debug=3 Debug level 3

Where am I? / What's around here?

  • pwd: print (current) working directory
  • ls: list
  • ls -a: list all (includes hidden files)
  • ls -l: list in long format (i.e. with details)
  • ls -d directory_name: list directory itself instead of its contents
  • ls -F: list with classification (*/@)


  • mkdir directory_name: make directory
  • mkdir -p directory_name/sub_directory_name make directory and parents
  • cd directory_name: change directory
  • cd without parameter: change to home directory
  • cd -: change to previous directory

Copying, Moving and Renaming (1)

Which command for what?

  • mv: move — Moving and renaming
  • cp: copy — Copying

Copying and moving files

  • mv old new, cp file copy
  • mv file1 file2 dir, cp file1 file2 dir
  • mv *.txt dir, cp *.txt dir

Copying, Moving and Renaming (2)

Options for mv and cp

  • mv -v …, cp -v …: verbose — say what the command is currently doing
  • mv -i …, cp -i …: interactive, ask before overwriting
  • cp -r …: recursive — also copy subdirectories
  • cp -p …: preserve — Also copy permissions and last modification time

Deleting stuff

  • rm file: Remove "file"
  • rm *.txt: Remove all files with suffix "txt"
  • rmdir directory: Remove empty directory
  • rm -r directory: Recursively remove a directory tree including all its files and subdirectories
  • rm -i *.txt: Ask before removing for each file
  • rm -f *.txt: Don't ask even before removing write-protected files

How to get help?

  • Text, easy to search through: man program_name (Help: man man)
  • Structured, with hyper links: info program_name (Help: info info; Overview over all available documentation: info without parameter)

Navigation in man/less

Input Meaning
/text<Enter> Search forward for "text"
?text<Enter> Search backward for "text"
n Next hit in current search direction
<Cursor down>, <Enter>, <Ctrl-n>, j Scroll one line down
<Cursor up>, <Ctrl-p>, k Scroll one line up
<Page down>, <Blank> Scroll one page down
<Page up>, b Scroll one page back
<Home>, g Jump to the beginning
<End>, <Shift-g> Jump to the end
q Quit

For what to look for?

Problem: A so called "man page" easily can contain over 5000 lines and often is no easy beside reading but a reference.

  • Synopsis: Short, generic examples of how to use
  • Options
  • Examples
  • See also
  • Environment
  • Files