simple way to show free swap Show Sample Output
Removes trailing newline; colon becomes record separator and newline becomes field separator, only the first field is ever printed. Replaces empty entries with $PWD. Also prepend relative directories (like ".") with the current directory ($PWD). Can change PWD with env(1) to get tricky in (non-Bourne) scripts. Show Sample Output
I have a directory containing log files. This command delete all but the 5 latest logs. Here is how it works: * The ls -t command list all files with the latest ones at the top * The awk's expression means: for those lines greater than 5, delete.
Consider this file : laminate this file with awk hello to commandlinefu I can use awk substring to laminate words : lamin this file with hello comma Similar to http://www.commandlinefu.com/commands/view/2000/laminate-files-line-by-line Show Sample Output
remove files with access time older than a given date. If you want to remove files with a given modification time replace %A@ with %T@. Use %C@ for the modification time. The time is expressed in epoc but is easy to use any other format. Show Sample Output
It's not a big line, and it *may not* work for everybody, I guess it depends on the detail of access_log configuration in your httpd.conf. I use it as a prerotate command for logrotate in httpd section so it executes before access_log rotation, everyday at midnight.
Sometimes I need a quick visual way to determine if there is a particular server who is opening too many connections to the database machine.
If you gzip an empty file it becomes 20 bytes. Some backup checks i do check to see if the file is greater than zero size (-s flag) but this is no good here. Im sure someone has a better check than me for this? No check to see if file exists before checking it's size.
Although Exim will purge frozen (undeliverable) messages over time, the command "exim -Mrm #id#" where #id# is a particular message ID will purge a message immediately. Being lazy, I don't want to type the command for each frozen message, so I wrote the one-liner to do it for me.
This may seem like a long command, but it is great for making sure all file permissions are kept in tact. What it is doing is streaming the files in a sub-shell and then untarring them in the target directory. Please note that the -z command should not be used for local files and no perfomance increase will be visible as overhead processing (CPU) will be evident, and will slow down the copy.
You also may keep simple with, but you don't have the progress info:
cp -rpf /some/directory /other/path
Show Sample Output
xargs deals badly with special characters (such as space, ' and "). To see the problem try this: touch important_file touch 'not important_file' ls not* | xargs rm Parallel https://savannah.nongnu.org/projects/parallel/ does not have this problem.
This awk command prints a histogram of the number of times 'emergency' is the first word in a line, per day, in an irssi (IRC client) log file. Show Sample Output
Easy way to grab the IP address of a machine for easy script use. If needed a "| grep -v 127.0.0.1" at the end will suppress localhost. Show Sample Output
Finds the line number matching the regex, then passes that to BC for some math, passes that to head, and uses tail to trim off the unwanted section at the top. The whole thing is spit out to a script that can then be shared or run. Comes in handy for reading select sections from error logs.
This command, or a derivative like it, is a must-have if you're a server administrator interested in website optimization: https://kinqpinz.info/?%C2%B6=287a7ba6 Command requires Yahoo's YUI, find it here: http://developer.yahoo.com/yui/ Show Sample Output
2d6 dice:
awk 'BEGIN { srand(); a=int(rand()*6)+1; b=int(rand()*6)+1; print a " + " b " = " a+b }'
3 + 6 = 9
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: