Linux Shell Commands

Basic LINUX/UNIX shell commands

Files and Folders

~ home directory

. present working directory

Environment

~/.bash* files that define the environment

Interpreters and Compilers

awk

C-like stream processing language

env

print the environment variables

sed

stream line editor

cd

change directory

export

define and inherit environment variable

bc

arbitrary precision calculator language

pwd

print path to present working dir

set

set or unset shell options

python

MatLab -like programming language

ls

list directory content

whereis

locate commands and manpages

gfortran

GNU FORTRAN-Compiler

mkdir

create a new folder

which

locate commands

gcc

GNU C-Compiler

rmdir

remove an existing folder

alias

define abbreviations for commands

make

compiling and processing utility

rm

remove files and folders

function

more complex abbreviations

 

 

chmod

change file status

 

 

Print commands

chown

change file owner

Job and Process Control

echo

unformatted printout

ln

create link to file or folder

jobs

list of active jobs in a terminal

printf

formatted printout

cp

copy

fg #

get job # to the foreground

 

mv

move

bg #

send job # to the background

Online Help

find

find

CTRL–c

Cancel the job in the foreground

man

display manual page ( troff processor)

locate

simple version of find

CTRL-z

Pause the job in the foreground

help

bash command to display help

du

print directory usage (file sizes)

… &

Start a job in the background

info

GNU-related help

df

print file system disk space

top, ps

list of processes on a computer

 

touch

change time stamp of a file

kill #

terminate process #

Commands

 

 

 

history

display cmd buffer

File Content

 

! #

repeat cmd number #

cat

print file content(s) to stdout

Input and Output Redirection

! char

repeat last cmd starting with char

more

print file content page by page

…|…

pipe stdout to the next command

A command is often followed by an argument, and its behavior can be refined with options.

The most general syntax is:

command [options] [arguments]

Options typically start with (occasionally +) , e.g., ls –a –l folder

Most commands have default arguments, e.g., the default of folder is the present working directory. Most options (especially flags that require no arguments) can be written together

ls –al

less

scroll through file content

> file

redirect stdout to file

cut

cut columns from a file

>> file

append stdout to file

vi, vim

programmers text editor

>& file

redirect stdout and stderr to file

wc

count words (lines, characters...)

2> file

redirect stderr to file

grep

scan files for certain content

( … )

group stdout and stderr

diff

print differences between two files

<<END … END

redirect to stdin

sort

sort lines of files

tee

duplicate stdout and route to file

head

print first lines of a files

 

 

tail

print last lines of a file

Archives

tac

print file content(s) backwards to stdout

tar, gzip , gunzip, bzip2