bash basics

🗞Shell
bash
basic
  • Unix: Standard input: keyboard, standard output: screen
  • Stop with strg + d

Pipe operator

Get list of logged in user names:

who > names.txt
sort < names.txt

Better:

who | sort

Noteworthy unix commands

Basics

cd..
mkdir
top
rm
cp
mv

Write blablabla into .vimrc with echo

echo “blablabla” >> .vimrc

Read files

cat test.tex    	:   	Displays the contents of test.tex
head test.tex		:	Display the first few lines
tail test.tex		:	Display last few lines
more test.tex		:

Find files

find \usr\ -name "sup*"

find /myfiles -type d

OSX: Open a file

Opens the file with the default-programme for that file-ending. By default it will be the app preview in which the pdf will be opened.

open file.pdf

Plot

echo $PATH

Description

Short Long
whatis cp man cp

Compare files

Compare contents of file1 and file2:

diff file1 file2

Does the same, but also works for binary

cmp file1 file2

Redo last command

!!

Get file-size

Get file size of myfile.txt in human readable form

du -h myfile.txt

Get file size of current folder (all its files recursively)

du -d0 -h .

Redirect

Redicrect output to somewhere else with >

Redirect information about logged in user into a file names.txt:

who > names.txt

Redirect input to come from somewhere: <

sort < big_list_of_words.txt

Append to a list

>>

Good homepages with tips:

Discuss on TwitterImprove this article: Edit on GitHub

Discussion


Explain Programming

André Kovac builds products, creates software, teaches coding, communicates science and speaks at events.