XXIIVV
Static
Static12U00

Unix is a family of computer operating systems that derive from the original Unix from Bell Labs.

This is the Unix philosophy: Write programs that do one thing and do it well. Write programs to work together. Write programs to handle text streams, because that is a universal interface.

Expect the output of every program to become the input to another, as yet unknown, program. Don't clutter output with extraneous information. Avoid stringently columnar or binary input formats. Don't insist on interactive input.

Locations in home

$HOME/binLocal binaries
$HOME/etcSystem configuration for local binaries
$HOME/gamesLocal game binaries
$HOME/includeLocal C header files
$HOME/libLocal libraries
$HOME/lib64Local 64-bit libraries
$HOME/manLocal online manuals
$HOME/sbinLocal system binaries
$HOME/shareLocal architecture-independent hierarchy
$HOME/srcLocal source code

Primitives

lsList files in the directory
cdChange directory
rmRemove file or directory(-r)
cpCopy file or directory(-r)
mvMove file or directory
wcCount words in file
manRead the manual
catReads content of files sequentially
mkdirMake new directory
dateShow system date
grepSearches text for matches of a regular expression
tailDisplays the tail end of a file or data

Cheatsheet

Copy a file

$ cp readme.txt documents/

Duplicate a file

$ cp readme.txt readme.bak.txt

Copy a directory

$ cp -a myMusic myMedia/

Duplicate a directory

$ cp -a myMusic/ myMedia/

Move a file

$ mv readme.txt documents/

Move a directory

$ mv myMedia myMusic/

Rename a directory

$ mv myMedia/ myMusic/

Merge directories

$ rsync -a /images/ /images2/

Create a new file

$ touch 'new file'

Create a new directory

$ mkdir 'untitled folder'

Show file/directory size

$ du -sh node_modules/

Show file/directory info

$ stat readme.md

Open a file with the default program

$ xdg-open file  # on Linux

Zip a directory

$ zip -r archive_name.zip folder_to_compress

Unzip a directory

$ unzip archive_name.zip

Peek files in a zip file

$ unzip -l archive_name.zip

Remove a file

$ rm my_useless_file
$ rm -r my_useless_folder

List directory contents

$ ls my_folder    # Simple

Tree view a directory and its subdirectories

$ tree

Find a stale file

$ find my_folder -mtime +5

View content of a file

$ cat apps/settings.py

Search for a text

$ grep -i "Query" file.txt

Make applications in ~/bin/ available from anywhere

Edit ~/.bashrc, when finished run source ~/.bashrc.

export PATH=$PATH:$HOME/bin

Pipes

ls > fooSend output from ls into file foo
wc < fooReceive input from file foo into wc
ls | wcConnect output of ls into input of wc

Aliases

An alias let you define your own command names, so you can customize the command line, and make it work the way you want it to work. You can see the list of aliases with:

alias

To create an alias that will be there for you every time you start your computer, open ~/.bash_profile and add a line like:

alias left='uxnemu ~/roms/left.rom'

When finished, run the following line to apply your changes:

source ~/.bash_profile

You have just created a new alias called left.

From each according to their stdout to each according to their stdin

Usage

A usage statement is a printed summary of how to invoke a program from a shell prompt. It includes a description of the possible command-line arguments that the program might take. If a program is called with incorrect command-line arguments, it should print a usage statement to the terminal.

usage: ls [-a] [-F]

This program is called ls and can be called with no arguments, with one optional argument (ls -a or ls -F) or with two optional arguments (ls -a -F). In this particular case, the -a optional argument says to list hidden files as well as normal ones, and -F changes the way the output of the program is formatted.

Usage statements should be printed to "standard error" stderr, and not to stdout. Your usage statement should contain:

Formatting guidelines

Optional arguments should always be surrounded by square brackets. Do not use square brackets for any other purpose in usage messages. Don't use anything but square brackets for this purpose. Square brackets mean that an argument is optional, always.

Optional "flags" (arguments that change the way the program works) should start with a dash. Very often (but not always) they will have a name which is a dash followed by a single letter, which identifies what it is.

Note that each optional argument gets its own set of square brackets. If an optional "flag" argument itself has arguments, put them inside the square brackets.

Notes

You shouldn't hard-code the program name into your program's source code. It won't make any difference in how it's displayed, but if you change the name of your program and don't change your usage message the usage message will be invalid. Instead, you should write your code so that the program name gets inserted into the usage message before printing. In C, the program name is argv[0] (the first element of the argv array) whereas in python it's sys.argv[0].

incoming firth raspberry