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.
This fetches ipfs v0.36.0 for GNU/LInux and puts it in ~/bin without a tmp file or anything else. This works if you already have ~/bin. The `--strip-components=1` flag removes the "kubo" directory in this case. If you have a tar with an even deeper directory structure, say: `some/other/directory/file`, you can just use `--strip-components=3` and it will only extract `file` for you. `-C ~/bin` puts the file in the designated path. In this case, `~/bin`.
$ tar -C ~/bin/ --strip-components=1 -xzf <( curl -L https://dist.ipfs.tech/kubo/v0.36.0/kubo_v0.36.0_linux-amd64.tar.gz ) kubo/ipfs % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 49.0M 100 49.0M 0 0 26.1M 0 0:00:01 0:00:01 --:--:-- 26.1M
Show top 10 users by memory combined consumption in percentage.
user01 1.6 user02 2.8 user03 2.8 user04 3.2 user05 4.9 user06 5.5 user07 6.6 user08 13.6 user09 13.7 user10 16.5
If you need to see a list of the reboots of your system with date and time stamps then on a Linux with systemd you can use (as non-root) the command:
journalctl --list-boots
This could be useful if you are trying to track when a power outage occurred.
An alternative is:
/bin/sudo grep "^-" /var/log/boot.log
^ This only shows the boot start date/times while the journalctl command shows a "LAST ENTRY" associated with each "BOOT ID".
$ journalctl --list-boots IDX BOOT ID FIRST ENTRY LAST ENTRY [data redacted]
This will download a video when given the link and it will extract the audio from the video. The filename will be the same as the video's title. File extension in mp3.
Hit an API with curl returning a random quote, then parse the result with jq.
"A guy that clean has to be dirty." -- Hank Schrader
No sample. Try it and see the magic!
Remove clear; sleep 5 and echo for not doing sample!
1) The last sed expression ensures the unicast/multicast bit is set to zero 2) The greedy space replacements are for portability across UNIX seds
a0:94:47:e1:f7:59
Enable it again: reg delete "HKEY_CURRENT_USER\Software\Classes\CLSID\{86ca1aa0-34aa-4e8b-a509-50c905bae2a2}" /f
Successfully completed.
Use variable: letters=("a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l" "m" "n" "o" "p" "q" "r" "s" "t" "u" "v" "w" "x" "y" "z")
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.
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
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: