Common Unix Commands

Common Command Line Interface commands for the unix family, including Linux and Mac OS X.


Command-Chaining Operators

Command Description
AND - OR && - || Combining and AND and OR operator acts like an if-else statement
AND && Execute proceeding command only if the preceding command succeeds with an exit status of 0
Ampersand & Run the preceding command in the background
Group {} Group two or more commands, dependent on the preceding operand.
NOT ! Execute all except the condition provided
OR || Execute proceeding command only if the preceding command fails with an exit status of 1
PIPE | Output from the preceding command is fed to the proceeding command
Precedence () Execute commands with precedence such as in math
Semi-colon ; Run the preceding command sequentially

File Management

cd

Change working directory.

Command Description
$ cd ~/ Change to home directory.
$ cd .. Change working directory to one level back.

clear

Clear the terminal output.

Command Description
$ clear Clear the terminal output.

find

Recursively finds files within path.

Command Description
$ find ~/ -name unix-commands.md Finds the file unix-commands.md within the users home directory.

locate

Find filenames quickly by using a database.

Command Description
$ locate *.md -n 20 List filenames ending with .md, and limit queries to 20.

ls

List files within working directory.

Command Description
$ ls -1 *.md List files that ends with .md, and force output to be one entry per line.

man

Displays manual for command. Pressing q quits the process.

Command Description
$ man cd Displays manual for the ls command.

mkdir

Create directory if they do not already exist.

Command Description
$ mkdir wiki Create directory named wiki.

mv

Move and or rename file/folder from source to destination.

Command Description
$ mv unix-commands.md commands/unix.md Move unix-commands.md to the commands directory, and name the file unix.md.

pwd

Return working directory name.

Command Description
$ pwn Return working directory name.

rm

Removes directory entries. Be very careful with this command.

Command Description
$ rm unix-commands.md Remove file named unix-command.md.
$ rm -rf .DS_Store Removes all Mac Desktop Servies Store files, recursively.

rmdir

Removes directories.

Command Description
$ rmdir docs Remove directory named docs.

touch

Create a file with default permissions.

Command Description
$ touch unix-commands.md Create file unix-commands.md, if it does not exist. If it does, change modification and access times.

Power Management

halt

Stop the system.

Command Description
$ sudo halt Stop the system.

reboot

Restart the system.

Command Description
$ sudo reboot Restart the system.

SCP (Secure Copy)

Copies files between hosts on a network. It uses ssh for data transfer. This comes in handy transferring files from your desktop to your arcade pc or raspberry pi. Be careful as scp will overwrite files without warning.

Command Description
$ scp [OPTION] [user@SRC_HOST:]file1 [user@DEST_HOST:]file2 Copies files between hosts on a network.
$ sudo scp -r wiki/ pi@raspberrypi.local:~/ Copy the wiki directory recursively to the user home directory on the raspberry pi.