Commands by nnsense (8)

  • Docker's local man pages are (often) half of what you have online, so I wanted that as local man. Install lynx and run my oneliner, then use as follows: dockpage Adjust lynx's page width at will Show Sample Output


    0
    dockpage() { lynx -width=180 --dump https://docs.docker.com/v1.11/engine/reference/commandline/$1/ | sed -n '/^Usage/,/On this page/{/On this page/b;p}'; }
    nnsense · 2017-09-18 23:53:34 24
  • Usefull, for example, when many ports are exposed and the docker ps output looks cluttered. Show Sample Output


    0
    alias dockps='docker ps --format "table {{.ID}}\t{{.Image}}\t{{.Status}}\t{{.Names}}"'
    nnsense · 2017-09-18 23:46:47 19
  • Sometimes it's useful to output just the ip address. Or some other information, changing the "ipv4.addresses" in command. The power of awk! Show all possible "greps" with nmcli connection show [yourInterfaceNameHere] Show Sample Output


    2
    showip() { nmcli connection show $1|grep ipv4.addresses|awk '{print $2}' ; }
    nnsense · 2015-05-13 16:24:28 15
  • This is a common use of bind. Hitting any key after will output the key's character sequence. This makes possible using it into a bind command. So pressing ctrl+v and then F2 will output "^[[12~", once binded every time you'll press the function key F2 it will execute your command. Added the \n to make it execute it as well. Show Sample Output


    1
    bind '"<ctrl+v><functionKey>":"command\n"'
    nnsense · 2015-05-11 17:59:09 12
  • I copied this (let's be honest) somewhere on internet and I just made it as a function ready to be used as alias. It shows the 10 most used commands from history. This seems to be just another "most used commands from history", but hey.. this is a function!!! :D Show Sample Output


    1
    mosth() { history | awk '{CMD[$2]++;count++;}END { for (a in CMD)print CMD[a] " " CMD[a]/count*100 "% " a;}' | grep -v "./" | column -c3 -s " " -t | sort -nr | nl | head -n10; }
    nnsense · 2015-05-11 17:41:55 19
  • Many times I give the same commands in loop to find informations about a file. I use this as an alias to summarize that informations in a single command. Now with variables! :D Show Sample Output


    2
    fileinfo() { RPMQF=$(rpm -qf $1); RPMQL=$(rpm -ql $RPMQF);echo "man page:";whatis $(basename $1); echo "Services:"; echo -e "$RPMQL\n"|grep -P "\.service";echo "Config files:";rpm -qc $RPMQF;echo "Provided by:" $RPMQF; }
    nnsense · 2015-05-11 16:46:01 13
  • I use this as an alias to get all .service files related a single installed file/conf (if it has services, of course). For rpm based systems ;) Show Sample Output


    1
    qf2s() { rpm -ql $(rpm -qf $1)|grep -P "\.service"; }
    nnsense · 2015-05-11 16:32:16 9
  • Not really alternative, just giving a different behavior listing current directory if no directory given.


    1
    cdls() { if [[ $1 != "" ]] ; then cd $1; ls; else ls; fi };
    nnsense · 2015-05-11 15:52:09 12

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

Remote control for Rhythmbox on an Ubuntu Media PC
Note: you'll want to set up pub-key ssh auth. Gives you a quick means of changing volume/tracks/etc for rhythmbox on a remote machine. E.g.: rc --next # Play next track rc --print-playing # Grab the name rc --volume-down rc --help

ls -hog --> a more compact ls -l
I often deal with long file names and the 'ls -l' command leaves very little room for file names. An alternative is to use the -h -o and -g flags (or together, -hog). * The -h flag produces human-readable file size (e.g. 91K instead of 92728) * The -o suppresses the owner column * The -g suppresses the group column Since I use to alias ll='ls -l', I now do alias ll='ls -hog'

list block devices
Shows all block devices in a tree with descruptions of what they are.

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

rename all images in folder with prefix of date and time from exif data
imagemagick is required

Generate password

Count number of files in a directory

Create a bunch of dummy text files

Show top committers for SVN repositority for today

create an uncompressed tar file of each child directory of the current working directory
First, use find to find directories exactly one level below current directory, then create a tar file using the directory as the basename.


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: