unix kernel is loaded (resides in root partition of system -> /boot/vmlinuz
init process starts first (is parent of all other processes)
$ ls foo bar baz
$ rm ba? $ ls foo
Commands are similar to emacs:
Ctrl-a Move to the start of the line.
Ctrl-e Move to the end of the line.
Alt-] x Moves the cursor forward to the next occurrence of x.
Alt-Ctrl-] x Moves the cursor backwards to the previous occurrence of x.
Ctrl-u Delete from the cursor to the beginning of the line.
Ctrl-k Delete from the cursor to the end of the line.
Ctrl-w Delete from the cursor to the start of the word.
Ctrl-y Pastes text from the clipboard.
Ctrl-l Clear the screen leaving the current line at the top of the screen.
Ctrl-x Ctrl-u Undo the last changes. Ctrl-_
Alt-r Undo all changes to the line.
Alt-Ctrl-e Expand command line.
Ctrl-r Incremental reverse search of history.
Alt-p Non-incremental reverse search of history.
!! Execute last command in history
!abc Execute last command in history beginning with abc
!n Execute nth command in history
^abc^xyz Replace first occurrence of abc with xyz in last command and execute it
starting with the root directory, look for the file containing the string fname:
find / -name {*fname*}
look in current directory for T.java:
find . -name T.java
look for files ending in .conf in the /etc folder:
find /etc -name '*conf'
quotes keep shell from expanding wildcards:
find . -not -name '*.java' -maxdepth 4
find files:
find . -type f
find directories:
find . -type d
find links:
find . -type l
changed within a day:
find . -mtime -1
changed within 15 minutes:
find . -mmin -15
compare to filea:
find . -newer foo.txt
compare to date:
find . -type f -newermt '2010-01-01'
find file between dates:
find . -type f -newermt '2010-01-01' ! -newermt '2010-06-01'
find via permissions:
find . -perm 644
find . -perm -ug=w
find via permissions:
find . -size -1k
find with size more than 100MB:
find . -size +100M
Lookup “AccessFileName .htaccess”:
grep -n "AccessFileName .htaccess" /etc/httpd/conf/http.conf
search command history:
history | grep http_load
search Bananamans home folder recursively and case-insensitively for all files containing “superted”.:
$ grep -iR "superted" /home/bananaman/
search the file Skeletor.txt for lines containing “Panthro” (case-sensitive).:
$ grep "Panthro" Skeletor.txt
replace all instances of “Superman” with “Batman” in SuperheroLeagueTable.csv and output.:
$ sed 's/Superman/Batman/g' SuperheroLeagueTable.csv
Output the 15th line of BabyGotBack.txt.:
$ awk 'NR==15' BabyGotBack.txt
search for word matches and display the line number:
grep -nr 'new Foo()' src
search for term foo and surrounding lines:
grep -r -C 2 foo src
show any of the last 10 lines of error_log with “badscript.php” in them, and watch the file for new lines with “badscript.php” in them.:
tail -f error_log | grep "badscript.php"
List just the sizes of all files in a folder.:
ls -al | awk '{print $5}'
list files in a folder and replace “123” with “456” in their names.:
$ ls | sed 's/123/456/g'
show free space on the /dev/sda1 drive.:
$ df | grep "/dev/sda1" | awk '{print $4}'
output the third item on the third line of vmstat (the amount of virtual memory in use).:
$ vmstat | awk 'NR==3' | awk '{print $3}'
list all files in a directory with their attributes, reduce that list to just their names, filter for just those containing “Holiday” and, for those, just show their file extensions (yes, a hugely contrived example).:
$ ls -al | awk '{print $8}' | grep "Holiday" | sed 's/^[^.]*\.//g'
Alt (AKA META)
Alt-< Move to beginning of file Alt-> Move to end of file
Ctrl-v Move forward one page (screen full) Alt-v Move back one screen Ctrl-l Centers screen around cursor
Ctrl-a Move to beginning of line Ctrl-e Move to end of line Alt-a Move to beginning of sentence Alt-e Move to end of sentence
Ctrl-f Move cursor right Ctrl-b Move Cursor left Ctrl-p Move Cursor up Ctrl-n Move Cursor down Alt-f Move cursor right (by word) Alt-b Move Cursor left (by word)
Ctrl-d Backspace/Delete Ctrl-k rm all text on a line Ctrl-y brings back removed text Ctrl-x u Undo
Ctrl-x Ctrl-f Find a file Opens new file Ctrl-x Ctrl-f Ctrl-g Cancels minbuffer Ctrl-x Ctrl-s Save File
remove program and configuration files associated with it:
sudo apt-get remove --purge <program>
install latest version of every package, and new dependencies:
sudo apt-get dist-upgrade
remove packages (not programs):
sudo apt-get clean
remove only older packages:
sudo apt-get autoclean
remove package and dependencies:
sudo aptitude purge <program>
remove dependencies from old uninstalls, no longer needed:
sudo apt-get autoremove
Quake pull down menu:
# apt-get install konsole yakuake
Merge pdf’s:
gs -dNOPAUSE -sDEVICE=pdfwrite -sOUTPUTFILE=out.pdf -dBATCH file1.pdf file2.pdf
Use Ubuntu keychain for ssh logins?:
[cmd] apt-get update && apt-get install keychain
[cmd] ssh-keygen -t rsa
edit $HOME/.bash_profile
add this code:
### START-Keychain ###
# Let re-use ssh-agent and/or gpg-agent between logins
/usr/bin/keychain $HOME/.ssh/id_dsa
source $HOME/.keychain/$HOSTNAME-sh
### End-Keychain ###
sudo apt-get install apache2
sudo apt-get install php5 libapache2-mod-php5
sudo /etc/init.d/apache2 restart
sudo apt-get install mysql-server
sudo apt-get install libapache2-mod-auth-mysql php5-mysql phpmyadmin
gksudo gedit /etc/php5/apache2/php.ini
[Change] ;extension=mysql.so
[To ] extension=mysql.so
sudo /etc/init.d/apache2 restart
sudo ln -s /usr/share/phpmyadmin/ /var/www/phpmyadmin
sudo apt-get install php5-curl
sudo /etc/init.d/apache2 restart
replaces rn with n:
sed 's/.$//' winfile > unixfile
replaces n with rn:
sed 's/$/\r/' unixfile > winfile
trims leading whitespace:
sed -i 's/^[ \t]*//' t.txt
trims trailing whitespace:
sed -i 's/[ \t]*$//' t.txt
trims leading and trailing whitespace:
sed -i 's/^[ \t]*//;s/[ \t]*$//' t.txt
delete’s blank lines:
sed '/^$/ d' file
c = create x = extract z = .gz f = force (not sure why this is needed, but fails without it)
tar xzf <folder.tar.gz> tar czf folder.tar.gz folder