Linux: for more information on many of the below commands/functions, see the respective man pages
-----
edit cron jobs:
sudo crontab -e
view cron jobs:
sudo crontab -l
md5sum --> generate hash of a file
vimtutor --> learn vim basics
host --> lookup website's IP address
debug in bash with -x and -xv
which shell am I using?
echo $SHELL
which desktop environment am I using?
echo $XDG_CURRENT_DESKTOP
or use screenfetch / neofetch
remove newlines from a file:
tr -d '\n' < file.txt
vim will let you look through AND EDIT the contents!
work with word lists and regexes:
find all three-letter words with no vowels:
egrep -i "^[^aeiouy']{3}$" /usr/share/dict/words
find all four-letter words that begin with p and end with l:
look p | egrep ^p..l$
file: determine file type
change shell (to bash, in this case):
chsh -s /bin/bash
sudo apt-get {update, dist-upgrade}
update will resync package index files
upgrade will install the newest versions of all packages & dist-upgrade will handle changing dependecies as well as do upgrade
lsb_release -a
will print distribution-specific information
search for R packages: // see http://cran.r-project.org/bin/linux/debian/
apt-cache search ^r-.*
install R:
sudo apt-get install r-base
screen: http://www.rackaid.com/blog/linux-screen-tutorial-and-how-to/
screen help
CTRL + A, then ?
new screen
CTRL + A, then c
switch between screens
CTRL + A, then n or p
detach
CTRL + A, then d
re-attach
screen -r
create a running log of the session
CTRL + A, then H
lock your screen
CTRL + A, then x
list running processes
ps aufx
remove html tags from text stream:
sed 's/<[^>]\+>//g'
See what shell you are running:
ps -p $$
print out some system info (CPU speed and temperature):
MHZ=$(cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq)
TEMPE=$(cat /sys/class/thermal/thermal_zone0/temp)
echo CPU Speed $(($MHZ/1000)) Mhz "|" CPU Temp $(($TEMPE/1000)) C
DNS resolver information: /etc/resolv.conf
User information: /etc/passwd
Run command on login and/or
make aliases for commands:
~/.bashrc (or .profile)
ex:
alias ll='ls -l'
Change a user's home directory:
usermod -d /path/to/new/homedir/ username
Generate a public/private key pair:
ssh-keygen -t dsa
Replace a String in Multiple Files in Linux Using Grep and Sed:
grep -rl matchstring somedir/ | xargs sed -i 's/string1/string2/g'
dpkg --get-selections // list installed packages
dpkg-query -l // also works; see https://wiki.debian.org/ListInstalledPackages
xkill = kill a program in linux
In Ubuntu, press Alt-F2 and then enter the following command: xkill
top = view running processes in linux
man = help
ctrl + alt + f1 = switch to full-screen terminal
ctrl + alt + f7 = switch back to GUI
install a .deb package: sudo dpkg -i packagename.deb
remove a .deb package: sudo dpkg -r packagename
df -h // This will output the usage of each partition in the server.
df -h --total // this will also output the TOTAL memory usage
du -sh /home/ // list the size of a specific directory
du -sh /home/* //list all the subdirectory sizes under /home
du --max-depth=1 -h / <-- this will show how much space folders are taking up, without recursing and printing out for each subfolder
# This will enter a full screen terminal called tty1:
ctl+alt+f1
# Then find the program you wanna kill: (ps -e lists them!)
ps -e | grep programname
# Then when you find the program name kill it:
killall programname
# Then go back to your display manager using terminal:
ctl+alt+f7
GParted and PartedMagic: http://distrowatch.com/weekly.php?issue=20070806
upload files to Dropbox using the Dropbox-Uploader script, available at https://github.com/andreafabrizi/Dropbox-Uploader
need to authorize root to use it, as well as any user(s), especially if you want to use it in a cronjob
Reset Windows password:
1. get chntpw -- run (sudo dpkg -i chntpw*) in a folder containing a .deb package
2. Mount Windows partition/harddrive
3. cd to /media/ and then to /WINDOWS/system32/config/
4. change admin password with (sudo chntpw SAM)
change user password with (sudo chntpw -u SAM)
USERS
-----
add a user
useradd USER
passwd USER
mkdir /home/USER
chown USER /home/USER
// change user
su - username
// verify it worked:
whoami
add user to sudoers:
sudo adduser paul sudo
modify sudoers file via visudo
username ALL=(ALL) ALL
make the user not have to enter password to run sudo with:
username ALL=(ALL:ALL) NOPASSWD:ALL
need .bashrc and ~/.profile
change hostname:
vi /etc/hostname
then run: hostname NEW_HOSTNAME
then run: hostname (to verify)
also change it via vi /etc/hosts
change user's home directory: // also see vi /etc/default/useradd
usermod -m -d /home/USER USER
change user's shell:
usermod -s /bin/bash USER
alternatively, run:
sudo chsh -s /bin/bash
// else change it in /etc/passwd
change user login
usermod -l login-name old-name
view user information:
id, finger
setting up Apache
-----------------
if a2ensite doesn't work for enabling sites-available, rename the file to *.conf
5 Deadly Linux Commands You Should Never Run, from http://www.maketecheasier.com/deadly-linux-commands/ (accessed 10/22/2014)
--------------------------------------------
Delete everything recursively:
rm -rf /
Fork bomb:
:(){ :|: & };:
Move contents of home folder to /dev/null:
mv ~ /dev/null
Format hard drive:
mkfs.ext3 /dev/sda
Output command to hard drive:
any-command > /dev/sda
Windows and/or Linux
--------------------
objdump -Dslx file
tracert, tracepath, and/or traceroute = tool in Windows/Linux for tracing the route taken to an IP address/URL
IRC
---
register a nick:
/msg NickServ register PASSWORD EMAIL_ADDRESS
only allow 30 seconds for password:
/msg NickServ SET ENFORCE ON
Nick yournick is temporarily unavailable:
/msg NickServ RELEASE yournick yourpassword
get info about a channel:
/msg ChanServ info ##channelname
register a channel:
/msg ChanServ register ##channelname
make yourself an operator of a channel:
/msg ChanServ op #channel yournick
get VERSION/client that someone is using (don't do too often!):
/ctcp VERSION
weechat
-------
enable channel list in left sidebar:
/script install buffers.pl
have it mark you as away and display a message about screen when you detach:
/script install screen_away.py
run shell commands within IRC:
/script install shell.py
/shell -o will pipe to IRC
/shell will not
irssi
-----
close a window:
/WINDOW CLOSE
git
---
change remote URL:
git remote set-url origin git://new.url.here
Windows
-------
nslookup --> lookup website's IP address
God Mode: Folder called GodMode.{ED7BA470-8E54-465E-825C-99712043E01C}
net statistics server / net stats srv --> get uptime
msconfig --> enable/disable startup programs
regedit --> edit the registry
resmon --> Resource Monitor (something like a more detailed Task Manager)
tasklist
taskkill (more info: http://forums.techarena.in/tips-tweaks/1161770.htm)
diskpart - list disk - select disk 2 - clean
right click on My Computer and click "Manage" - Disk partition management
Windows + L = lock computer
Excel: Alt+Enter = new line
Excel: drop down menus: Data>>Validation>>Settings
Excel: Array formulas (Control+Shift+Enter)
source: http://office.microsoft.com/en-us/excel-help/introducing-array-formulas-in-excel-HA001087290.aspx
Sysinternals tools: http://live.sysinternals.com/ or \\live.sysinternals.com\tools\
Process Idle Tasks (and potentially speed up your computer): http://buzzblogging.com/tweaks/how-to-clean-up-your-windows-xp-memory/
Start>>Run (or Windows Key + R) (or even from cmd)
%windir%\system32\rundll32.exe advapi32.dll,ProcessIdleTasks
remove items from right-click context menus:
regedit:
HKEY_CLASSES_ROOT\*\shellex\ ContextMenuHandlers
HKEY_CLASSES_ROOT\Directory\shellex\contextmenuhandlers
Add "Open Command Window in this Folder" to right-click context menu on folders:
Manual Method:
(This requires editing your registry. If you are not familiar with registry editing, this isn't for you, so skip to the easy method below)
1. Open regedit
2. Navigate to HKEY_LOCAL_MACHINE/Software/Classes/Folder/Shell
3. Create a new key called Command Prompt
4. Your default value should be Command Prompt Here
5. Create a new key called Command under the Command Prompt key
6. Your default value should be cmd.exe /k pushd %L
Your popup menu when you right click on a folder will now contain an option called
Command Prompt Here which will open a command prompt in the selected folder.
Source: http://www.tech-recipes.com/rx/232/right-click-to-open-a-command-prompt/
move windows (useful if they are stuck off screen):
Alt+Space R = Restore
Alt+Space X = Maximize
Alt+Space M = Move (can use arrow keys)
source: http://www.howtogeek.com/howto/windows/bring-misplaced-off-screen-windows-back-to-your-desktop-keyboard-trick/
Full screen cmd.exe in XP: Alt+Enter
source: http://www.windowsnetworking.com/articles_tutorials/windows-xp-keyboard-shortcuts.html
device manager: mmc devmgmt.msc
Javascript
----------
Wayback Machine bookmarklet (archive this! button): javascript:window.location="http://web.archive.org/web/*/"+window.location;
Harlem Shake in browser; works well on Wikipedia: javascript:(function(){function c(){var e=document.createElement("link");e.setAttribute("type","text/css");e.setAttribute("rel","stylesheet");e.setAttribute("href",f);e.setAttribute("class",l);document.body.appendChild(e)}function h(){var e=document.getElementsByClassName(l);for(var t=0;te&&s.heightt&&s.width=w&&t<=b+w}function S(){var e=document.createElement("audio");e.setAttribute("class",l);e.src=i;e.loop=false;e.addEventListener("canplay",function(){setTimeout(function(){x(k)},500);setTimeout(function(){N();p();for(var e=0;eIf you are reading this, it is because your browser does not support the audio element. We recommend that you get a new browser.
";document.body.appendChild(e);e.play()}function x(e){e.className+=" "+s+" "+o}function T(e){e.className+=" "+s+" "+u[Math.floor(Math.random()*u.length)]}function N(){var e=document.getElementsByClassName(s);var t=new RegExp("\\b"+s+"\\b");for(var n=0;n
...
...
...
...
HTML redirects:
...
...
Internet
--------
-inurl:htm -inurl:html intitle:"index of" mp3 "john lennon"