Commands tagged POSIX (9)


  • 27
    grep -Fx -f file1 file2
    zarathud · 2010-05-28 14:50:14 23
  • 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 askapache.github.com ssh-keygen -f ~/.ssh/`date +git-$USER@$HOSTNAME-%m-%d-%g` -C 'webmaster@askapache.com' # /home/gpl/.ssh/git-gplnet@askapache.github.com-04-22-10 # 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 [ http://www.askapache.com/linux-unix/bash_profile-functions-advanced-shell.html bash_profile ] Show Sample Output


    21
    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 16

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


    6
    getfacl file1 | setfacl --set-file=- file2
    funky · 2010-03-31 13:36:53 7
  • 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 &


    2
    url="[Youtube URL]"; echo $(curl ${url%&*} 2>&1 | grep -iA2 '<title>' | grep '-') | sed 's/^- //'
    rkulla · 2010-04-29 02:03:36 4
  • 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


    2
    builtin declare -f | command grep --color=never -E '^[a-zA-Z_]+\ \(\)'
    sciro · 2018-07-23 05:24:04 942
  • 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


    0
    alias allvars=' ( set -o posix; set ) | less'
    incidentnormal · 2016-03-04 14:04:45 12
  • Install with `npm install unix-permissions`. https://github.com/ehmicky/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


    -2
    unix-permissions convert.stat $(unix-permissions invert $(umask))
    ehmicky · 2019-02-05 14:06:08 389
  • 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


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

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

save stderr only to a file
taken from http://www.unix.com/shell-programming-scripting/158311-how-tee-stderr.html " What does it mean? The redirection operator n>&m makes file descriptor n to be a copy of file descriptor m. So, whe are: - Opening a new file descriptor, 3, that is a copy of file descriptor 1, the standard output; - Making file descriptor 1 a copy of file descriptor 2, the standard error output; - Making file descriptor 2 to be a copy of file descriptor 3 (the "backup" of the standard output) in a short: we swapped the standard output and the standard error output. "

Get your outgoing IP address

youtube2m3u
generate playlists from youtube ( or othre things that support yt-dlp)

Read info(1) pages using 'less' instead of GNU Texinfo
I like man pages, and I like using `less(1)` as my pager. However, most GNU software keeps the manual in the 'GNU Texinfo' format, and I'm not a fan of the info(1) interface. Just give me less. This command will print out the info(1) pages, using the familiar interface of less!

save your current environment as a bunch of defaults

Monitor all DNS queries seen by the local machine

delete files containing matching text
-r recursively -Z zero byte after each file name instead of the usual newline -l only filenames

a function to find the fastest DNS server
http://public-dns.info gives a list of online dns servers. you need to change the country in url (br in this url) with your country code. this command need some time to ping all IP in list.

Check the status of a network interface
no need for installing mii-tools, all generic tools working under archlinux.

sort lines by length


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: