Commands tagged POSIX (9)

  • 27
    grep -Fx -f file1 file2
    zarathud · 2010-05-28 14:50:14 2
  • If you have used bash for any scripting, you've used the date command alot. It's perfect for using as a way to create filename's dynamically within aliases,functions, and commands like below.. This is actually an update to my first alias, since a few commenters (below) had good observations on what was wrong with my first command. # creating a date-based ssh-key for ssh-keygen -f ~/.ssh/`date +git-$USER@$HOSTNAME-%m-%d-%g` -C '' # /home/gpl/.ssh/ # create a tar+gzip backup of the current directory tar -czf $(date +$HOME/.backups/%m-%d-%g-%R-`sed -u 's/\//#/g' <<< $PWD`.tgz) . # tar -czf /home/gpl/.backups/04-22-10-01:13-#home#gpl#.rr#src.tgz . I personally find myself having to reference date --help quite a bit as a result. So this nice alias saves me a lot of time. This is one bdash mofo. Works in sh and bash (posix), but will likely need to be changed for other shells due to the parameter substitution going on.. Just extend the sed command, I prefer sed to pretty much everything anyways.. but it's always preferable to put in the extra effort to go for as much builtin use as you can. Otherwise it's not a top one-liner, it's a lazyboy recliner. Here's the old version: alias dateh='date --help|sed "/^ *%%/,/^ *%Z/!d;s/ \+/ /g"|while read l;do date "+ %${l/% */}_${l/% */}_${l#* }";done|column -s_ -t' This trick from my [ bash_profile ] Show Sample Output

    alias dateh='date --help|sed -n "/^ *%%/,/^ *%Z/p"|while read l;do F=${l/% */}; date +%$F:"|'"'"'${F//%n/ }'"'"'|${l#* }";done|sed "s/\ *|\ */|/g" |column -s "|" -t'
    AskApache · 2010-04-21 01:22:18 5

  • 10
    grep -Fxv -f file1 file2
    zarathud · 2010-05-28 14:48:27 0
  • same as the chmod example, but should also copy extended access control list attributes. deliberately stolen from: man setfacl

    getfacl file1 | setfacl --set-file=- file2
    funky · 2010-03-31 13:36:53 2
  • There's another version on here that uses GET but some people don't have lwp-request, so here's an alternative. It's also a little shorter and should work with most youtube URLs since it truncates at the first &

    url="[Youtube URL]"; echo $(curl ${url%&*} 2>&1 | grep -iA2 '<title>' | grep '-') | sed 's/^- //'
    rkulla · 2010-04-29 02:03:36 1
  • Uses the shell builtin `declare` with the '-f' flag to output only functions to grep out only the function names. You can use it as an alias or function like so: alias shfunctions="builtin declare -f | command grep --color=never -E '^[a-zA-Z_]+\ \(\)'" shfunctions () { builtin declare -f | command grep --color=never -E '^[a-zA-Z_]+\ \(\)'; } Show Sample Output

    builtin declare -f | command grep --color=never -E '^[a-zA-Z_]+\ \(\)'
    sciro · 2018-07-23 05:24:04 0
  • Normally executing 'set' returns a vast amount of information, including the source code of every function and variable within the environment - including those that are part of the shell. By using the -o posix argument, bash runs temporarily in POSIX mode for this command, which simplifies expressions and leaves out the shell's own functions and definitions - leaving a much smaller, more useful list. Show Sample Output

    alias allvars=' ( set -o posix; set ) | less'
    incidentnormal · 2016-03-04 14:04:45 0
  • Install with `npm install unix-permissions`. Unix file permissions can take many shapes: symbolic (`ug+rw`), octal (`660`) or a list of characters (`drw-rw----`). `unix-permissions` enables using any of these (instead of being limited to a single one) with any CLI command. Show Sample Output

    unix-permissions convert.stat $(unix-permissions invert $(umask))
    ehmicky · 2019-02-05 14:06:08 0
  • This produces a parseable output of the last day of the month in future or past. Change the '-v-0m' to be a month plus or minus from the current system time. Show Sample Output

    date -j -v1d -v-0m -v-1d +'%m %d %Y'
    drewk · 2010-03-04 17:47:51 1

What's this? 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

List all NPM global packages installed

Rename files in batch

Extract all GPS positions from a AVCHD video.

Spoof your wireless MAC address on OS X to 00:e2:e3:e4:e5:e6
If you want to check that the spoof worked, type the same command as earlier: $ifconfig en1 | grep ether Now you will see: $ether 00:e2:e3:e4:e5:e6 For the wired ethernet port: $sudo ifconfig en0 ether 00:e2:e3:e4:e5:e6

Delete specific sender in mailq

make 100 directories with leading zero, 001...100, using bash3.X

Create .pdf from .doc
sudo apt-get install wv tetex-extra ghostscript

Convert CSV to JSON
Replace 'csv_file.csv' with your filename.

diff the same file in two directories.
This is useful when you're diffing two files of the same name in radically different directory trees. For example: Set $ path1='/some/long/convoluted/path/to/all/of/your/source/from/a/long/dead/machine' then $ path2='/local/version/of/same/file' then run the command. Much easier on the eyes when you're looking back across your command history, especially if you're doing the same diff over and over again.

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

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.


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: