Title: Unix Crashcourse

Command: wc -b /etc/passwd
Effect: Count bytes in /etc/passwd

Command: cat input_file | wc -l
Effect: Count lines in input_file

Command: seq 20 2 40
Effect: Generate all even numbers between 20 and 40.

Command: ls | head -n 5
Effect: List first five files in the current directory.

Command: cat /etc/passwd | tail -n 20
Effect: Print last 20 lines of /etc/passwd file.

Command: ssh derp@derp.home.net
Effect: Login to remote machine derp.home.net with username derp.

Command: ssh derp:exposedpassword@derp.home.net:~ rm testfile
Effect: Login under username derp. (with specified password) to a remote machine derp.home.net and delete file called test_file in derp's home directory.
Watch out: specifying the password like this is a bad idea, using keys is a much better idea.

Command: who
Effect: Show who is logged on this machine.

Command: ls -l /etc
Effect: List detailed info about files and directories in /etc

Command: nl input_file > output_file
Effect: Number lines of input_file and redirect to output_file.

Command: cat input_file | tail -n +5
Effect: Print lines of input_file from line 5 till the end of the file. Use tail.

Command: cat input_file | head -n -13
Effect: Print lines of input_file with the exception of the last 13 lines. Use head.

Command: cat input_file | sort
Effect: Sort lines of input_file alphabetically in ascending order.

Command: cat input_file | sort -n
Effect: Sort lines of input_file numerically (interpreting initial number as a number, not as a text) in ascending order.

Command: pwd
Effect: Print name of current working directory.

Command: mkdir 'dir with spaces in name'
Effect: Create directory called "dir with spaces in name" (without the actual quotes).

Command: ls *.c > "list *.c"
Effect: Write names of all files ending with .c into a file called "list *.c" (without the actual quotes).

Command: cat input_file | sort -r
Effect: Sort lines of input_file alphabetically in descending order.

Command: cd ..
Effect: Change current working directory to parent directory.

Command: cd
Effect: Change the current working directory to the home directory.

Command: cat input_file1 input_file2
Effect: Print the content of input_file1 followed by content of input_file2 .

Command: man vim
Effect: Open manual page for command vim.

Command: man -k printf
Effect: Look for the printf keyword in manual pages.

Front: Unix Philosophy
Back: Building minimalist, modular software. Favor composability as opposed to monolithic design.
Learn More

Front: Relative path
Back: A file or directory location relative to where we currently are in the file system.
cd ../tmp

Front: Absolute path
Back: A file or directory location in relation to the root of the file system.
cd /home/derp

Front: Unix is case sensitive.
Back: Beware of silly typos. "cd /etc" != "cd /ETC"

Front: Command line options
Back: Almost all commands have many useful command line options. Make sure you skim the man page for new commands so you are familiar with what they can do and what is available.

Command: file input_file
Effect: Determine the file type of input_file based on its content.

Command: rmdir dir_name
Effect: Remove directory dir_name, but only if it is empty.

Command: rm filename
Effect: Remove file filename.

Command: rm -r filename_or_dir
Effect: Remove file_or_dir. If it is a directory, remove its content recursively first.

Command: rm -i filename
Effect: Remove filename, asking for confirmation.

Command: rm -f filename
Effect: Force remove filename, not asking for confirmation even for write-protected files.

Command: seq 10 > filename
Effect: Redirect output of command seq 10 to filename. If the file already exists, it is overwritten.

Command: echo more stuff >> filename
Effect: Append "more stuff" to the end of filename. If the file does not exist, it is created first.
The append should be atomic under POSIX-compliant system, given that the size of data appended is reasonably small. The limiting buffersize (PIPE_BUF) depends on filename and system (commonly 1024B or 4096B).

Command: wc -w < filename
Effect: Count words in input. The input to wc is read (redirected) from filename.
Compare with wc -w filename

Command: echo *[0-9]*
Effect: Wildcards: print filenames which contain a number (excluding hidden files).

Command: echo *.???
Effect: Wildcards: print filenames with a three-letter extension (excluding hidden files).

Command: echo .*a *a
Effect: Wildcards: print filenames ending with an "a" (including hidden files).

Command: ln source_fn dest_fn
Effect: Make hard link from source_fn to dest_fn.

Command: ln -s source_fn dest_fn
Effect: Make soft link (symbolic link) from source_fn to dest_fn.

Command: touch .filename
Effect: Create empty hidden file named .filename.

Command: ls -la
Effect: List details of all hidden files in the current directory.

Command: ls -lt
Effect: List details of all files in the current directory, entries sorted by the modification time, newest first.

Command: chmod +r filename
Effect: Add rights to read content of filename to all users.

Command: chmod 700 filename
Effect: Change rights of filename, s.t. owner can read, write and execute, but nobody else can do anything. Octal notation.

Command: uname -n
Effect: Print the computer's network hostname. (Alternatively, you can use non-standard hostname command.)

Front: POSIX
Back: Portable Operating System Interface – a family of standards specified by the IEEE for maintaining compatibility between operating systems. POSIX defines the application programming interface (API), command line shells and utility interfaces.
Posix @ wiki
POSIX.1-2008 specification (contains e.g. list of utilities and standard options).

Front: shell PATH variable
Back: Shell looks for executables in directories specified by standard (colon delimited) variable PATH. Some commands might be available as a shell built-in and need not be present in PATH directories.

Command: which vim
Effect: Prints location of vim executable file, looking through directories specified in the PATH variable.

Front: rc files
Back: Naming convention for (mostly hidden) initialization files of many apps/scripts. For instance, bash initialization file is called .bashrc, is usually located in $HOME and contains commands to be run on start of bash shell.
The name is probably a shortcut for "run commands".

Command: cat input_file | grep 'blue$'
Effect: Print only those lines of input_file which contain word blue at the very end.

Command: cat input_file | grep '^Sir'
Effect: Print only those lines of input_file which contain word Sir at the very beginning.

Command: cat /etc/passwd | cut -d ':' -f 5
Effect: Print column with names (fifth one) from the colon-delimited file /etc/passwd

Command: cat input_file | grep house
Effect: Print only those lines of input_file, which contain word house somewhere.

Command: cat input_file | grep -v nope
Effect: Print only those lines of input_file which do not contain word nope