Skip to content

Sysadmin Tools (Terminal Proficiency)

aw3as edited this page Feb 27, 2015 · 5 revisions

Sysadmin Tools (Terminal Proficiency)

The majority of tools used by developers have command-line options, which provide functionality from text editing to web page downloading. Many of these tools have no graphical interface outside of a terminal, due to the need for remote access through SSH (Secured SHell). This guide will demonstrate navigation through a terminal interface to increase proficiency by our developers! Unless otherwise stated, the following commands will assume a Unix terminal. In Ubuntu, the terminal window can be opened by CTRL-ALT-T.

Structure of Unix

Unix distros will nest all folders inside a root directory, simply named / - or the Windows equivalent of C:\. Base commands, such as ls or cat (to be explained later) will be in /bin - akin to Windows' C:\Program Files. The home folder, or C:\Users\Joe is located (at least in Ubuntu) in /home/joe. Single periods, . will denote the current directory or file, while double periods, .. will denote the parent directory.

General Terminal Terminology

When providing a file or directory name, tab will attempt to auto-complete the name based on the directory contents. If a file or directory begins with a single period, e.g. .bashrc, then it is a hidden file or directory.

All terminal commands accept option flags, denoted either by a single hyphen or double hyphens. Flags can be combined, i.e. ls -a -l is equivalent to ls -al Double hyphenated flags are simply more verbose versions of their single hyphen version, ls -a is equivalent to ls --all

Command line tool outputs can be piped in or outputted to other commands or files, known as I/O redirection. This is denoted by < or > for pipe in and pipe out respectively. For example, a ls command's output can be saved into file.txt through ls > file.txt

Commands can be chained with a semicolon, e.g. ls;ls will output the directory listing twice. Bash scripting, or chaining many multiple commands using flow structures (if-else) is beyond the scope of this article, but those scripts are usually saved as any_name.sh

Basic Terminal Tools (Navigation, File Manipulation, Help)

The following list will cover basic terminal proficiency, providing commonly used commands and most-used flags.

  • pwd - shows the current path of the terminal, e.g. "/home/joe". "~" or tilde, is a shortcut to here.
  • ls - lists the current directory contents. ls -a will list hidden files as well, and ls -l will provided detailed information (filesize, date changed, etc.)
  • cd - changes the current directory. Takes an argument, e.g. cd /home/joe (functionally equivalent to cd ~ or simply cd). To navigate to a parent directory, cd .. Can be nested, e.g. to go up one folder and enter a sibling folder: cd ../second
  • cp - copies the target file into a destination file, e.g. cp old_file.txt new_folder/new_name.text Will accept -r to recursively copy directories, e.g. cp -r old_directory new_directory
  • mv - similar to cp but deletes the old one - a move command, e.g. mv old_file.txt ../. will move old_file.txt up one folder (..) and keep the same name (.). mv can also be used as a file or directory rename, e.g. mv old_name new_name. Likewise with cp, the -r flag will recursively the folder and its contents.
  • rm - removes the given file or directory. To remove recursively (i.e. folders) the -r flag is needed. Certain protected files will necessitate the -f force flag. Finally, -v will output what is being removed as it is removed. Example command - rm -rf test_directory
  • touch - creates an empty file with a given name in the current directory, e.g. touch new_file
  • man - gives the manual or help documentation for any command, e.g. man ls Helpful for describing any flags that you are unsure of.
  • cat - reads a filename and directly outputs (pipes) to terminal, e.g. cat foo.bar Can also concatenate files together when using I/O redirection, e.g. cat file1 file2 > new_file will combine file1 and file2 contents into new_file. To append a file to another, cat file1 >> file2 will add file1 contents to the end of file2.
  • tail - outputs the last lines of a file to the terminal. Used with the -f or --follow flag to continuously monitor a file's output, usually when accessing log files, e.g. tail -f log.txt
  • clear - clears the current output buffer, so the terminal screen is clean.
  • exit - closes the current terminal window.

Advanced Terminal Tools

These tools will often be installed as packages, and most will merit their own wiki page for specifics.

Clone this wiki locally