recentpopularlog in

kme : tipsandtricks   747

« earlier  
Th Most Handy du (Disk Usage) Commands in Linux - Make Tech Easier
Honestly did not know about the '--threshold' or exclusion options.
sysadmin  diskspace  unix  linux  du  tipsandtricks 
4 weeks ago by kme
tmux(1) - OpenBSD manual pages |
select-pane [-DdeLlMmRU] [-T title] [-t target-pane]
(alias: selectp)
Make pane target-pane the active pane in window target-window. If one of -D, -L, -R, or -U is used, respectively the pane below, to the left, to the right, or above the target pane is used. -l is the same as using the last-pane command. -e enables or -d disables input to the pane. -T sets the pane title.

-m and -M are used to set and clear the marked pane. There is one marked pane at a time, setting a new marked pane clears the last. The marked pane is the default target for -s to join-pane, swap-pane and swap-window.
til  tmux  tipsandtricks  windowmanagement 
4 weeks ago by kme
[dev] Re: Auto-preview man pages from Charles Lehner on 2016-01-09 (dev mail list archive)
You could also send mupdf a SIGHUP signal to tell it to reload, instead of spawning a new mupdf:
<code class="language-bash">
mupdf address.pdf & pid="$!"
echo address.yaml | entr sh -c "make address.pdf && kill -HUP $pid"</code>
entr  automation  manpage  commandline  devel  tipsandtricks 
5 weeks ago by kme
A minimalist guide to tmux | Hacker News
Well, I was half-joking :-) and I did expect that few people would know about C-\ for SIGQUIT. Myself, I find it very useful for programs written by people who think it's a good idea to capture SIGINT (it's not), because same people (and I will refrain from using adjectives) forget about SIGQUIT most of the time. Which means I can quickly kill a misbehaving program without typing something in a separate shell.
tmux  terminal  multiplexer  jobcontrol  keybindings  tipsandtricks 
5 weeks ago by kme
Bash test: get the directory of a script
Dude made the mistake of assuming the whole world was Linux.
whereami  bash  shellscripting  tipsandtricks  tests  interesting 
7 weeks ago by kme
Get the source directory of a Bash script from within the script itself - Stack Overflow
Lots of conflicting opinions here, but here are two solid options:
<code class="language-bash">
DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )
DIR=$( dirname "$(readlink -f "$0")" )
bash  shellscripting  newbie  whereami  tipsandtricks 
7 weeks ago by kme
Julio Biason .Net 4.0 - Things I Learnt The Hard Way (in 30 Years of Software Development)
"A language that doesn't affect the way you think about programming, is not worth knowing." -- Alan Perlis
antipatterns  coding  programming  career  advice  tipsandtricks 
8 weeks ago by kme
How do you attach and detach from Docker's process? - Stack Overflow
To detach the tty without exiting the shell, use the escape sequence Ctrl-p Ctrl-q.

more details here:

additional info from this source (!msg/docker-user/nWXAnyLP9-M/kbv-FZpF4rUJ):

* docker run -t -i → can be detached with ^P^Qand reattached with docker attach
* docker run -i → cannot be detached with ^P^Q; will disrupt stdin
* docker run → cannot be detached with ^P^Q; can SIGKILL client; can reattach with docker attach
docker  commandline  tipsandtricks  solution  fuckina 
9 weeks ago by kme
Perl Is Still The Goddess For Text Manipulation – Towards Data Science
<code class="language-perl"># insert line numbers
perl -i -ne 'printf "%04d %s", $., $_'</code>

# print columns 1-5
perl -F"\t" -nlae'print join "\t", @F[0..4]'

# print all lines from line 18 to line 29
perl -ne 'print if $. >=18 && $. <=29'

# print all lines between two patterns
perl -ne 'print if (/^START/../^END/);'</code>
perl  textprocessing  oneliners  tipsandtricks  likeawk 
10 weeks ago by kme
bash - REOPEN: Perform arithmetic expansion inside parameter expansion? - Unix & Linux Stack Exchange
Again with the 'set' trick for testing script arguments interactively:
<code class="language-bash">set 6 7; echo $(($1*$2))</code>
bash  parameterexpansion  arithmeticexpansion  shellscripting  parameters  positionalarguments  idiom  tipsandtricks 
10 weeks ago by kme
linux - bash + arithmetic calculation with bash - Unix & Linux Stack Exchange
Since arithmetic expansion only does integer division, the proposed answer uses AWK, passing in values as variables, with '/dev/null' as the input file, and the math in a 'BEGIN' block.
bash  awk  shellscripting  floatingpoint  math  tipsandtricks  solution 
10 weeks ago by kme
How To Create Fillable PDF Forms With LibreOffice Writer - Linux Uprising Blog
LibreOffice Writer can be used to create fillable PDF forms, being a great free, open source alternative to Adobe's Acrobat for this use case. LibreOffice is cross-platform too, so you can use it not only on Windows and macOS, but also on Linux.
pdf  libreoffice  filloutforms  tipsandtricks  howto 
10 weeks ago by kme
Deciphering Glyph :: Tips And Tricks for Shipping a PyGame App on the Mac
Luckily the OS ships with the macOS-specific “scriptable image processing system”, which can helpfully convert an icon for you. Make yourself a 512x512 PNG file in your favorite image editor (with an alpha channel!) that you want to use as your icon, then run it something like this:
<code class="language-bash">$ sips -s format icns Icon.png --out Icon.icns</code>

somewhere in your build process, to produce an icon in the appropriate format.
mac  python  pygame  packaging  woes  imageprocessing  icons  tipsandtricks 
11 weeks ago by kme
Search for visually selected text | Vim Tips Wiki | FANDOM powered by Wikia
Create file (for example) ~/.vim/plugin/vsearch.vim (Unix) or $HOME/vimfiles/plugin/vsearch.vim (Windows) with contents:

<code class="language-viml">" Search for selected text.
let s:save_cpo = &cpo | set cpo&vim
if !exists('g:VeryLiteral')
let g:VeryLiteral = 0
function! s:VSetSearch(cmd)
let old_reg = getreg('"')
let old_regtype = getregtype('"')
normal! gvy
if @@ =~? '^[0-9a-z,_]*$' || @@ =~? '^[0-9a-z ,_]*$' && g:VeryLiteral
let @/ = @@
let pat = escape(@@, a:cmd.'\')
if g:VeryLiteral
let pat = substitute(pat, '\n', '\\n', 'g')
let pat = substitute(pat, '^\_s\+', '\\s\\+', '')
let pat = substitute(pat, '\_s\+$', '\\s\\*', '')
let pat = substitute(pat, '\_s\+', '\\_s\\+', 'g')
let @/ = '\V'.pat
normal! gV
call setreg('"', old_reg, old_regtype)
vnoremap <silent> * :<C-U>call <SID>VSetSearch('/')<CR>/<C-R>/<CR>
vnoremap <silent> # :<C-U>call <SID>VSetSearch('?')<CR>?<C-R>/<CR>
vmap <kMultiply> *
nmap <silent> <Plug>VLToggle :let g:VeryLiteral = !g:VeryLiteral
\\| echo "VeryLiteral " . (g:VeryLiteral ? "On" : "Off")<CR>
if !hasmapto("<Plug>VLToggle")
nmap <unique> <Leader>vl <Plug>VLToggle
let &cpo = s:save_cpo | unlet s:save_cpo</code>
vim  searching  searchandreplace  tipsandtricks  essential  movein  vimscript 
11 weeks ago by kme
Intrepid command line directory traversal - |
I use Terminal (well, iTerm 2) for file management on my Mac more often than I use Finder. Typing out long path names is often more tedious than drilling through Finder folders, though. I have enough
unix  shell  bash  commandline  filesystemnavigation  tipsandtricks 
april 2019 by kme
How to setup trap in bash functions? - Unix & Linux Stack Exchange
Accepted answer suggests making function asynchronous (put it in the background?) and using 'wait'. I do not understand this.
Protip: Send the foreground process a QUIT with Ctrl-\ when Ctrl-C, -Z, -D aren't working.

Clear traps at the end of execution with trap - list of signals here

Fun on a non-production system: Try setting a trap for all sensible signals (e.g., not KILL). kill -l (not that's a lower-case L not a number 1 or pipe |)
bash  shellscripting  signals  processmanagement  tipsandtricks  reference 
april 2019 by kme
Awesome Bar - Search your Firefox bookmarks, history and tabs from the address bar | Firefox Help
Possible workaround for (Firefox assuming anything with dots in it is a domain name).
If you are looking for a specific type of result, like a bookmark or tag, you can speed up the process of finding it by typing in special characters after each search term in the address bar separated by spaces:

* Add ^ to search for matches in your browsing history.
* Add * to search for matches in your bookmarks.
* Add + to search for matches in pages you've tagged.
* Add % to search for matches in your currently open tabs.
* Add # to search for matches in page titles.
* Add $ to search for matches in web addresses (URLs).
* Add ? to search for matches in suggestions.
firefox  awesomebar  shortcuts  tipsandtricks  reference  fuckina  webbrowser  newbie 
april 2019 by kme
The Art of Debugging
If the site they're talking about is jsbin, then I know saving does work, because I just used it, it just means that saving isn't working for them (and potentially others). Translation: saving could just be working for me.
debugging  javascript  webdevel  frontend  tipsandtricks  bestpractices  chrome  devtools 
march 2019 by kme
permissions - How to chmod without /usr/bin/chmod? - Unix & Linux Stack Exchange |
You can run the loader directly, and pass it the command you want to run:
<code class="language-bash">
/lib/ /bin/chmod +x /bin/chmod

Your path to the loader might vary. On a 64-bit system you need to choose the right one based on how chmod was compiled; the 64-bit version is named something like /lib64/

The chmod utility relies on the chmod() system call (see man 2 chmod). So you could do this with a few lines of C, or just about any other language that has a wrapper around it (which would be most of them). Very few *nix systems are going to lack a C compiler and a perl interpreter; most linux distros require the later to work.
<code class="language-bash">
perl -e 'chmod 0755, "foobar.file"'
linux  unix  sysadmin  chmod  tipsandtricks  disasterrecovery 
march 2019 by kme
pipe - cryptsetup: Attaching loopback device failed - Unix & Linux Stack Exchange |
It seems that cryptsetup requires the LUKS header to be either regular file or device. If you need to provide the LUKS header as an output from a process/stream, you can easily circumvent the restriction by sending it to /dev/ram
<code class="language-bash">
cat LUKS-HEADER > /dev/ram0

(provided that your kernel supports ramdisk)

Then you can then simply use your cryptsetup command as:
<code class="language-bash">
cryptsetup luksOpen /dev/sdb1 sdb1 --header /dev/ram0

Keep in mind, the LUKS header will stay in /dev/ram0 disk until you free up the space. To free up the memory, you can use the blockdev command:
<code class="language-bash">
blockdev -v --flushbufs /dev/ram0
luks  crypto  blockdevices  linux  unix  sysadmin  tipsandtricks 
march 2019 by kme
linux - Why redirect stdin inside a while read loop in bash? - Stack Overflow |
The clear intent here is to prevent do_something from reading from the sample.text stream, by ensuring that its stdin is coming from elsewhere. If you're not seeing differences in behavior with or without the redirection, that's because do_something isn't actually reading from stdin in your tests.


By the way, I would write this more as follows:
<code class="language-bash">exec 3</dev/tty || exec 3<&0 ## make FD 3 point to the TTY or stdin (as fallback)

while read -a args; do ## |- loop over lines read from FD 0
do_something "${args[@]}" <&3 ## |- run do_something with its stdin copied from FD 3
done <sample.text ## \-> ...while the loop is run with sample.txt on FD 0

exec 3<&- ## close FD 3 when done.</code>

It's a little more verbose, needing to explicitly close FD 3, but it means that our code is no longer broken if we're run with stdout attached to the write-only side of a FIFO (or any other write-only interface) rather than directly to a TTY.
bash  shellscripting  stdin  filedescriptors  epiphany  tipsandtricks  solution 
march 2019 by kme
How to get $HOME directory of different user in bash script? - Stack Overflow |
<code class="language-bash">eval echo "~$different_user" # prints $different_user's home dir.</code>
sysadmin  homedirectory  bash  tipsandtricks  solution 
march 2019 by kme
GNU Parallel 20110205 - The FOSDEM Release - YouTube |
Using '--pipe'

Each block of 3 is sorted, but whole output is not sorted:
<code class="language-bash">
# when used with --pipe, '-N' is the number of records to read

seq 1 10 | shuf | parallel --pipe -N 3 sort -n
# result:
# 1
# 3
# 10
# 2
# 4
# 6

Sort each group of records individually, output to files w/ '--files':
<code class="language-bash">
seq 1 10 \
| shuf \
| parallel --pipe --files -N 3 sort -n
# result:
# /tmp/sNGZtP6Kr8.par
# /tmp/q44fQdincg.par
# /tmp/CSVAPt5Ybe.par

Pipe through another parallel to merge pre-sorted files & clean up temps using '-mj1' is basically like 'xargs' (all arguments on one command line); with recent versions, may want to use '-X' instead.
<code class="language-bash">
seq 1 10 \
| shuf \
| parallel --pipe -N 3 sort -n \
| parallel -mj1 sort -nm {} ';' rm {}
gnuparallel  parallelism  sysadmin  unix  textprocessing  tipsandtricks  video 
february 2019 by kme
Set current working directory on ssh - Super User |
Invoke $SHELL instead.
<code class="language-bash">
ssh -t user@server 'cd /home/some/dir ; exec "$SHELL"'
unix  linux  ssh  putty  tipsandtricks  remoteexecution  sysadmin  solution 
february 2019 by kme
Genomics Code: How to correct negative coordinates from peaks bed file |
Use cat and pipe it to awk:
<code class="language-bash">cat peaks.bed | awk '{OFS="\t"}{if($2<0){$2=0};print}' > corrected_peaks.bed

Or remove them:
<code class="language-bash">cat peaks.bed | awk ‘($2>0)’ | filtered_peaks.bed</code>
bedfiles  bed  genomics  awk  tipsandtricks 
february 2019 by kme
keyboard shortcuts - How to put current line at top/center/bottom of screen in vim? - Unix & Linux Stack Exchange |
zt puts current line to top of screen
z. or zz puts current line to center of screen
zb puts current line to bottom of screen

More info about scrolling at or in vim type :help scroll-cursor
vim  tipsandtricks  scrolling  cursormotion  solution  dammitbrain 
february 2019 by kme
Tips and tricks: How to change default Google calendar |
The only real solution is to deselect all the other calendars when you're creating events. The top calendar (of the enabled ones) is the default when adding new events.

googlecalendar  calendar  tipsandtricks  annoyance  sortof  solution 
january 2019 by kme
Ensuring the Longevity of Digital Information
archive  digitization  archival  datastorage  permanence  tipsandtricks  science  article 
january 2019 by kme
Installing older versions of packages – RStudio Support
<code language="R">
install_version("ggplot2", version = "0.9.1", repos = "")

Unfortunately, you will probably need Rtools (on Windows) to build one of the dependencies of 'devtools' (maybe pkgload?).

I ran into this problem where shiny-1.2.0 required httpuv-1.4.5, but only httpuv-1.4.1 was available from the CRAN repos for R 3.3.x.

This might've let me install an older version, but I still had to guess at *which* version of RShiny would've worked with httpuv-1.4.1. What I ended up doing was installing a binary shiny-1.0.5 from
r  rstudio  packagemanagement  sortof  solution  tipsandtricks 
november 2018 by kme
bash - Remove files which not named "" - Unix & Linux Stack Exchange |
Use a negative match (requires shopt -s extglob, but possibly already set):
<code class="language-bash">
rm !(today).md

(you can first use ls instead of rm to check the result).

Lots of power in extglob, you could also do
<code class="language-bash">
rm !(yesterday|today).md

if you wanted to spare two files.
bash  shellscripting  wildcard  globs  filemanagement  tipsandtricks 
november 2018 by kme
Adding size of files using shell script - Unix & Linux Stack Exchange |
Two good solutions:

<code class="language-bash">stat -c "%s" /etc/*.conf|paste -sd+|bc -l</code>

<code>{ stat -c '%s+\' /etc/*.conf ; echo 0 ; } | bc</code>
bash  unix  shellscripting  stat  tipsandtricks  solution 
november 2018 by kme
linux - How to strip path while archiving with TAR - Stack Overflow
In your "Extraction phase" you can use the strip-components flag like
<code class="language-bash">tar xvf tarname.tar --strip-components=n</code>
tar  archive  decompression  tipsandtricks  commandline  shellscripting  solution 
november 2018 by kme
Remember all your bash history forever |
WATCH OUT! Old-ass versions of Bash (4.1.x on CentOS 6, for example) will truncate your damn history file if you use HISTFILESIZE=-1 or HISTSIZE=-1.
Append the following lines to /etc/bash.bashrc:
<code class="language-bash">HISTTIMEFORMAT='%F %T '
shopt -s histappend # append to history, don't overwrite it
# attempt to save all lines of a multiple-line command in the same history entry
shopt -s cmdhist
# save multi-line commands to the history with embedded newlines
shopt -s lithist</code>

This configures bash to save every command line typed at the interactive shell prompt (HISTFILESIZE) to ~/.bash_history (default), including a timestamp (HISTTIMEFORMAT) and ignoring consecutive duplicate entries (HISTCONTROL). By setting HISTSIZE to the same value as HISTFILESIZE, all saved commands are read back to memory when a new interactive shell starts. The default value for HISTSIZE (500) would load only a fraction of the saved history.

When saving the history at shell exit, history lines are appended to existing ones, instead of replacing them (shopt -s histappend).

By setting HISTIGNORE=?:??, lines consisting of just one or two characters are discarded from the history (e.g. ls commands).
bash  history  tipsandtricks  configsettings  essential  movein  bashrc 
october 2018 by kme
Bash Reference Manual: Bash History Builtins |
A useful alias to use with the fc command is r='fc -s', so that typing ‘r cc’ runs the last command beginning with cc and typing ‘r’ re-executes the last command (see Aliases).
bash  history  tipsandtricks  bashrc  bash_aliases  movein  essential 
october 2018 by kme
linux - How to show line number when executing bash script - Stack Overflow |
<code class="language-bash">export PS4='+(${BASH_SOURCE}:${LINENO}): ${FUNCNAME[0]:+${FUNCNAME[0]}(): }'</code>
bash  shellscripting  devel  debugging  configfile  movein  tipsandtricks  solution 
august 2018 by kme
linux - Force logout a user - Super User |
You terminate a session by killing its parent process, called the session leader. Find out which process it is with:

<code class="language-bash">ps -dN|grep pts/3</code>
unix  linux  sysadmin  usermanagement  processmanagement  tipsandtricks  maybesolution 
july 2018 by kme
How to: Linux Kill and Logout Users - nixCraft |
The ultimate command to kill and logout all users is as follows: <code class="language-bash"># skill -KILL -v /dev/pts/*</code>
unix  linux  usermanagement  processmanagement  sysadmin  tipsandtricks 
july 2018 by kme
Indeterminate Checkboxes | CSS-Tricks |
<code class="language-html"><!-- Inline click handler, just for demo -->
<input type="checkbox" id="cb1" onclick="ts(this)"></code>

<code class="language-javascript">
function ts(cb) {
if (cb.readOnly) cb.checked=cb.readOnly=false;
else if (!cb.checked) cb.readOnly=cb.indeterminate=true;
webdesign  webdeve  html  jquery  css  javascript  checkbox  tristate  tipsandtricks 
may 2018 by kme
« earlier      
per page:    204080120160

Copy this bookmark:

to read