Commands by sonic (8)

  • From the manpage: man less -X or --no-init Disables sending the termcap initialization and deinitialization strings to the terminal. This is sometimes desirable if the deinitialization string does something unnecessary, like clearing the screen. Bonus: If you want to clear the screen after viewing a file this way that had sensitive information, hit or just type clear. Since is readily available, I don't know why less bothers to automatically clear. If you're viewing the file at all, chances are you want to see the output from it after you quit. Show Sample Output


    2
    less -X /var/log/insecure
    sonic · 2016-06-24 13:53:49 16
  • The original command is great, but I often want to prepend to every line. Show Sample Output


    2
    sed -i 's/^/ls -l /' output_files.txt
    sonic · 2013-10-07 15:12:53 6
  • Prints line numbers making it easier to see long lines that wrap in your terminal and extra line breaks at the end of a file. :set nu works too. Show Sample Output


    0
    :set number
    sonic · 2013-10-07 15:03:52 6
  • If /home/sonic/archive/ was a symlink to /backup/sonic/archive it would follow the links and give you the file listing. By default find will NOT follow symbolic links. The default behavior for the find command is to treat the symlinks as literal files. I discovered this when trying to write a script run via cron to delete files with a modification time older than X days. The easiest solution was to use: /usr/bin/find -L /home/sonic/archive -name '*gz' -type f -mtime +14 -exec rm '{}' \; Show Sample Output


    -1
    find -L /home/sonic/archive -name '*gz' -type f
    sonic · 2013-10-07 14:32:22 9
  • the advantage to doing it this way is that you can adjust the max depth to get more recursive results and run it on non GNU systems. It also won't print trailing slashes, which can easily be removed, but can be slightly annoying.. You could run: # for file in `find * -maxdepth 0 -type d`;do ls -d $file;done and in the ls -d part of the command you can put in whatever parameters you want to get things like permissions, time stamps, and ownership. Show Sample Output


    0
    find * -maxdepth 0 -type d
    sonic · 2013-02-25 21:10:49 8
  • just an alternative to setting the size, this allows you to scroll up and see your previous commands in a given session but when you logout the history is not saved. That's the only advantage to doing it this way.. Show Sample Output


    0
    export HISTFILE=/dev/null
    sonic · 2013-02-18 16:37:01 4
  • To ignore aspect ratio, run: for file in *; do convert $file -resize 800x600! resized-$file; done and all images will be exactly 800x600. Use your shell of choice.. This was done in BASH. Show Sample Output


    0
    for file in *; do convert $file -resize 800x600 resized-$file; done
    sonic · 2013-02-17 21:37:14 3
  • I couldn't find this on the site and it's a useful switch. Great for large files. Show Sample Output


    2
    wget -c or wget --continue
    sonic · 2013-02-17 21:12:00 3

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

Create the directoty recursively

STAT Function showing ALL info, stat options, and descriptions
This shows every bit of information that stat can get for any file, dir, fifo, etc. It's great because it also shows the format and explains it for each format option. If you just want stat help, create this handy alias 'stath' to display all format options with explanations. $ alias stath="stat --h|sed '/Th/,/NO/!d;/%/!d'" To display on 2 lines: $ ( F=/etc/screenrc N=c IFS=$'\n'; for L in $(sed 's/%Z./%Z\n/'

doing some floating point math

ROT13 whole file in vim.
gg puts the cursor at the begin g? ROT13 until the next mov G the EOF

Open-iscsi target discovery

list file descriptors opened by a process
Useful for examining hostile processes (backdoors,proxies)

validate json
I have this saved as jsonlint chmodded +x and file.js is instead $1, but YMMV

Show a curses based menu selector
Not so much handy by itself, but very nice in shell scripts. This makes you a handy ncurses based checklist. Much like terminal installers, just use the arrow keys and hit 'Space' to adjust the selections. Returns all selected tags as strings, with no newline at the end. So, your output will be something like: "one" "two" "three" "four" "etc" For those who prefer bash expansion over gratuitious typing: $ whiptail --checklist "Simple checkbox menu" 12 35 3 $(echo {one,two,three,four}" '' 0"} ) Things to note: The height must includes the outer border and padding: add 7 to however many items you want to show up at the same time. If the status is 1, it will be selected by default. anything else, will be deselected.

display a one-liner of current nagios exit statuses. great with netcat/irccat

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" }


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: