Basic unix commands
Find and grep
Unix Command | Description |
---|---|
|
Lists all |
|
Find all files containing the pattern |
|
Find files named |
|
Show all current |
|
Look for the string |
Current process
Unix Command | Description |
---|---|
|
Displays all current running processes containing |
|
Displays detailed view of the process with the given process ID. |
kill -9 66939 |
kill processes with the id |
|
kill processes with the name |
Compress and encrypt with ZIP
Unix Command | Description |
---|---|
zip -r -e FinalName SourceDirectory |
Recursive compression of the |
unzip SourceDirectory |
Uncompress (and decrypt) the |
Copy
Unix Command | Description |
---|---|
|
Copies ALL files, including hidden files and the whole directory structure recursiv |
|
Copys |
|
Copys |
|
Copys |
Network
Unix Command | Description |
---|---|
|
Display information about all interfaces in the system |
|
Query Internet domain name servers |
|
Create and close one TCP connection to port 5432 to the host 127.0.0.1 (e.g check data base connectivity) |
|
Shows network status with IP adresses and ports |
Inspect files
Unix Command | Description |
---|---|
|
list all files sorted by time as most recently modified are last displayed |
|
tee reads standard input and writes it to both standard output and one or more files |
|
Inspects the |
|
Displays last lines of ALL files in current directory, waits for further input |
|
compare files line by line |
|
recursive compare of folders |
Mixed
Unix Command | Description |
---|---|
|
halt and close down the system immediately, requires |
|
Write the String 'myLine' inside of the file |
|
Displays statistics about the amount of free disk space in "Human-readable" output. |
|
Displays size in human readable format of |
|
Creates a parent directory |
|
Change ownership of directory |
|
tar process stream files |
Bash environment
Unix Command | Description |
---|---|
|
List ALL environment variables |
|
locate the program |
Platform dependent tools
OS X - Using pasteboard/clipboard
Command | Description |
---|---|
|
(1) Copies current directory inside the clipboard |
|
(2) changes directory to the value inside clipboard |
Ubuntu Linux
Linux Command | Description |
---|---|
|
Installs debian package |
|
Update debian package list |
|
Installs |
|
Removes |
|
Removes |
|
Removes obsolete dependencies from |
Bash Configuration
Ubuntu Linux
Setting global environment variables for login and sub shells
A login shell is started on system boot process. It’s the one where the user is going to be authenticated by its credentials (username, password). All user specific configurations are loaded on this point for the user. Other shells started from this point, derive the settings from the login shell and are called sub shells (like the manual start of the terminal program that runs the shell in a window).
To see another login shell you can leave your desktop with Ctrl + Alt + F1
and go back with Ctrl + Alt + F7
.
Another example of a login shell is the connection via ssh
.
Lets configure some environment variables for the login shells as a system wide configuration.
# JDK 8 export export JAVA_HOME='/home/bakka/java/jdk1.8.0_65' (1) export PATH="$JAVA_HOME/bin:$PATH" (2)
-
The use of single quotation marks for
JAVA_HOME
causes interpolation to be suppressed! Only single quotation marks within the URL need be escaped. -
Double quotation marks in the second assignment allow interpolation.
Verify this global setting for login shells via the command sh -l -c 'printenv JAVA_HOME'
that should result in:
/home/bakka/java/jdk1.8.0_65
Ok that works, but what about the sub shells those have to derive the global setting from /etc/profile
?
We simple evaluate the /etc/profile
file and execute it in the current context with the source
command inside of .bashrc
that is called on each sub shell creation for the current user.
source /etc/profile
Check this result with echo $JAVA_HOME
that should return:
/home/bakka/java/jdk1.8.0_65
Note:
If .bashrc
does not exist in your home folder create one and make sure it is referenced in ~/.profile
like that:
# ~/.profile: executed by Bourne-compatible login shells. if [ "$BASH" ]; then if [ -f ~/.bashrc ]; then . ~/.bashrc fi fi
As an alternative define source /etc/profile
directly in ~/.profile
.
Current folder in bash prompt
Prompt shows only current directory in ubuntu-bash.
export PS1='\u@\h:\W$ '
Bash Scripting
Loops
Loop over files
Loop: for each file that end with jpg
rename the file to the current name with the prefix my.
for i in *.jpg; do mv "$i" "my.$i"; done
Loop in C
syntax
Loop: Creates directories in the range from 0..9
#!/bin/bash for ((i=0; i<10; i++)); do mkdir ${i}; done