User Tools

Site Tools


unix_commands

Some Basic Unix Commands

Required Reading

Finding Commands

Most user-level commands can be found in the /bin, /usr/bin, and /usr/local/bin directories. Some programs can be found in /sbin and/or /usr/sbin, but those programs are usually reserved for the administrator, and they won't work for you unless you have the password. You can also use the man command to search for commands by keyword, but search is limited. Google is probably a better choice unless you know a specific keyword you're looking for.

A List Of Some Popular Commands

Command Description
arch
Outputs the hardware architecture of the current machine.
$ arch
x86_64

Man Page

awk
A very powerful text processing program. Entire books have been dedicated to it's use, and I won't even begin to understand everything that it can do. But I'll give you some links.

Man PageGNU ManualExamples
basename
Given a path as a command line argument, output the last segment:
$ basename /path/to/directory/file.txt
file.txt

Additionally, when given a suffix, it will strip off the suffix:

$ basename /path/to/directory/file.txt .txt
file

Man Page

bash
A standard shell program available on almost every Unix-based system. There's a good chance that when you open a terminal this is the shell program that the terminal runs. There are other shell programs, and each has it's own strengths and weaknesses, but for the purposes of these wiki pages the bash script will be what we focus on.

Man PageGNU Manual
basename
Strip directory (and optionally suffix) from path names.

Man Page
bc
An arbitrary-precision command line calculator.

Man PageGNU ManualExamples
cat
Concatenate one or more files.

Man Page
cd
Change directory.

Man Page
chmod
Change file or directory permissions.

Man Page Examples
chown
Change file or directory ownership.

Man Page
clear
Clear the terminal screen.

Man Page
cp
Copy file(s).

Man Page Examples
cut
Read input line at a time, removing a segment of each line before output.

Man Page Examples
date
Return a time and date in configurable formats.

Man Page Examples
df
Return the space used on a filesystem.

Man Page Examples
dirname
Given a path as a command line argument, output everything except the last segment (the inverse of basename).

Man Page
echo
Output a string.

Man Page
exec
Replace the currently running shell or script with a new command.

Man Page
exit
Return an exit code to the parent shell.

Man Page
export
Add a variable to the environment.

Man Page
file
Get information about the type of data inside a file.

Man Page
find
Locate files and/or directories according to user-supplied search criteria.

Man Page Examples
for
A loop command:
for <condition>; do <commands>; done

Example

free
Outputs information about how much memory exists and is being used. Man Page
grep
Reads input line at a time searching for a regular expression. If found, an action is taken. (Or if not found, an action is taken, depending on command line options used.)

Man Page Examples
gzip
Compress a file.

Man Page Examples
head
Reads input line at a time, outputting the first <N> lines.

Man Page Examples
if
A conditional command:
if <condition>; then <commands>; fi

Or a more complex example:

if <condition>; then 
  <commands> 
elif <condition2>; then 
  <commands2> ; 
elif <condition3>; then 
  <commands3> ; ... ; 
fi

Examples

last
Ouptuts a list of users who last logged into this machine.

Man Page
less
Reads input and prints it to the screen, one page at a time. It pauses the output and gives the user a chance to read what they want. It will resume when the user pressed the space bar or the return key. This command is a newer version of the more command, which does the same thing except without some nice features like the ability to go backward or to search through the file.

Man Page Examples
ln
Creates a symbolic (think Windows' shortcut) or hard link (file physically exists in two places on the filesystem at once).

Man Page Examples
ls
Outputs a directory listing.

Man Page Examples
make
Searched for a file named “Makefile” or “makefile” and, if found, executes the commands within. Execution stops if an error occurs.

Man Page GNU Manual
mc
A text-based file manager.

Man Page
mkdir
Create a directory.

Man Page Examples
mv
Move or rename a file or directory.

Man Page Examples
paste
Merge lines from multiple files.

Man Page Examples
ping
Tests to see if a remote host is reachable over the network.

Man Page Examples
pwd
Ouptuts the current working directory.

Man Page
read
Reads a line from input and stores it in an environment variable.

Man Page Examples
rm
Deletes a file. (NOTE: There is no going back!)

Man Page Examples
rsync
A synchronization tool that can update, copy, or delete files between two locations – both locally and over a network.

Man Page Examples
screen
A fake terminal tool that can be used to run commands even after you log out.

Man Page GNU Manual Examples
script
A fake terminal tool that will store everything typed or printed to the terminal window into a file – handy for recording your terminal session.

Man Page
sed
A search-and-replace text editing tool.

Man Page GNU Manual Examples
set
This command will show you all of the environment variables currently set in your shell.

Man Page Examples
seq
This command takes two integer command line arguments and outputs every integer between them, inclusively, as it counts from the first to the second.

Man Page Examples
shift
Used for processing command line arguments in shell scripts.

Man Page Examples
sort
Reads input one line at a time, sorts the lines, and then outputs the results.

Man Page Examples
ssh
A program for connecting to a remote host securely.

Man Page Examples
tail
Reads input line at a time, only outputting the last <N> lines.

Man Page Examples
tar
A program used to pack multiple files or directories into a single file. Like a zip file, but without compression. (Compression is usually handled by a separate program like gzip, bzip2, or xz.)

Man Page Examples
test
Used to test certain conditional expressions. Often used with if, for, and while conditional statements.

Man Page Examples
time
Used to measure the amount of time that a command takes to execute.

Man Page Examples
touch
Used to create empty files, or to update the timestamp on existing files.

Man Page Examples
tr
Used to transform input. A simple example would be to capitalize text.

Man Page Examples
true
Always returns a successful exit code. Used in conjunction with boolean logic expressions and/or inside if, for, and while conditional statements.

Man Page
uptime
Outputs the amount of time that this machine has been turned on.

Man Page
wc
Reads input line at a time and outputs user-specified metrics such as the number of lines, the number of words, the number of characters, or the number of bytes.

Man Page Examples
wget
A command line tool for interacting with a web server. Can be used to download HTML, or to download a file from a web page.

Man Page Examples
which
Outputs the location of a program, if known.

Man Page
while
A conditional loop command:
while <condition>; do <commands>; done

Examples

This list is by no means exhaustive!

unix_commands.txt · Last modified: 2016/05/25 20:22 by peek