Contents

Startup

GRUB: hold shift key down as soon as bios loads

/etc/default/grub //for grub settings - tried adding vga=0x0369 to this file to fix boot issues and it hasn't worked.  
sudo update-grub // after making any changes to /etc/default/grub - writes to /boot/grub/grub.cfg  

Non-Upstart

For non-upstart services:
sudo update-rc.d tomcat6 enable 2 //changes symlink in /etc/rc2.d/ from K08tomcat6 to S92tomcat6
sudo update-rc.d tomcat6 disable 2 //changes symlink in /etc/rc2.d/ from S92tomcat6 to K08tomcat6
For upstart services:

ls /etc/init/*.conf // lists all upstart services  
/etc/gdm/Init/Default //this is where you 'can' put some xrandr to apply on startup  
/etc/init.d //this folder has start-up scripts  
/etc/default //this folder has default values  

Upstart

initctl list //lists all services with status   
service --status-all //same as 'ls /etc/init.d'   
start/stop/restart/status <service> // same as initctl start/stop/restart/status <service>  
halt/poweroff/shutdown/reboot  
shutdown -r -t 20 now // shutdown in 20s with warning now and reboot
last reboot //info on previous few reboots
halt -p // when halting the system switch off the power  
/etc/init/mysql.override //edit to contain word 'manual' to override startup instructions in mysql.conf - same for all other startup services  
added cups.override, mysql.override, ssh.override, smbd.override to override startup instructions in respective /etc/init/*.conf files  

Kernel upgrade

wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v4.4.140/linux-headers-4.4.140-0404140_4.4.140-0404140.201807111137_all.deb 
wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v4.4.140/linux-headers-4.4.140-0404140-generic_4.4.140-0404140.201807111137_amd64.deb 
wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v4.4.140/linux-image-4.4.140-0404140-generic_4.4.140-0404140.201807111137_amd64.deb 
sudo dpkg -i *.deb

Reboot

USER/PASSWORD/ADMIN

/etc/passwd /etc/groups /etc/shadow
/etc/default/useradd // default settings for new user
echo $PATH  
export PATH = $PATH:/new_path/to_add/  
sudo adduser chetan  
sudo usermod -g users chetan  
sudo usermod -s /bin/bash chetan
sudo passwd chetan // prompts for new password
stat chetan  
chmod 0700 chetan/  // rwx------  
chmod u+x <filename> // add exec right to current user

INSTALLTION/REPOSITORIES

/etc/apt/sources.list or /etc/apt/sources.list.d/* //repository list  
sudo add-apt-repository ppa:<repo path>  
/home/sridhar/.local/share/Trash // Rubbish  
update-alternatives --config java //then choose number from list  
apt-get --simulate purge popularity-contest //remove popularity-contest and related packages altogether   
apt list --upgradable
apt-get autoremove --purge // removes old kernels from boot partition to free up disk space
apt-cache search killall
apt-get install psmisc // for killall
dpkg -c/i/l/L/r/s  // package manager view contents/install/list/file locations/remove/installed?
dpkg -S /usr/bin/gcc // outputs which package provides a binary
dpkg --status tzdata|grep Provides|cut -f2 -d'-'
vgdisplay // volume groups
pvdisplay // physical volumes
lvresize -r -L -20G /dev/mapper/home
lvextend -r -L +20G /dev/mapper/root
lsblk -a /dev/sda // lists blocks on hd

NETWORK

arp -a // find mac address of router  
ifconfig  
/etc/network/interfaces  
ifdown  
ifup  
iptables  
kill -9 pid //find pid of open tcp/udp connection using netstat -atp  
netstat -at //list all tcp connections -au //udp  -ax //unix  -ar //raw   
nmap -v -sS localhost //half-open scanning of localhost  
nmap -v -sS 192.168.0.0/24 //half-open scanning of local network  
traceroute <host>  
ufw default deny   
ufw enable  

MEMORY

cat /proc/sys/kernel/threads-max //=62274  
cat /proc/sys/fs/file_max //=401408  
cat /proc/mdstats  
du -h | cut -f1 | sort -h | uniq -c | sort -rn | head  //du recursively lists directory and file sizes
df -h //lists all partitions
top // lists cpu util
ulimit -v //for virtual = unlimited  
ulimit -s //for stack = 8192  

SHORTCUTS

Alt-F2 //type xkill and click on hung app  
Alt-F4 //closes window
Ctrl-Alt-F1 // go to virtual terminal - can do sudo reboot from there  
.bash_aliases  
alias ssh1='ssh 192.168.0.133'   
alias grepxsvn='grep -r --exclude=*.svn-base'  
alias grephtml='grep -r --include=*.html'  

UTILITIES

> // redirects
>& // redirect stream to another file descriptor
0 stdin, 1 stdout, 2 stderr // sample file descriptors
echo doofus > filename // redirect "doofus" into filename. same as ..
echo doofus 1> filename // same as above
echo doofus 1>&2 // redirect stdout to stderr
echo doofus 2>&1 // or vice versa
. ./.profile  //sources profile file without restart   
acpi -V // battery status   
aplay -L //list of available cards and devices
apropos -s 1 compare OR apropos "compare" //searches man files for keyword or string
arch  // possible output is i686 (32 bit) or x86_64 (64 bit)    
chmod o=rx dir/ OR u=rwx dir/ OR g=rx dir/  
chown -R sridhar dir/   
chgrp -R sridhar dir/   
convert -delay 5 -loop 0 *.jpg pp.gif //gif creation
cp -r source_dir/ target_dir/  
cron // user crontabs in /var/spool/cron/crontabs
curl 'http://www.gnu.org/software/coreutils/manual/coreutils.html' 2>/dev/null |  
    grep 'h3 class' |  
    grep 'class="command"' |  
    sed 's/.*class="command">//' |  
    sed 's|</span></samp>||' |  
    sed 's|</h3>||' |  
    grep ':' |  
    sort  
date -d "@4294967295" // Sun  7 Feb 06:28:15 GMT 2106
dmesg  //print kernel ring buffer - can be used for boot up message  
dpkg-reconfigure popularity-contest  //can toggle whether package usage data is sent to debian  
dpkg --add-architecture i386 //allows 32 bit applications to be installed/run
exec -l $SHELL   //restarts shell  
fdisk -l //list all partitions  
find /path -name file_name -type d/f  
find ./ -type f -name \*.class -exec rm -rf {} \;            // remove all files recursively named \*.class under ./  
find ./ -type f -name \*.class -exec grep -H "string" {} \+  // search for string in files recursively named \*.class under ./ (multi-threaded)  
find ./ -type f -name \*.class -print0 | xargs -0 -n1 -P8 grep -H "string" //search for string in files recursively named \*.class under ./ use xargs  
find . -name '\*.c' | sort | xargs head -1  
find ./ -type d -newer ~/docs/temp/timestamp -exec rm -rf {} \;  // remove directories newer than timestamp
find ./ -type d ! -newer ~/docs/temp/timestamp -exec rm -rf {} \;  // remove directories older than timestamp
find -L / -maxdepth 2 -samefile /run/systemd/resolve/resolv.conf // -L follows symlinks to a maxdepth of 2 and finds symlinks which are the same as provided filename
grep -r search_term dir/  
grep . /sys/devices/system/cpu/vulnerabilities/\* 
grep -r --exclude-dir={examples,docs} search_term
gstreamer-properties //multi-media settings  
gunzip < coreutils-8.13.tar.gz | tar -vx  
history 
!25 // runs historical command #25
!-4 // runs 4th previous command
locate  
ls -a (include hidden) -F (dirs with trailing / and exes with trailing \*) -l (long listing) -t (sort by time modified) -R (all subdirs)  --full-time (show year)
ls -1 | wc -l  //counts the number of line entries in ls command   
find . -type f -exec ls -lrt {} + // lists files only - latest modified at bottom
ldconfig -p | grep libgdiplus
lspci -v   
lsb_release -rd  
lsof -i -n -P //list all open files & ports   
lsof -i tcp:8888 /// lists services running on 8888   
lsusb //list usb devices  
ps -ef //list all running processes  
rename -n 's/old/new/' \*.jpg //bulk rename
rm -rf ./dir  ///// for dirs with special chars in name  
rsync -anv ./dir sridhar@192.168.0.9:/home/sridhar/dev   //simulate  
rsync -az ./dir sridhar@192.168.0.9:/home/sridhar/dev     //do it for real using compression  
rsync -a --exclude=pattern_to_exclude ./dir sridhar@192.168.0.9:/home/sridhar/dev     //do it for real  
scp -C sridhar@192.168.1.72:/usr/local/bin/iptables /usrlocal/bin/iptables    // need to 'sudo start ssh' on server before trying to connect, always use -C to enable compression
ssh -C 192.168.1.72 -l sridhar   // ssh on port 22 (tcp)  always use -C to enable compression
ssh -C sridhar@192.168.1.72   // ssh on port 22 (tcp)  always use -C to enable compression
screen ctrl-a then c for new terminal. ctrl-a, 0 or 1 to toggle between terminal // not used much since byobu  
speaker-test -Dsysdefault:Intel -c 6 // tests 6 audio channels only first two of which are generally used
stty -echo // turn off terminal echo
stty echo // turn it back on
tail <file> //lists last few entires in file  
tar -xvzf file.tar.gz  
tar xfJ scala-docs-2.10.2.txz  
tar -zvcf file.tar.gz directory/      //compress directory into file.tar.gz  
tee <output_file> //reads from std input and writes to std output and to the named file
time ./program //real: real time, user: how long program was running on cpu, sys: how long the program was waiting for os to perform tasks for it  
touch -t 201607010000 ~/docs/temp/timestamp
uname -a     // 32 or 64 bit i686 is 32 bit, x86_64 is 64 bit  
uname -r // prints kernel version
unrar e file.rar  
wget 'http://ftp.gnu.org/gnu/coreutils/coreutils-8.13.tar.gz'  
whereis  
xxd //make hexdump or reverse hexdump  
xrandr //used to set size, orientation and output for screens  

Filesystem

filenames with space : escape with \ filenames with & or ( or ) : enclose in 'filename'

Applications

evince file.pdf  
ffmpeg -f gif -i 585.gif 585.mp4 //converts gif to mp4
ffmpeg -i 585.mp4 -i 585.mp3 -codec copy -shortest output.mp4 //adds music to mp4
pdftk in.pdf cat 1-12 14-end output out1.pdf //removes page 13  
pdftk in.pdf cat 1E output out1.pdf //rotates p1 anti-clockwise  
pdftk A=in1.pdf B=in2.pdf cat A1-12 B3 A14-end output out1.pdf //add p3(B) after p12(A) & remove page 13(A)  
pdftohtml file.pdf  //saves html as file.html // lynx file.pdf does the same thing  
pdftotext file.pdf //saves text as file.txt  
printf '%x\n' 85  // prints 85 in hex
display boy.jpg // imagemagick command line tool  
enscript -p foo.ps foo.txt  
ghostscript: ps2pdf foo.ps, pdf2ps foo.pdf  
texi2pdf file.tex  

Ubuntu One

u1sdtool --help  
u1sdtool --list-folders  
u1sdtool --waiting  
u1sdtool --current-transfers  

Byobu

F9 for menu  
F12 escape  
byobu-ctrl-a to change behaviour of ctrl-a  
developed in python  

Wacom

sudo add-apt-repository ppa:lekensteyn/wacom-tablet  
sudo apt-get update  
sudo apt-get install dkms wacom-dkms  

References