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

Display Spinner while waiting for some process to finish
alternatively, run the spinner for 5 seconds: timeout 5 bash -c 'spinner=( Ooooo oOooo ooOoo oooOo ooooO oooOo ooOoo oOooo); while true; do for i in ${spinner[@]}; do for j in seq 0 ${#i}; do echo -en "\b\b"; done; echo -ne "${i}"; sleep 0.2; done; done'

Find partition name using mount point
lsblk | grep mountpoint

list all opened ports on host

Get your outgoing IP address
should be very consistent cause it's google :-)

Get ethX mac addresses
I much prefer using /sbin/ip over /sbin/ifconfig for most everything. I find the interface and output to be much more consistent and it has many abilities that ifconfig, route, etc. do not. To get the mac address for only one interface, add 'show dev [interface]' to the 'ip link' part of the command: ip link show dev eth0 | grep 'link/ether' | awk '{print $2}' . Also, both this command and the ifconfig one do not require root access to run, so the sudo is not necessary.

get all Amazon cloud (amazonws etc) ipv4 subnets

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"

For a $FILE, extracts the path, filename, filename without extension and extension.
Useful for use in other scripts for renaming, testing for extensions, etc.

Show changed files, ignoring permission, date and whitespace changes
Only shows files with actual changes to text (excluding whitespace). Useful if you've messed up permissions or transferred in files from windows or something like that, so that you can get a list of changed files, and clean up the rest.

delete all leading and trailing whitespace from each line in file


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: