avoiding UUOC! cut can handle files as well. No neet for a cat.
Transcodes mpg2 files, that cannot be read by iMovie to m4v files. Show Sample Output
# grab the first line showing php version php -i | grep 'PHP Version' | awk '{if(NR==1)print}' php -i | grep 'PHP Version' | sed -n '1!p' php -i | grep 'PHP Version' | tail -n 1 Show Sample Output
built-in command to see the last command executed by some users Show Sample Output
Prints the variable "$a" 80 times with a new line at the end. There is no need for backspaces as printf (by default) does not print a newline nor an space. Use a bunch of variables called "$_0" and a number. The name start with an underscore and a 0 to avoid conflicts with already defined variables. If still worried: All variables may be cleared up before use with "unset $_{1..080}". A command with a variable count is a bit of a mouthful: a=hello+; n=7; eval printf "%s" '$_{1..0'"$n"'}"$a"' $'$\'\\n\'' And carry some risk if the variable "$n" could be set by an attacker. Show Sample Output
List all your public IPs in an EC2/AWS region, and run an nmap scan against them (ignoring ping response). Requires: aws cli, jq for shell JSON processing Show Sample Output
Use this function with bash version 4+ to convert arbitrary hexadecimal sequences to binary. If you don't have bash 4+ then modify the lowercase to uppercase demangling statement
s=${@^^}
to set s equal to the uppercase hex input or the bc command throws an input parser error.
Show Sample Output
I used this to cut down the file size of a 1gb .avi to about 200mb without sacrificing much quality.
Helpful when we want to do mass file renaming(especially mp3s). Show Sample Output
This command will shorten any URL the user inputs. What makes this command different is that it utilizes 5 different services and gives you 5 different outputs: is.gd, bit.ly, u.nu, geekology.co.za, and tinyurl. curl -s http://tinyurl.com/create.php?url=$1 \ | sed -n 's/.*\(http:\/\/tinyurl.com\/[a-z0-9][a-z0-9]*\).*/\1/p' \ | uniq ; curl -s http://bit.ly/?url=$1 \ | sed -n 's/.*\(shortened-url" value="http:\/\/bit.ly\/[a-zA-Z0-9][a-zA-Z0-9]*\).*/\1/p' \ | sed -n 's/.*\(http:\/\/bit.ly\/[a-zA-Z0-9][a-zA-Z0-9]*\).*/\1/p' \ | uniq ; curl -s http://geekology.co.za/shortii/create.php?u=$1 \ | sed -n 's/.*\(http:\/\/geekology.co.za\/[a-z0-9][a-z0-9]*\).*/\1/p' \ | uniq ; curl -s http://u.nu/unu-api-simple?url=$1 \ | sed -n 's/.*\(http:\/\/u.nu\/[a-z0-9][a-z0-9]*\).*/\1/p' \ | uniq ; curl -s http://is.gd/api.php?longurl=$1 \ | sed -n 's/.*\(http:\/\/is.gd\/[a-z0-9][a-z0-9]*\).*/\1/p' \ | uniq echo ""
Some source package have many 'README' kind of files, among many other regular files/directories. This command could be useful when one wants to list only 'README' kind of files among jungle of other files. (e.g. I came across this situation after downloading source for module-init-tools) Warning: This command would miss a file like => README.1 (or one with spaces in-between) Corrections welcome. Show Sample Output
Should run with sudo
zless /proc/config.gz
See who is using a specific port. Especially when you're using AIX. In Ubuntu, for example, this can easily be seen with the netstat command. Show Sample Output
Allows system to be halted and session closed by KDE. Very useful to save applications states, especially with the KDE apps that behave correctly.
Magic line will extract almost all possible archives from current folder in its own folders. Don't forget to change USER name in sudo command. sed is used to create names for folders from archive names w/o extension. You can test sed expression, used in this command:
arg='war.lan.net' ; x=$(echo $arg|sed 's/\(.*\)\..*/\1/') ; echo $x
If some archives can't be extracted, install packages:
apt-get install p7zip-full p7zip-rar
Hope this will save a lot of your time. Enjoy.
For moving to the specified directory in the FreeBSD ports tree. I had been doing the following: whereis doom Which would return the path, but then I'd have to copy and paste the path to cd to the location. This command eliminates the copy, paste, cd, part of building from ports when I don't know the full path. Take note, the command is enclosed within backticks, not apostrophes or single quotes. Show Sample Output
### for ADUSER in $(wbinfo -u --domain="$(wbinfo --own-domain)" | sort); do WBSEP=$(wbinfo --separator); ADUNAME=$(wbinfo -i "$ADUSER" | cut -d ":" -f5); UINFO=$(wbinfo -i "$ADUSER" | cut -d ":" -f4); SIDG=$(wbinfo -G "$UINFO"); GROUPID=$(wbinfo -s "$SIDG" | sed 's/.\{1\}$//' | cut -d "$WBSEP" -f2); echo -e "$ADUSER ($ADUNAME)\n$(printf '%.s-' {1..32})\n\t[*] $GROUPID"; for GID in $(wbinfo -r "$ADUSER"); do SID=$(wbinfo -G "$GID"); GROUP=$(wbinfo -s "$SID" | cut -d " " -f1,2); echo -e "\t[ ] $(echo -e "${GROUP/%?/}" | cut -d "$WBSEP" -f2)"; done | sed '1d'; echo -e "$(printf '%.s=' {1..32})\n"; done ### Show Sample Output
Google Cloud SDK comes with a package manager `gcloud components` but it needs a bit of `sed` to work. Modify the "^| Not" bit to change the package selection. (The gcloud --format option is currently broken) Show Sample Output
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: