Commands by atoponce (57)

  • This is a simple example of using proper command nesting using $() over ``. There are a number of advantages of $() over backticks. First, they can be easily nested without escapes: program1 $(program2 $(program3 $(program4))) versus program1 `program2 \`program3 \`program4\`\`` Second, they're easier to read, then trying to decipher the difference between the backtick and the singlequote: `'. The only drawback $() suffers from is lack of total portability. If your script must be portable to the archaic Bourne shell, or old versions of the C-shell or Korn shell, then backticks are appropriate, otherwise, we should all get into the habit of $(). Your future script maintainers will thank you for producing cleaner code.

    echo "The date is: $(date +%D)"
    atoponce · 2009-03-07 15:51:59 8
  • Discovering all executables on your system that can be run as another user, especially root, is critical for system security. The above command will find those files with have SUID or SGID bits set and are owned by the root user or group.

    sudo find / -type f \( -perm /4000 -a -user root \) -ls -o \( -perm /2000 -a -group root \) -ls
    atoponce · 2009-03-02 18:48:17 6
  • Rather than typing out all 10 files, you can use brace expansion to do the trick for you. This is useful for backup files, numbered files, or any files with a repeating pattern. Gives more control than 'rm file*' as I might want to keep others around.

    rm file{1..10}
    atoponce · 2009-03-02 14:42:05 2
  • When downloading RPMs from the Internet, you don't have to 'rpm -i' or 'rpm -U' to install the package. Especially, if the package has dependencies. If you have YUM setup to access an RPM repository, this command will install the downloaded package, then any dependencies through YUM that it relies on. Very handy on RPM-based systems.

    yum localinstall /path/to/package.rpm
    atoponce · 2009-03-02 14:32:23 1
  • In this case, I'm keeping an eye on /var/log/messages, but of course any file will do. When I'm following a file, I generally don't want to see anything other than what has been added due to the command or service I've executed. This keeps everything clean and tidy for troubleshooting.

    tail -n 0 -f /var/log/messages
    atoponce · 2009-03-02 14:21:18 5
  • This is a simple case of recursing through all directories, adding the '.bak' extension to every file. Of course, the 'cp $file $file.bak' could be any code you need to apply to your recursion, including tests, other functions, creating variables, doing math, etc. Simple and clean recursion.

    find . -type f | while read file; do cp $file ${file}.bak; done
    atoponce · 2009-03-01 23:42:49 5
  • Useful mainly for debugging or troubleshooting an application or system, such as X11, Apache, Bind, DHCP and others. Another useful switch that can be combined with -mmin, -mtime and so forth is -daystart. For example, to find files that were modified in the /etc directory only yesterday: sudo find /etc -daystart -mtime 1 -type f

    sudo find / -mmin 60 -type f
    atoponce · 2009-03-01 23:03:31 1
  •  < 1 2 3

What's this? 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

Play radio stream with mplayer
Above command will play Virgin Radio Dubai

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

Install pip with Proxy
Installs pip packages defining a proxy

Fastest Sort. Sort Faster, Max Speed
sort is way slow by default. This tells sort to use a buffer equal to half of the available free memory. It also will use multiple process for the sort equal to the number of cpus on your machine (if greater than 1). For me, it is magnitudes faster. If you put this in your bash_profile or startup file, it will be set correctly when bash is started. $ sort -S1 --parallel=2 /dev/null && alias sortfast='sort -S$(($(sed '\''/MemF/!d;s/[^0-9]*//g'\'' /proc/meminfo)/2048)) $([ `nproc` -gt 1 ]&&echo -n --parallel=`nproc`)' Alternative $ echo|sort -S10M --parallel=2 &>/dev/null && alias sortfast="command sort -S$(($(sed '/MemT/!d;s/[^0-9]*//g' /proc/meminfo)/1024-200)) --parallel=$(($(command grep -c ^proc /proc/cpuinfo)*2))"

find duplicate messages in a Maildir
# find assumes email files start with a number 1-9 # sed joins the lines starting with " " to the previous line # gawk print the received and from lines # sort according to the second field (received+from) # uniq print the duplicated filename # a message is viewed as duplicate if it is received at the same time as another message, and from the same person. The command was intended to be run under cron. If run in a terminal, mutt can be used: mutt -e "push otD~=xq" -f $folder

Remove duplicate entries in a file without sorting.
Using awk, find duplicates in a file without sorting, which reorders the contents. awk will not reorder them, and still find and remove duplicates which you can then redirect into another file.

Quickly Encrypt a file with gnupg and email it with mailx
This is a quick and easy way of encrypting files in a datastream, without ever really creating an output file from gpg. Useful with cron also, when file(s) have to be sent based on a set schedule.

Use md5sum to check your music and movie files. Also use diff.
This is a beginning script. You can create a file with > filename. You can also use diff to compare output run at different times to verify no change in your files. I apologize in advance if this is too simple. For some it should be a start.

Quickly create an alias for changing into the current directory

list block devices
Shows all block devices in a tree with descruptions of what they are.

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.


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: