All commands (13,945)

  • Shell function which takes a bash command as its input, and displays the following formatted output: EXAMPLE: command OUTPUT: output from command Show Sample Output


    1
    example() { echo "EXAMPLE:"; echo; echo " $@"; echo; echo "OUTPUT:"; echo ; eval "$@" | sed 's/^/ /'; }
    bartonski · 2019-11-10 19:08:23 0
  • Measure the cpu performance: In-case if the cpu is thermal throttling then you can find it using this command. Check the first line of the output. Example: Doing md5 for 3s on 16 size blocks: 11406892 md5's in 2.98s ? #(When cpu is not throttling) Doing md5 for 3s on 16 size blocks: 110692 md5's in 2.98s ?? #(When cpu is thermal throttling) Practical use case: Once we had cooling outage in data center which caused thermal throttling in some of the worker nodes. We used this tool to prove that some servers are not performing well because of the cpu thermal throttling. Show Sample Output


    0
    openssl speed md5
    kharthigeyan · 2019-11-07 16:30:30 0
  • Click window to change its opacity. Source: https://unix.stackexchange.com/a/494289


    0
    xprop -format _NET_WM_WINDOW_OPACITY 32c -set _NET_WM_WINDOW_OPACITY 0x7FFFFFFF
    yoyoyojomo · 2019-10-31 20:44:21 0
  • This command first determines whether a second screen is connected. If this is the case, it sets the screen's RGB gamma via xrandr. Useful for cheap or slightly defective monitors with a tint. In this example a yellowing/champagne color deviation is compensated for by decreasing the red and the green portion of the image.


    0
    secondscreen=$(xrandr -q | grep " connected" | sed -n '2 p' | cut -f 1 -d ' '); [ "$secondscreen" ] && xrandr --output $secondscreen --gamma 0.6:0.75:1
    lordtoran · 2019-10-28 13:12:08 0
  • Change the file extension in batch. Useful to create output file names with same input name but distinct extension by including logic inside the loop


    1
    for file in *.txt; do mv "$file" "${file%.txt}.xml"; done
    neomefistox · 2019-10-24 04:35:10 0

  • 3
    find /glftpd/site/archive -type f|grep '([0-9]\{1,9\})\.[^.]\+$'|parallel -n1 -j200% md5sum ::: |awk 'x[$1]++ { print $2 " :::"}'|sed 's/^/Dupe: /g'|sed 's,Dupe,\x1B[31m&\x1B[0m,'
    wuziduzi · 2019-10-22 16:02:15 1
  • Top 10 Memory Processes (reduced output to applications and %usage only) Show Sample Output


    0
    ps aux | sort -rk 4,4 | head -n 10 | awk '{print $4,$11}'
    n0a110w · 2019-10-20 22:52:55 0
  • You will see it on the corner of your running terminal. Show Sample Output


    2
    while sleep 1; do tput sc; tput cup 0 $(($(tput cols)-29)); date; tput rc; done &
    rakibfiha · 2019-10-19 20:50:48 0
  • Hides all Files and Folders on the MacOS Desktop. To show files and folders, type "true" instead of "false". "Finder" at the end is case sensitive, "finder" doesn’t work


    0
    defaults write com.apple.finder CreateDesktop -bool false;killall Finder
    vranx · 2019-10-18 12:13:56 0

  • 0
    for i in *; do sum=$(md5sum $i); mv -- "$i" "${sum%% *}"; done
    malsploit · 2019-10-17 08:46:22 0
  • Print date in iso format. Show Sample Output


    0
    date +%Y-%m-%dT%H:%M:%S%z
    ThinWarrior · 2019-10-13 13:49:58 1
  • Works for repos cloned via ssh or https. Show Sample Output


    0
    git remote -v | sed -n '/github.com.*push/{s/^[^[:space:]]\+[[:space:]]\+//;s|git@github.com:|https://github.com/|;s/\.git.*//;p}'
    bartonski · 2019-10-11 16:50:22 0
  • GNU grep's perl-compatible regular expression(PCRE).


    0
    binaries () { dpkg -L "$1" | grep -Po '.*/bin/\K.*'; }
    metropolis · 2019-10-05 10:52:15 0
  • This shell function displays a list of binaries contained in an installed package; works on Debian based Linux distributions. Show Sample Output


    0
    binaries () { for f in $(dpkg -L "$1" | grep "/bin/"); do basename "$f"; done; }
    lordtoran · 2019-10-05 10:37:51 0
  • With this command you can convert a tab separate file (TSV) into a JSON file with jq. For example, this input.tsv i-0b9adca882e5e6326 172.16.0.188 i-088dd69e5c3624888 172.16.0.102 i-0e70eac180537d4aa 172.16.0.85 will produce the showed output. Show Sample Output


    2
    cat input.tsv | jq --raw-input --slurp 'split("\n") | map(split("\t")) | .[0:-1] | map( { "id": .[0], "ip": .[1] } )'
    nordri · 2019-10-01 10:52:35 0
  • It displays the top 10 processes sorted by memory usage Show Sample Output


    2
    ps aux | sort -rk 4,4 | head -n 10
    x3mboy · 2019-09-26 16:37:33 1
  • Copy this function to command line, press 'Enter' 'f'' 'Enter' to execute (sentence on the left written only for newbies). Hint 'e|x|v|1..9' in front of displayed last modified file name means: "Press 'e' for edit,'x' for execute,'v' for view or a digit-key '1..9' to touch one file from the recent files list to be last modified" and suggested (hidden files are listed too, else remove 'a' from 'ls -tarp' statement if not intended). If you find this function useful you can then rename it if needed and append or include into your ~/.bashrc config script. With the command . ~/.bashrc the function then can be made immediately available. In the body of the function modifications can be made, i.e. replaced joe editor command or added new option into case statement, for example 'o) exo-open $h;;' command for opening file with default application - or something else (here could not be added since the function would exceed 255 chars). To cancel execution of function started is no need to press Ctrl-C - if the mind changed and want to leave simple Enter-press is enough. Once defined, this function can with typeset -f f command be displayed in easy readable form Show Sample Output


    2
    f() { ls -lart;e="ls -tarp|grep -v /|tail -9";j=${e/9/1};g=${e/9/9|nl -nln};h=$(eval $j);eval $g;read -p "e|x|v|1..9 $(eval $j)?" -n 1 -r;case $REPLY in e) joe $h;;v)cat $h;;x) eval $h;;[1-9]) s=$(eval $g|egrep ^$REPLY) && touch "${s:7}" && f;;esac ; }
    knoppix5 · 2019-09-26 11:58:37 1
  • The command finds every item within the directory and edits the output so that subdirectories are and files are output much like the tree command Show Sample Output


    0
    find . -print | sed -e 's;[^/]*/;|-- ;g;s;-- |; |;g'
    jonavon · 2019-09-25 17:49:35 0

  • 0
    $ sudo systemctl restart bluetooth
    jadnb · 2019-09-23 19:18:56 0
  • If your `date` command has `-r` option, you don't need `stat`


    1
    cp file{,.$(date -r file "+%y%m%d")}
    brx75x · 2019-09-19 09:42:38 0
  • Writes hybrid ISO directly to USB stick; replace /dev/sdb with USB device in question and the ISO image link with the link of your choice


    0
    wget -O /dev/sdb https://cdimage.ubuntu.com/daily-live/current/eoan-desktop-amd64.iso
    realkstrawn93 · 2019-09-19 04:03:13 0

  • 3
    diff <(tree /dir/one) <(tree /dir/two)
    redraw · 2019-09-19 01:33:08 1

  • 1
    (read -r passphrase; b58encode 80$( brainwallet_exponent "$passphrase" )$( brainwallet_checksum "$passphrase" ))
    Jacki188 · 2019-09-15 21:31:52 1
  • --delete will delete copies on remote to match local if deleted on local --stats will output the results -z zip -a archive -A preserve ACL -x don't cross filesystem boundaries -h human readable -e specify the remote shell to use


    2
    rsync --delete --stats -zaAxh -e ssh /local_directory/ username@IP_of_remote:/Remote_Directory/ > /Text_file_Directory/backuplog.txt
    chicagonpg · 2019-09-10 21:00:29 0
  • AWS provides a method to audit for obsolete AWS security groups. From their documentation: "Describes the stale security group rules for security groups in a specified VPC. Rules are stale when they reference a deleted security group in a peer VPC, or a security group in a peer VPC for which the VPC peering connection has been deleted." Show Sample Output


    0
    aws ec2 describe-vpcs --query 'Vpcs[*].VpcId' --output text |xargs -t -n1 aws ec2 describe-stale-security-groups --vpc-id
    vocatan · 2019-09-09 18:54:08 0
  •  1 2 3 >  Last ›

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

Get your internal IP address and nothing but your internal IP address
Will return your internal IP address.

Use the builtin ':' bash command to increment variables
I just found another use for the builtin ':' bash command. It increments counters for me in a loop if a certain condition is met... : [arguments] No effect; the command does nothing beyond expanding arguments and performing any specified redirections. A zero exit code is returned.

vmstat/iostat with timestamp
Also useful with iostat, or pretty much anything else you want timestamped.

Get AWS temporary credentials ready to export based on a MFA virtual appliance
You might want to secure your AWS operations requiring to use a MFA token. But then to use API or tools, you need to pass credentials generated with a MFA token. This commands asks you for the MFA code and retrieves these credentials using AWS Cli. To print the exports, you can use: `awk '{ print "export AWS_ACCESS_KEY_ID=\"" $1 "\"\n" "export AWS_SECRET_ACCESS_KEY=\"" $2 "\"\n" "export AWS_SESSION_TOKEN=\"" $3 "\"" }'` You must adapt the command line to include: * $MFA_IDis ARN of the virtual MFA or serial number of the physical one * TTL for the credentials

last.fm rss parser
Quick and kludgy rss parser for the recent tracks rss feed from last.fm. Extracts artist and track link.

Get AWS temporary credentials ready to export based on a MFA virtual appliance
You might want to secure your AWS operations requiring to use a MFA token. But then to use API or tools, you need to pass credentials generated with a MFA token. This commands asks you for the MFA code and retrieves these credentials using AWS Cli. To print the exports, you can use: `awk '{ print "export AWS_ACCESS_KEY_ID=\"" $1 "\"\n" "export AWS_SECRET_ACCESS_KEY=\"" $2 "\"\n" "export AWS_SESSION_TOKEN=\"" $3 "\"" }'` You must adapt the command line to include: * $MFA_IDis ARN of the virtual MFA or serial number of the physical one * TTL for the credentials

Convert seconds to [DD:][HH:]MM:SS
Converts any number of seconds into days, hours, minutes and seconds. sec2dhms() { declare -i SS="$1" D=$(( SS / 86400 )) H=$(( SS % 86400 / 3600 )) M=$(( SS % 3600 / 60 )) S=$(( SS % 60 )) [ "$D" -gt 0 ] && echo -n "${D}:" [ "$H" -gt 0 ] && printf "%02g:" "$H" printf "%02g:%02g\n" "$M" "$S" }

Apache memory usage

Find status of all symlinks
The symlinks command can show status of all symbolic links, including which links are dangling, which symlinks point to files on other file systems, which symlinks use ../ more than necessary, which symlinks are messy (e.g. having too many slashes or dots), etc. Other useful things it can do include removing all dangling links (-d) and converting absolute links to relative links (-c). The path given must be an absolute path (which is why I used $(pwd) in the example command).

gets your public IP address


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: