Commands by cryptology_codes (4)

  • Issues & improvements Race conditions: the check for writability then mv is not fully atomic — another process could create/remove/change the target between the test and mv. Permissions and ownership: mv will preserve contents but the resulting file may have the temp file's permissions/ownership (mktemp default). Signal safety: if interrupted (SIGINT, SIGTERM) the temp file may remain. Portability: uses bash-compatible constructs but relies on mktemp and -a (POSIX [ -a ] is obsolete; better to use -e). Better error messages and exit status handling. Allow optional mode to write to stdout when no filename given. Support setting desired file mode (umask or chmod) and preserve atomic replace semantics. Enhanced version Uses safer existence test ([ -e ] not deprecated -a). Installs traps to clean up temp file on exit/signals. Preserves mode of the existing file (if it exists) or allows a chmod option. Attempts a safer atomic replace: write to temp in same directory as target when a filename is supplied (reduces window for cross-filesystem mv failure and preserves atomicity). If no filename given, writes temp contents to stdout. Returns non-zero on failure and prints concise errors to stderr.


    -4
    buffer(){ tty -s&&return; d=${1:-/tmp}; tmp=$(mktemp "$d/.b.XXXXXX")||return; trap 'rm -f "$tmp"' EXIT; cat>"$tmp"||{ rm -f "$tmp"; return 1; }; [ -z "$1" ]&&{ cat "$tmp"; rm -f "$tmp"; return 0; }; mv -f "$tmp" "$1"; }
    cryptology_codes · 2025-09-14 21:19:55 0

  • 3
    bc -l <<< "scale=1000; 4*a(1)"
    cryptology_codes · 2020-03-11 15:58:21 1

  • 2
    iamawesome=$(curl -LsS iamawesome.com | echo -e "\n\n$(cat) \n\n");
    cryptology_codes · 2018-11-08 03:22:42 0
  • Pluralize a word, aka change from single to multiple; text formatting. echo hamburgler | pluralize Show Sample Output


    0
    pluralize() { if [ -n "$1" ]; then echo ${1}s else while read line; do pluralize $line done fi }
    cryptology_codes · 2018-08-21 22:49:21 0

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands


Check These Out

Display time of accounts connection on a system
Works on CentOS ad OpenBSD too, display time of accounts connection on a system, -p option print individual user's statistics.

Top 10 Memory Processes
It displays the top 10 processes sorted by memory usage

Get the IP address

Find usb device in realtime
Using this command you can track a moment when usb device was attached.

Recursive search and replace (with bash only)
Replaces a string matching a pattern in one or several files found recursively in a particular folder.

function to verify an IP address - can be used at the shell prompt or in a shell script
When processing IP addresses in the shell (or shell script) it is useful to be able to verify that the value of data is an IP address (an not some random string or non-sensible IP address).

In-Place search/replace with datestamped backup
Does an in situ search-replace but leaves a datestamped backup. A variation with more precision: sed -i.`date +%Y%m%d%H%M%S 's/pattern/replace' [filename]

Tweak system files without invoking a root shell
only for sudo-style systems. Use this construct instead of I/O re-directors ``>'' or ``>>'' because sudo only elevates the commands and *not* the re-directors. ***warning: remember that the `tee` command will clobber file contents unless it is given the ``-a'' argument Also, for extra security, the "left" command is still run unprivileged.

One liner to kill a process when knowing only the port where the process is running

Calculate N!


Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: