From personal use - Windows - Scripting - Bash - Awk - Distributions - Debian - Configuration management software - To explore - See also
This page is a quick references for common problems I had and the quick fix to move on. There is no complex script here, check instead shell_scripts for an attempt at structuring the small scripts I use often and thus try to maintain.
From personal use
- inotifywait from the inotify-tools package
inotifywait -m /data/ -e modify | while read path action file; do date +%s >> /tmp/modified; done
- adding
-e create
can result in 2 events being fired, 1 for file creation then another for modification
- prefer instead
-e close_write
- filename accessible as
$file
- works through Docker volumes
- multiple ssh servers on 1 IP while keep strict checking
- vinagre as VNC client
vinagre IP:port
- if password saved and keyring working goes straight to the remote computer
- used tightvnc server side (~5min setup making sure the computer is in the DMZ)
- Nautilus mount points on Ubuntu 15+
/run/user/...UID.../gvfs/...
- useful to run scripts
- rsync
-i
to only shown uploaded files and why
- copy content from terminal
- echo content | xclip -selection c
- toggle touchpad
- test 0 -eq `synclient | grep TouchpadOff | sed "s/.*\(.\)$/\1/"` && synclient TouchPadOff=1 || synclient TouchPadOff=0
^ : Control key
meta : Alt key
- Bluetooth audio headset
find . -iname "*PaTtErN*"
- look for a filename containing either pattern or PATTERN, etc
~/.ssh/config
- Security
- cdrecord/dvd+rw-format/dvd+rw-mediainfo/mkisofs
- man:xargs e.g. used to handle list of URLs with the rtmpdump script
- backup with relative path and checksum
- DATE=$(date +%F-%HH%M) && tar -C /home/user/path/data/ -cvf ~/place/to/share/backup.${DATE}.tar . && md5sum ~/place/to/share/backup.${DATE}.tar > ~/place/to/share/backup.${DATE}.tar.md5
- this should be put within a script and in crontab
reset
: reset the display of the current terminal, useful when you receive data that mess up the display
- command-line calculations using bc by Rob Newcater, Basically Tech 2006
- using SSH for tunneling
- man:ssh and man:sshd
- see Censorship#DIY to tunnel your way out (get)
-R
on ssh and GatewayPorts yes
on sshd to tunnel your way in (share)
- Breaking Firewalls with OpenSSH and PuTTY Mike Chirico
ssh me@server.tld -R binding_address.tld:remoteport:127.0.0.1:443 -N
- ideally you would share an encrypted protocol else anybody monitoring the client to your shared service will be able to record the content
- consider Lighttpd/Apache mod_proxy or CGI to convert the specific port to a proper URL
- PATH=$PATH:~/bin/ && export PATH
- most terminals and some apps
- ^T : transpose_characters
- note that those text edits are coherent with irssi (cf Irssi)
- ^K : erase_to_end_of_line
- meta-b : backward_word
- meta-f : forward_word
- meta-d : delete_next_word
- meta-Delete : delete_previous_word
- ^R : history search
- man : help for most available commands
- apropos : find the command that does what you want to do
- locate : find files listed thanks to updatedb
- cd - : go back to the last changed directory
- env : ...
- encapsulate through pipes (thanks to sed)
- grep term ~/file | sed "s/$/<br \/>/" | sed "$ s/^/<html>/" | tac | sed "$ s/$/<\/html>/" > ~/web/mypaths/myfile.html
Windows cmd.exe shell
- cygwin/mingw
- notes on path (e.g. interpreter like ruby, no probleme with java paths, ...)
- MingW system variables are available as $UP not%UP%
sc delete
servicename : remove the service
- still require to first stop it then delete it from the registry
ifconfig /flushdns
: force to discard the current DNS cache (useful if hosts configuration has been updated)
attrib
changes attributes of files and directories
- devcon to unmount devices including USB keys
- Windows Server 2003 Resource Kit Tools including
timeit
fsutil volume diskfree C:
: free space (in bytes) in the C: hard drive
shutdown -r -t 0
: reboot now
shutdown -a
: abort shutdown
- cd /D x:\path\
- actually switches to the other directory on the other drive
- packing and sending daily backup
- set dt=%date:~10,4%%date:~4,2%%date:~7,2%
- 7z a internalwiki_%dt%.tar wiki
- 7z a internalwiki_%dt%.tar.bz2 internalwiki_%dt%.tar
- del internalwiki_%dt%.tar
- pscp internalwiki_%dt%.tar.bz2 user@server.tld:/home/user/backups_path/
- tasklist : list the active processes
WMIC PROCESS get Caption,Commandline,Processid
- doskey /history > mycommands.txt : save the commands you typed in the
mycommands.txt
file
- path %path%;c:\myother\bin\path\; : appends the directory to the current path
- note that this is not a permanent change
- 7z : use 7zip command-line interface
7z a internalwiki.tar wiki
then 7z a internalwiki.tar.bz2 internalwiki.tar
- Stupid Command Prompt Tricks by Jeff Atwood, Coding Horror 2005
- Windows : Command Processor, PC Tools
- PowerShell by Microsoft
PuTTY suite
- pscp
- does require the
-agent
option to check for Pageant running instances
- and obviously a working key pair
- yet... it sometimes seem to work without!?
- pageant
- PuTTY Tray improved version of PuTTY (Win32). It features some cosmetic changes, and a number of addons to make it more useful and much more fun to use.
- KiTTY as recommended in #tmux on freenode
Scripting
Warning, this section is really shell specific (i.e. bash != zsh ...)
- sed
- expression1\|expression2 = Matches expression1 or expression (esp with GNU sed)
- see Vi and PmWiki for other regular expressions
crontab -l | sed "/^SSH_AUTH_SOCK/s,[^=]*$,$SSH_AUTH_SOCK," | crontab
- no need for
``
or $()
since it is a global variable
- delimiter changed to take into account the slashes in the path
- note that sed does allow access to environment variables and even to execute command but the ouput should not in include the delimiter
- e.g.
x=`whoami`; echo "fff" | sed "s/ff/$x /"
will work
- but fail if there is / in the username
- if it is the case and you can predict with certainty the character then change the delimiter e.g.
x=`whoami`; echo "fff" | sed "s|ff|$x |"
Check my ~/backups/*.sh and ~/bin/*.sh for examples
Bash
- http://mywiki.wooledge.org/RegularExpression from Bash guide
- see also the associated #bash channel on freenode
history
especially as with screen ~/.bash_history
does no cover all the commands
- practical also to get the lat commands via e.g.
tail
and to output them into a future script
history | tail -30 > my_new_bash_script
- Making sure it is being executed in the right environment
- Link to the motivation and the context
- # http://related/wiki/URL
- Testing for explicit help or improper number of argument
- Handling omitted arguments
date -d @1234909950
to convert unixtime time stamp to the default format
- for loop
- LANG=en_EN.utf-8 (required in the terminal and the application too)
- $@ to handle every arguments passed to the script
- PS1="[\u@\w]$ " set permanently in in ~/.bashrc
- seq -w -s" " 1 12 returns
01 02 03 04 05 06 07 08 09 10 11 12
- $((do some math))
- echo $(( $(cat file | sed "s/.*\d//" | wc -l) * 1024))
See also env, export, printenv, etc...
Awk
- awk '{print $2}'
- grep action=edit page_generated.txt | awk '{ SUM += $2} END {print SUM}'
Distributions
Debian
systemctl suspend
to sleep
- useful to stop after a long task with a boot proper, e.g
sudo dd if=/dev/sdb of=./pimetaapnaf.img bs=32M && sudo systemctl suspend
- man:checkinstall
- Debian Administration System Administration Tips and Resources
- http://packages.qa.debian.org/w/win32-loader.html
- parameters to load an ISO file
- Debian Backports
- recompiled packages from testing (mostly) and unstable (in a few cases only, e.g. security updates), so they will run without new libraries (wherever it is possible) on a stable Debian distribution.
- installing from source
- apt-get update
- apt-get install build-essential
- apt-get -b source package
- dpkg -i package_versionnumber_arch.deb
- updatedb
- locate package | more
cat /etc/debian_version
dpkg --search /file/whose/package/is/unknown
dpkg -L packagename
to list the files from a specified package
Configuration management software
See also the WebWorkersCampParis talk and the "infrastructure as code" paradigm presented during Automated Infrastructure is on the Menu with Chef, O'Reilly Webcast July 2010
- Nimbus open source toolkit that allows you to turn your cluster into an Infrastructure-as-a-Service (IaaS) cloud.
To explore
See also
- my related tools pages
- shell_sink web accessible version of your bash history, you can search, annotate and tag it.
- commandlinefu.com the place to record those command-line gems that you return to again and again.
- Blinkenshell.org
- Embedding shell clients
- Stow GNU Project
- program for managing the installation of software packages, keeping them separate (/usr/local/stow/emacs vs. /usr/local/stow/perl, for example) while making them appear to be installed in the same place (/usr/local).
- Advanced Bash-Scripting Guide An in-depth exploration of the art of shell scripting by Mendel Cooper
- Linux-libre project removing software that is included without source code, with obfuscated or obscured source code, under non-Free Software licenses, that do not permit you to change the software so that it does what you wish, and that induces or requires you to install additional pieces of non-Free Software.
- Shell Commander PHP script, that allows remote execution of shell commands (like SSH client) through a web browser.
Note
My notes on Tools gather what I know or want to know. Consequently they are not and will never be complete references. For this, official manuals and online communities provide much better answers.