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 7
  • 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 7
  • 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 10
  • 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 9
  • 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 5
  • 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 4
  • 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 4

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

print all network interfaces' names and IPv4 addresses
ifconfig can't properly display interface's name longer 9 symbols,also it can't show IPs added thru ip command, so 'ip' should be used instead. This alias properly shows long names, bond interfaces and all interface aliases. loopback interface is ignored, since its IP is obvious

Get your external IP address ( 10 characters long )
Shortest url to a external IP-service, 10 characters.

Find usb device in realtime
Using this command you can track a moment when usb device was attached.

Disable system bell in an X session
Execute this command in a terminal to disable the system-bell during X-session lifetime.

File rotation without rename command
Rotates log files with "gz"-extension in a directory for 7 days and enumerates the number in file name. i.e.: logfile.1.gz > logfile.2.gz I needed this line due to the limitations on AIX Unix systems which do not ship with the rename command.

List last opened tabs in firefox browser
Tuned for short command line - you can set the path to sessionstore.js more reliable instead of use asterixes etc. Usable when you are not at home and really need to get your actual opened tabs on your home computer (via SSH). I am using it from my work if I forgot to bookmark some new interesting webpage, which I have visited at home. Also other way to list tabs when your firefox has crashed (restoring of tabs doesn't work always). This script includes also tabs which has been closed short time before.

mtr, better than traceroute and ping combined
mtr combines the functionality of the traceroute and ping programs in a single network diagnostic tool. As mtr starts, it investigates the network connection between the host mtr runs on and HOSTNAME. by sending packets with purposly low TTLs. It continues to send packets with low TTL, noting the response time of the intervening routers. This allows mtr to print the response percentage and response times of the internet route to HOSTNAME. A sudden increase in packetloss or response time is often an indication of a bad (or simply over‐loaded) link.

Simultaneously running different Firefox profiles
After running $ firefox -ProfileManager and creating several different profiles, use this command to run multiple Firefox profiles simultaneously.

Check if you work on a virtual/physical machine in Linux
Command used to know if we are working on a virtual or physical machine. This command will use the dmidecode utility to retrieve hardware information of your computer via the BIOS. Run this command as root or with sudo.

Less a grep result, going directly to the first match in the first file
Really useful way to combine less and grep while browsing log files. I can't figure out how to make it into a true oneliner so paste it into a script file called lgrep: Usage: lgrep searchfor file1 [file2 file3] Advanced example (grep for an Exception in logfiles that starts with qc): lgrep Exception $(find . -name "qc*.log")


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: