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

Yet Another Rename (bash function)
Implementation of `rename` for systems on which I don't have access to it.

Select and Edit a File in the Current Directory
This command displays a simple menu of file names in the current directory. After the user made a choice, the command invokes the default editor to edit that file. * Without the break statement, the select command will loop forever * Setting the PS3 prompt is optional * If the user types an invalid choice (such as the letter q), then the variable $f will become an empty string. * For more information, look up the bash's select command

Jump to a directory, execute a command and jump back to current dir

Get the size of all the directories in current directory
OSX's BSD version of the du command uses the -d argument instead of --max-depth.

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

Backup all mysql databases to individual files on a remote server
It grabs all the database names granted for the $MYSQLUSER and gzip them to a remote host via SSH.

Upgrade pip-installed python packages

Which processes are listening on a specific port (e.g. port 80)
swap out "80" for your port of interest. Can use port number or named ports e.g. "http"

Find the package that installed a command

list with full path


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: