-
Notifications
You must be signed in to change notification settings - Fork 14
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.
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 isC:\ -
/bin- (short for binaries). Base commands necessary for file navigation likels,cp, orcatreside 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/binand/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/binand/usr/sbincontain non-essential system commands/var- Short for "variable." Contains files that vary as the system runs, like log files and caches.
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
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 -awill list hidden files as well, andls -lwill provided detailed information (filesize, date changed, etc.) -
cd- changes the current directory. Takes an argument, e.g.cd /home/joe(functionally equivalent tocd ~or simplycd). 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.textWill accept-rto recursively copy directories, e.g.cp -r old_directory new_directory -
mv- similar tocpbut deletes the old one - a move command, e.g.mv old_file.txt ../.will moveold_file.txtup one folder (..) and keep the same name (.).mvcan also be used as a file or directory rename, e.g.mv old_name new_name. Likewise withcp, the-rflag will recursively the folder and its contents. -
rm- removes the given file or directory. To remove recursively (i.e. folders) the-rflag is needed. Certain protected files will necessitate the-fforce flag. Finally,-vwill 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 lsHelpful for describing any flags that you are unsure of. -
cat- reads a filename and directly outputs (pipes) to terminal, e.g.cat foo.barCan also concatenate files together when using I/O redirection, e.g.cat file1 file2 > new_filewill combinefile1andfile2contents intonew_file. To append a file to another,cat file1 >> file2will addfile1contents to the end offile2. -
tail- outputs the last lines of a file to the terminal. Used with the-for--followflag to continuously monitor a file's output, usually when accessing log files, e.g.tail -f log.txt -
ls -ltra- lists all files in a directory as well as their permissions, ownership, last modified date, and in reverse alphabetical order -
chown <user>:<group> <file>- files are owned by users and also by groups. Sometimes you won't be able to run a program or open a file because you don't have permission to do so. Thechowncommand can be run as root and modify who has permission to use the file or program -
clear- clears the current output buffer, so the terminal screen is clean. -
exit- closes the current terminal window.
These tools will often be installed as packages, and most will merit their own wiki page for specifics.
-
apt-get(oryum) - installs packages using packaging manager systems. -
vim- terminal text editor for files -
subl- See here for directions on how to make this shortcut to use Sublime as your default text editor