-
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 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.
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 -
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 - see