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
An alternative which does not require to be root
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
paste one file at a time instead of in parallel Show Sample Output
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
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
Show all columns except 5th. This might help you save some typing if you are trying to exclude some columns from the output.
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
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
Useful tool to test if all speaker channels are working properly. speaker-test is part of alsa-utils package Show Sample Output
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
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
perror should be installed if mysql-server package is installed Show Sample Output
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
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
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
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.
Leading zeros might help correct sorting and they can be removed by sed after sorting Show Sample Output
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
-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
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
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
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.
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
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: