Linux: Basic Shell Commands

By Xah Lee. Date: . Last updated: .

This is a list of most frequently used linux commands. These are essential commands. Most of them are used everyday by every linux user.

The code here are based on Ubuntu Linux, but 99% of them work in any unix, including Mac OS X.

Get System Info


Archive, Compression (tar, gzip)

Viewing File

Locate Command

Install Program/Package

Text Processing

Fetching and Sync Remote Files: rsync, unison, wget, curl

Manage Process

Job Control

File Permission System

Users and Groups

Version Control


Show current date and time
date --rfc-3339=seconds
Show time stamp in this format: “yyyy-mm-dd hh:mm:ss-07:00” the last are time offset to UTC.
Show how long the system's been running.
source fname
Execute a file fname. source fname is equivalent to . fname
Start a new bash. Ctrl+d to exit when done.
echo $PATH
View value of a environment variable PATH.
Show all environment variables
alias str=cmd_str;
Make str as shortcut for cmd_str. For example, alias l="ls -al --color"

[see Show Opened Files, lsof]

Image Processing

Generic Useful Bash Syntax

cmd *.txt
A asterisk “*” means any character. *.txt means all files ending in “.txt”. Can be used for any command that take list of files or dir. See man 7 glob.
cmd1 | cmd2
Pass the output of cmd1 to the input of cmd2
cat fileName | cmd
Feed the content of fileName to the input of cmd
cmd > fileName
Write the output to file
cmd >> fileName
Append output to file
cat fileName1 fileName2 > newFileName
Join contents of fileName1 fileName2 to newFileName
cmd1; cmd2; …
Run several commands.
cmd1 && cmd2
Run cmd1, if success, then run cmd2 (otherwise stop.) (the && is a logical “and” operator. Unix commands returns 0 if success, else a integer error code.)
… `cmd` …
Generate the output of cmd and use it in your whole command. For example, ls -l `which more`
cmd &
Run the command cmd in background.
echo $?
Show exit status of previous command.

Bash Keys

Bash Keys

Linux {Desktop, Window Manager} Overview

How to Switch to LXDE, Xfce