ncl-tools

Tools for National Cyber League Competition

View on GitHub

Appndix: Command Line Commands

File Tree Navigation

ls lists all files and directories in the working directory.

Input/Output Redirection

Alias

Grep

grep stands for “global regular expression print”. It searches files for lines that match a pattern and returns the results. Case sensitive. Grep Documentation located here.

Syntax of grep command:

grep [option...] [patterns] [file...]

There can be zero or more options and zero or more files. Typically, patterns should be quoted.

Uniq

uniq “unique”. Takes a filename or standard input and prints out every line, removing any exact duplicates.

Syntax of uniq command:

uniq [option] [INPUT[OUTPUT]]

Options for uniq command:

Note: sort the input first to filter all unique lines, not just contiguous ones.

Sort

Sort documentation found here. Tool to sort, merge, or compare all the lines from the files given (or standard input).

Sort command syntax:

sort [options] [file...]
sort [options] ... --files0-from=F

Sort command ordering options:

Other options given in sort man page (linked above). Descriptions of how lines are compared and sorted given in man page. Examples of sort command also given in man page.

Misc.

Background Commands and Persistent Sessions

To run a command in the background, add ampersand to the end of the command:

command &

To suppress the stdout and stderr messages, use:

command > /dev/null 2>&1 &

To display the status of all stoped and background jobs in the current shell session:

jobs -l

To bring a background process to the foreground, use the fg command (or fg %1 if you have multiple background jobs.

To terminate the background process, use the kill command followed by the process ID (which can be obtained through the jobs -l command, above. In this example it’s 12928):

kill -9 12928

Generally, if connection drops or you exit the shell session, the background process terminates. To keep the process running, use the disown command or start the process with the nohup command.

Alternatively, use Tmux (“terminal multiplexer”) to switch between multiple programs in one terminal. Tmux sessions are persistent; programs will continue to run even if you exit the shell or are disconnected.