some more neat unix tricks
scp when there are too many arguments
Sometimes you want to retrieve a lot of files from a remote location but the expension of star (*) in bash returns the following error
Argument list too long
One way of fixing it is to leverage find
and its nice -exec switch:
$ ssh <user>@<remote-host> 'find <path-where-files-are> -type f -name "<some-regex>" | tar czvf - --files-from -' | tar zxvf - -C <local-destination>
As a reminder, following command allows to retrieve the max number of arguments that can be passed to a command:
$ getconf ARG_MAX
Reload groups without logging out
Simple trick to avoid to log out to apply new groups
$ id
$ su - $USER
$ id
Find file newer or older than a specific date
Create a file with the to-be-tested timestamp (format: YYYYMMDDHHMM, see also the manpage)
$ touch -t 201501010000 /tmp/timestamp
Then query with find
$ find <some-path> -newer /tmp/timestamp
$ find <some-path> -not -newer /tmp/timestamp
Chown symlink
How to chown a symlink
$ chown -h <user>:<group> <symlink>
Gateway routing
Check which gateway would be used for routing a specific IP:
$ ip route get <IP>
Randomize-lines replacement
The package Randomize-lines
that provides the quite useful rl
for
randomizing lines has been removed in latest Ubuntu version
(Xenial and newer).
A replacement for this is the shuf
tool.
For example to retrieve a random line from a file
$ shuf -n 1 <some-file>
script duration
Ever wanted to know the duration of a specific bash script ? The following oneliner allows to do that easily:
date -u -d @${SECONDS} +%T
ps tree-style
Display ps
output with the processes hierarchy:
ps aux --forest