Commands by alperyilmaz (22)

  • When I'm testing some scripts or programs, they end up using more memory than anticipated. In that case, computer nearly halts due to swap space usage, and sometimes I have to press Magic SysRq+REISUB to reboot. So, I was looking for a way to limit memory usage per script and found out that ulimit can limit memory. If you run it this way: $ ulimit -v 1000000 . $ scriptname Then the new memory limit will be valid for that shell. I think changing the limit within a subshell is much more flexible and it won't interfere with your current shell ulimit settings. note: -v 1000000 corresponds to approximately 1GB of RAM


    2
    (ulimit -v 1000000; scriptname)
    alperyilmaz · 2011-01-27 21:30:59 7
  • An alternative which does not require to be root


    2
    echo <percentage> | sudo dd of=/proc/acpi/video/VGA/LCD/brightness
    alperyilmaz · 2011-01-05 03:57:58 7
  • If you want to decompress the files from an archive to current directory by stripping all directory paths, use --transform option to strip path information. Unfortunately, --strip-components option is good if the target files have same and constant depth of folders. The idea was taken from http://www.unix.com/solaris/145941-how-extract-files-tar-file-without-creating-directories.html Show Sample Output


    1
    tar --transform 's#.*/\([^/]*\)$#\1#' -xzvf test-archive.tar.gz
    alperyilmaz · 2010-11-29 23:16:57 6
  • paste one file at a time instead of in parallel Show Sample Output


    2
    paste --serial file1 file2 file3
    alperyilmaz · 2010-10-27 08:17:41 6
  • Style analyses the surface characteristics of the writing style of a document. It prints various readability grades, length of words, sentences and paragraphs. It can further locate sentences with certain characteristics. If no files are given, the document is read from standard input. style is part of "diction" package Show Sample Output


    2
    style TEXT-FILE
    alperyilmaz · 2010-10-27 08:07:04 32
  • if you're using wildcards * or ? in your command, and if you're deleting, moving multiple files, it's always safe to see how those wildcards will expand. if you put "echo" in front of your command, the expanded form of your command will be printed. It's better safe than sorry. Show Sample Output


    11
    echo rm *.txt
    alperyilmaz · 2010-10-27 07:26:26 7
  • Show all columns except 5th. This might help you save some typing if you are trying to exclude some columns from the output.


    24
    cut -f5 --complement
    alperyilmaz · 2010-10-21 20:21:07 15
  • Most of the "most used commands" approaches does not consider pipes and other complexities. This approach considers pipes, process substitution by backticks or $() and multiple commands separated by ; Perl regular expression breaks up each line using | or < ( or ; or ` or $( and picks the first word (excluding "do" in case of for loops) note: if you are using lots of perl one-liners, the perl commands will be counted as well in this approach, since semicolon is used as a separator Show Sample Output


    4
    history | perl -F"\||<\(|;|\`|\\$\(" -alne 'foreach (@F) { print $1 if /\b((?!do)[a-z]+)\b/i }' | sort | uniq -c | sort -nr | head
    alperyilmaz · 2010-04-08 13:46:09 5
  • In this example, file contains five columns where first column is text. Variance is calculated for columns 2 - 5 by using perl module Statistics::Descriptive. There are many more statistical functions available in the module. Show Sample Output


    1
    perl -MStatistics::Descriptive -alne 'my $stat = Statistics::Descriptive::Full->new; $stat->add_data(@F[1..4]); print $stat->variance' filename
    alperyilmaz · 2010-04-02 21:16:12 7
  • Useful tool to test if all speaker channels are working properly. speaker-test is part of alsa-utils package Show Sample Output


    5
    speaker-test -D plug:surround51 -c 6 -l 1 -t wav
    alperyilmaz · 2009-11-05 02:57:46 3
  • sed can be used deleting the last line and with -i option, there's no need to for temp files, the change is made on the actual file


    1
    for f in *.html; do sed '$d' -i "$f"; done
    alperyilmaz · 2009-10-12 14:46:43 4
  • This command might not be useful for most of us, I just wanted to share it to show power of command line. Download simple text version of novel David Copperfield from Poject Gutenberg and then generate a single column of words after which occurences of each word is counted by sort | uniq -c combination. This command removes numbers and single characters from count. I'm sure you can write a shorter version. Show Sample Output


    -4
    wget -q -O- http://www.gutenberg.org/dirs/etext96/cprfd10.txt | sed '1,419d' | tr "\n" " " | tr " " "\n" | perl -lpe 's/\W//g;$_=lc($_)' | grep "^[a-z]" | awk 'length > 1' | sort | uniq -c | awk '{print $2"\t"$1}'
    alperyilmaz · 2009-05-04 16:00:39 11
  • perror should be installed if mysql-server package is installed Show Sample Output


    1
    perror NUMBER
    alperyilmaz · 2009-03-31 19:19:44 4
  • This command will sort the contents of FILENAME by redirecting the output to individual .txt files in which 3rd column will be used for sorting. If FILENAME contents are as follows: foo foo A foo bar bar B bar lorem ipsum A lorem Then two files called A.txt and B.txt will be created and their contents will be: A.txt foo foo A foo lorem ipsum A lorem and B.txt will be bar bar B bar


    2
    awk '{print > $3".txt"}' FILENAME
    alperyilmaz · 2009-03-31 15:14:13 6
  • By time thumbnail images in ~/thumbnails take up too much space, this command will help deleting old ones. Find options explained: -type f : find files only, not directories -atime +30 : last accessed more than 30 days ago


    1
    find ~/.thumbnails/ -type f -atime +30 -print0 | xargs -0 rm
    alperyilmaz · 2009-03-30 04:23:07 13
  • xclip -o > /tmp/spell.tmp # Copy clipboard contents to a temp file aspell check /tmp/spell.tmp # Run aspell on that file cat /tmp/spell.tmp | xclip # Copy the results back to the clipboard, so that you can paste the corrected text I'm not sure xclip is installed in most distributions. If not, you can install x11-apps package


    2
    xclip -o > /tmp/spell.tmp; aspell check /tmp/spell.tmp ; cat /tmp/spell.tmp | xclip
    alperyilmaz · 2009-03-26 00:49:59 7
  • When you run a memory intensive application (VirtualBox, large java application, etc) swap area is used as soon as memory becomes insufficient. After you close the program, the data in swap is not put back on memory and that decreases the responsiveness. Swapoff disables the swap area and forces system to put swap data be placed in memory. Since running without a swap area might be detrimental, swapon should be used to activate swap again. Both swapoff and swapon require root privileges.


    10
    swapoff -a ; swapon -a
    alperyilmaz · 2009-03-25 03:30:41 16
  • Leading zeros might help correct sorting and they can be removed by sed after sorting Show Sample Output


    2
    sed 's/\b\(0*\)//g' filename
    alperyilmaz · 2009-03-24 20:19:42 10
  • Does not necessarily require a file to process, it can be used in a pipe as well: cat filename | sed -e :a -e 's/\(.*[0-9]\)\([0-9]\{3\}\)/\1,\2/;ta' I don't remember where I copy/pasted this from, I wish I credited the original author Show Sample Output


    3
    sed -e :a -e 's/\(.*[0-9]\)\([0-9]\{3\}\)/\1,\2/;ta' filename
    alperyilmaz · 2009-03-24 20:06:02 6
  • -N removes header -s removes separator chars -r raw output After using these options, the MySQL ouptut can be used with pipes very easily Show Sample Output


    8
    mysql DATABASE -N -s -r -e 'SQL COMMAND'
    alperyilmaz · 2009-03-24 19:53:46 5
  • Useful to detect number of tabs in an empty line, DOS newline (carriage return + newline). A tool that can help you understand why your parsing is not working. Show Sample Output


    4
    cat -v -t -e
    alperyilmaz · 2009-03-24 19:29:03 11
  • The file .my.cnf located at user's home directory is used for mysql login. If this file exists, then mysql -uYOURUSERNAME -pYOURPASSWORD database -e 'SOME SQL COMMAND' can be replaced with mysql database -e 'SOME SQL COMMAND' It saves you from typing! This is valid for mysqladmin and mysqldump commands as well. Show Sample Output


    0
    echo -e "[client]\nuser = YOURUSERNAME\npassword = YOURPASSWORD" > ~/.my.cnf
    alperyilmaz · 2009-03-24 19:05:39 10

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

Convert Shell Text to Upper/Lower Case

External IP (raw data)
can be used in script like : echo $(wget -qO- http://utils.admin-linux.fr/ip.php)

Create .pdf from .doc
sudo apt-get install wv tetex-extra ghostscript

Automatically find and re-attach to a detached screen session
-RR option is used to resume the first appropriate detached screen session

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

Mount a temporary ram partition
Makes a partition in ram which is useful if you need a temporary working space as read/write access is fast. Be aware that anything saved in this partition will be gone after your computer is turned off.

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

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

Convert files from DOS line endings to UNIX line endings
Here "^M" is NOT "SHIFT+6" and "M". Type CTRL+V+M to get it instead. Its shortest and easy. And its sed!, which is available by default in all linux flavours.. no need to install extra tools like fromdos.

Find the package that installed a command


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: