commandlinefu.com is the place to record those command-line gems that you return to again and again.
Delete that bloated snippets file you've been using and share your personal repository with the world. 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.
You can sign-in using OpenID credentials, or register a traditional username and password.
First-time OpenID users will be automatically assigned a username which can be changed after signing in.
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:
The output format is given by the -printf parameter:
%[email protected] = modify time in seconds since Jan. 1, 1970, 00:00 GMT, with fractional part. Mandatory, hidden in the end.
%TY-%Tm-%Td %TH:%TM:%.2TS = modify time as YYYY-MM-DD HH:MM:SS. Optional.
%p = file path
Refer to http://linux.die.net/man/1/find for more about -printf formatting.
------------------------
sort -nr = sort numerically and reverse (higher values - most recent timestamp - first)
head -n 5 = get only 5 first lines (change 5 to whatever you want)
cut -f2- -d" " = trim first field (timestamp, used only for sorting)
------------------------
Very useful for building scripts for detecting malicious files upload and malware injections.
Shows "Bang!" in a chance of 1 out of 6, like in the original game with the gun (spin every round). Otherwise, echoes "Click...". If feeling brave you can also do:
[ $[ $RANDOM % 6 ] == 0 ] && echo 'Bang!' && a really killer command || echo 'Click...'
Requires:
curl
xsel
access to the internet(http://transfer.sh)
This is an alias utilizing the transfer.sh service to make sharing files easier from the command line. I have modified the alias provided by transfer.sh to use xsel to copy the resulting URL to the clipboard.
The full modified alias is as follows since commandlinefu only allows 255 characters:
transfer() { if [ $# -eq 0 ]; then echo "No arguments specified. Usage:\necho transfer /tmp/test.md\ncat /tmp/test.md | transfer test.md"; return 1; fi if tty -s; then basefile=$(basename "$1" | sed -e 's/[^a-zA-Z0-9._-]/-/g'); curl --progress-bar --upload-file "$1" "https://transfer.sh/$basefile" |xsel --clipboard; else curl --progress-bar --upload-file "-" "https://transfer.sh/$1" |xsel --clipboard ; fi; xsel --clipboard; }
nothing fancy
`ls` alternative `exa`, with most info printed and passed through less with the `-R` (raw) option, to preserve colour output https://github.com/ogham/exa
You can add or remove `[email protected]` to print extended attributes for files that have them.
Just run this command and it will printout all the info available about your current distribution and package management system.
rsync'ing an empty directory over a directory to be deleted recursively is much faster than using rm -rf, for various reasons. Relevant only for directories with really a lot of files.
Uses git grep for speed, relies on a valid she-bang, ignores leading whitespace when stripping comments and blank lines
This command will add up RAM usage of all processes whose name contains "java" and output the sum of percentages in HRF. Also, unlike the original #15430, it wont fail on processes with a usage of >9.9%.
Pleases note that this command wont work reliably in use cases where a significant portion of processes involved are using less than 0.1% of RAM, because they will be counted as "0", even though a great number of them could add up to significant amounts.
Dependencies on phone: adb access, screencap command, base64 command.
Dependencies on computer: adb, sed, base64, display (from imagemagick, but can substitute other image viewer which reads from stdin).
This should work around adb stupidies (i.e. that it replaces \n with \r\n) with base64.
Get the latest and hopefully greatest to test out on the Ubuntu Phone - sometimes broken but always interesting. https://developer.ubuntu.com/en/start/ubuntu-for-devices/image-channels/
Warning this will allow you to write to the system image on the phone, not recommended. But sometimes useful.
To fix this bug: https://bugs.launchpad.net/ubuntu/+source/unity8/+bug/1389698
This will download and install the latest version of the open store on the ubuntu phone, this store includes unconfined applications such as the TweakGeek and the Ubuntu Touch Tweak Tool. You can see the install instructions from here: https://open.uappexplorer.com/docs#install
Generating ssh key
then need to copy public key in to /root/.ssh/authorized_keys
This command telnet and and looks for a line starting with "SSH" - works for OpenSSH since the SSH banner is something like "SSH-2.0-OpenSSH_6.0p1 Debian-4+deb7u3". Then it triggers an action accordingly.
It can be packed as a script file to echo 0/1 indicating the SSH service availability:
if [[ "$(sleep 1 | telnet -c <host> <port> 2>&1 | grep '^SSH')" == SSH* ]]; then echo 1; else echo 0; fi;
Alternative uses:
Trigger an action when server is UP (using &&):
[[ "$(sleep 1 | telnet -c <host> <port> 2>&1 | grep '^SSH')" == SSH* ]] && <command when up>
Trigger an action when server is DOWN (using ||):
[[ "$(sleep 1 | telnet -c <host> <port> 2>&1 | grep '^SSH')" == SSH* ]] || <command when down>
Nginx (and other webservers like Apache) can be awkward to trace. They run as root, then switch to another user once they're ready to serve web pages. They also have a "master" process and multiple worker processes.
The given command finds the process IDs of all Nginx processes, joins them together with a comma, then traces all of them at once with "sudo strace." System trace output can be overwhelming, so we only capture "networking" output.
TIP: to kill this complex strace, do "sudo killall strace".
Compare with a similar command: http://www.commandlinefu.com/commands/view/11918/easily-strace-all-your-apache-processes
Alternative1 (grep support):
pacman -Ss python | paste - - | grep --color=always -e '/python' | less -R
Alternative2 (eye-candy, no grep):
pacman --color=always -Ss "python" | paste - - | less -R
in ~/.bashrc:
pkg-grep() { pacman -Ss "$1" | paste - - | grep --color=always -e "${2:-$1}" | less -R ; }
pkg-search() { pacman --color=always -Ss "python" | paste - - | less -R; }