Linux
Published: 05:45, Friday 08 July 2011
All I know about linux (or almost).
Except for some early attempts, I started using linux in fall 2011. There's so much to learn from this beautiful os, and I've been taking notes about it almost continuously - unfortunately not from the very beginning, as my notetaking habit developed together with my knowledge of how to do it effectively with my pc. Maybe here you will find something of use to you.
Notes
What's this? See my article about Notes.
View as plain text file.
drivers
hardware abstraction layer (hal):
lshal
open terminal from nautilus: sudo aptitude install nautilus-open-terminal
irc
irssi
[[/connect]] irc.freenode.org
[[/join]] #nickpiace
talk
terminal on top at startup:
wmctrl -r [[:ACTIVE:]] -b add,above
get mouse position and other stuff:
xdotool
pipes:
redirect output to file:
>=save,>>=append
1=stdout,2=stderr,&=both
silence:
&> /dev/null
pipe
to programs as stdin with |
named pipe: mkfifo name
stdin to first arg: cmd1 | xargs cmd2
ascii
.Xdefaults
xrdb ~/.Xdefaults
default terminal emulator: sudo update-alternatives --config x-terminal-emulator and System->Preferences->Preferred Applications
other keybindings: gconf-editor
window manager
processes:
fg
ps ax
mv/move/rename:
match and replace:
mmv "file*.asd" "file#1_old.asd"
rm/remove:
remove files recursively
Switch Esc and Caps Lock:
System->preferences->keyboard->dispositions->options...->...
not needed code:
remove Lock = Caps_Lock
keysym Escape = Caps_Lock
keysym Caps_Lock = Escape
add Lock = Caps_Lock
custom x session:
https://wiki.ubuntu.com/CustomXSession
check ubuntu possibilities first!
archives:
tar:
extract
tar xvf archive.tar
list contents: t
extract: x
use archive file: f
verbose: v
archive: tar -zcf archive.tar.gz file1 file2
zip:
current dir: zip -r asd.zip
file: zip name.zip filename
unzip: unzip file -d dir
rar:
extract: unrar e file.rar
install with rpm
use alien (apt-get it)
sudo alien -k rpmfile.rpm
bash:
output of a command in string: ...`cmd`...
man bash is cool
terminal settings: .bashrc
#! /bin/bash
set -e
export
if [ $UID -ne 0 ]; then
if [ "$1" = "asd" ]; then
a=$b without spaces!
arguments
$1, ...
called file name: @0
all the args: $@
read user input:
read -p "Var: " varname
password
stty -echo; read -p "Enter password: " pass; echo; stty echo
iterate over all file lines:
while read line; do echo "$line"; done < "$filename"
while read line; do echo "$line"; done < fname
get extension: extension=${filename##*.}
get filename: filename=${filename%.*}
time:
date
timestamp: date +%s
[[/etc/sudoers]]
Defaults !env_reset
Defaults env_keep+="PROG_LOCATION"
save cmd result to var:
asd=$(cmd)
dialog
input=$(zenity --text "Question" --entry)
retval=$?
case $retval in
0)
1)
launch and hold: konsole -hold -e cmd
exit on error: set -e
location of cmd: which cmd
remove except/remove all except one file: rm !(filename)
shopt ?
command line browsing/browser: lynx elinks
grep
egrep
search in files
grep "str" *
show only files: -l
search file
locate term
sudo updatedb
search file: find . -name term
compare files: diff
copy to clipboard: e.g. cat filename | xclip -sel clip
paste to file: xclip -o > file
empty file: > file
echo/print from stdin: cat
download from commandline: wget url
mounted:
see space usage: df
/mnt
available: /dev/sda**
mount /dev/sda*** /mnt/***
format:
fat is bad
ext4
filesystem standard hierarchy/fhs/linux directories:
/bin: binaries available in single user mode
/boot: boot loaders
/dev: devices
/etc
config files
/etc/init.d/: start/stop/restart/... scripts for services as apache2
/etc/opt: config files for opt
/etc/X11 etc/sgml etc/xml
/home: users' saved files, personal settings
/lib: libraries for bin and sbin
/media: mount points for removable media
/mnt: temporary mounted filesystems
/opt: optional application software packages
/proc: virtual filesystem for kernel and process status as text files!
/root: home for root user
/sbin: system binaries
/srv: site-specific data (?)
/tmp: not preserved by sys reboots
/usr
read-only user data
/usr/bin: binaries not needed in single user mode
/usr/include: include files
/usr/lib: libraries for usr/bin and /usr/sbin
/usr/share: shared data ?
/usr/src: kernel source code with header files
/usr/X11R6
/usr/local
/var
variable files - change during system operation
/var/cache: application cache data
/var/lib: state information
/var/lock: keep track of resources in use
/var/log: log files
/var/mail: user's mailboxes
/var/run: info about running system
/var/spool: tasks ?
/var/tmp: temporary, preserved betw reboots
apt-get:
sometimes purge is better than remove
startup at boot programs/services:
etc/rc2.d contains something (but also /etc/init.d/)
used sudo mv{S,K}91apache2 to not let it start at boot
take a look at update-rc.d
to add sth:
in /etc/rc.d/rc3.d or 2?
ln -s ../init.d/httpd S80httpd or stuff
create symbolic link/symlinks
ln -s file link
unlink symbolic links
unlink all symlinks in a dir: unln -rR
media:
audio editint: audacity
video editing: avidemux
video to audio:
mp4 to mp3:
ffmpeg -i input.mp4 output.mp3
ffmpeg -i input.mp4 -acodec copy -vn output.mp3
tried once and didn't work
soundconverter -b filename.mp4
tried once and took too long
images
view: eog
convert:
to png: pnmtopng from > to
compress:
convert -resize 10%x10% from to
a4 at 300 dpi: 2480x3508
at 600 dpi: 4960x7016
at 71 dpi (web): 595 x 842
pdf:
convert to pdf:
ppt2pdf (my script)
images to pdf:
convert *.png out.pdf
merge
pdftk 1.pdf 2.pdf 3.pdf cat output 123.pdf
gui: pdfsam
extract images: pdfimages -j document.pdf imgprefix
extract pages
pdftk A=100p-inputfile.pdf cat A22-36 output outfile_p22-p36.pdf
split into single pages: pdftk input.pdf burst
scan:
my scripts:
scan
scanpdf
other stuff:
scanimage > name.pnm
scanimage -L
scans to image.pnm
gui: xsane
mount harddisks:
mkdir in /mnt
mount /dev/sdax /mnt/dir
filesystem
mount shows
ext4: 16TiB
speak: espeak "Oh my god this is so crazy" -s 20
killall: kill all processes with name
dati pc/info pc/list hardware: sudo lshw
change user/switch user: su uname
command not found:
command-not-found package
/usr/lib/command-not-found
included via /etc/bash.bashrc
file transfer protocol/ftp:
use pftp (passive)
passive mode: -p
fireftp
get all: mget *
wget -r ftp://user:pass@server.com/
ncftp
lftp
open, user
bash command: !
lcd
download: mirror . .
upload: mirror -R . .
prompt
/etc/promptrc
ps1
kernel version
uname -r
log:
sudo vi /var/log/messages +
dmesg - kernel message buffer
uname - name, version, details of machine and os
ssh:
generating rsa key:
ssh-keygen -t rsa -C "comment"
share:
cat ~/.ssh/id_rsa.pub | xclip -sel clip
paste
login/connect
ssh username@server.com
yes and passphrase
if successfully auth: ok
ssh-agent: to make it work: ssh-add
ethz:
ssh mnicola@optimus.ethz.ch
ssh mnicola@slab1.ethz.ch (bis 8)
man landet in /nas/mnicola
logged user:
in /nas all current users, or command w
w to see user information
write works :)
sshd
add user: adduser name
sed:
replace in file/substitute in file
sed s/day/night/ old > new
use & as matched
\1 for part matched by ()
/g global, /2 second occurrence
-n prints only /p
delete d
quit q
combine with -e
-f sedscript
one command per line
parameters:
's/asdasd'"$1"'asdasdf/'
calculator: bc
see folder size/directory size:
du -hs dir
calendar:
cal
pal
timer/countdown: timer-applet
linux on browser: http://bellard.org/jslinux/
watch/regular/repeat
watch command
watch -n interval command
mkfifo debug; while [ 1 ]; do cat debug; done;
add to path:
export PATH=$PATH:newpath
on file change/inotify
bash: incron
/etc/incron.conf
/etc/incron.d
/var/spool/incron
incrontab
sudo service incron start
<path> <mask> <command>
wildcards
$$
$@ watched filesystem path
$# event-r
elated file name
$% event flags (textually)
$& event flags (numerically)
example:
/var/mail IN_CLOSE_WRITE abc $@/$#
media player
cmus
1: library, 2: sorted library 3: playlist, 4: play queue 5: browser, 6: filter
e: append to queue, E: prepend to queue
b: next, c: pause, x: play, z: prev, v: stop
s: shuffle/scramble/random
empty: :clear
move element: p/P
restart: vx r: toggle repeat o: toggle sorted
file operations: D: delete,
^R: toggle repeat current
q: quit, :w file save current view's contents to a playlist
search with / and n
volume: []
play mp4:
I got there in this order (very probably not everything is needed ;))
just trying around:
sudo apt-get install moc mmpeg moc-ffmpeg-plugin xmms2
ubuntu-restricted-extras
added medibuntu: http://medibuntu.org/repository.php
installed libavformat-extra52
worked:
uninstall cmus, remove ~/.cmus (I didn't have any important data there yet!)
downloaded source: http://cmus.sourceforge.net/#download
sudo apt-get install libncursesw5-dev libpulse-dev libalsaplayer-dev libavformat-dev alsa-source libasound2-dev mp4h flac libflac-dev libmad0-dev libvorbis-dev libfaad-dev
install mp4v2
untar, ./config, make, make install
./configure CONFIG_FLAC=y CONFIG_MAD=y CONFIG_VORBIS=y CONFIG_WAV=y CONFIG_MP4=y CONFIG_AAC=y CONFIG_ALSA=y
make
make install
screen:
detach C-a-d
screen -ls
screen -r
samba/smb: to see eachother's public dirs, imitates windows network stuff
skype:
didn't start
install from website
mime types: see [[php#headers]]
send sms from pc
connect to a phone or a gsm/gprs modem
at commands: cmgs, cmss, cmgw, cmgd, cmgc, cmms
chose the desktop folder
http://www.linux-geek.co.nz/2011/06/03/use-any-folder-for-your-ubuntu-desktop-even-a-dropbox-folder/
~/.config/user-dirs.dirs
now the home folder is my desktop folder :)
hex/dec:
echo $((0x15a))
printf '%x\n' 346
Write a Comment
* These fields are mandatory.