Skip to content

Sysadmin Tools (Terminal Proficiency)

Daniel Coo edited this page Jun 20, 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 (short for distributions) nest all folders inside a root directory, simply named / - or the Windows equivalent of C:\. The home folder, denoted as C:\Users\Joe in Windows is located in /home/joe on linux boxes. Single periods, . denote the current directory or file, while double periods, .. will denote the parent directory (more on this later).

  • / - The root directory. The Windows equivalent is C:\
  • /bin - (short for binaries). Base commands necessary for file navigation like ls, cp, or cat reside here
  • /boot - Contains essential startup information
  • /cdrom - Cd's can be "mounted" in this directory. Mounting a device means making it visible to your computer. However, you should typically mount all of your devices to /media
  • /dev - Contains system drivers and important system files
  • /etc - Pronounced "ET - see". Contains essential system and network configuration files. Do NOT mess with this directory
  • /home - This is where all users are stored with the exception of root. Windows equivalent of "My Documents and Settings." Holds personal files and settings
  • /lib - Contains the library files for all the binaries in /bin and /sbin
  • /lost+found - Recovered files are placed here if your system crashes
  • /media - All mounted devices go here: usb's, cd's, dvd's, and all other flash drives
  • /mnt - Mount point for temporary file settings. You should be using /media
  • /opt - If you are using the Solaris distro then you are the only one who uses this
  • /proc - Not important
  • /root - Very important. This is the directory for the root/super user. /root ~ /home/daniel
  • /run - Not important
  • /sbin - Binaries reserved for root/super users are stored here
  • /srv - Short for "serve". Not important
  • /sys - Contains kernel and system settings
  • /tmp - Holds temporary files. This directory is cleaned on every reboot. It is not good practice to manually delete things from here
  • /usr - Contains binaries and libraries for user applications. /usr/bin and /usr/sbin contain non-essential system commands /var - Short for "variable." Contains files that vary as the system runs, like log files and caches.

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