This command converts filenames with embedded spaces in the current directory replacing spaces with the underscore ("_") character. Show Sample Output
This example calculates the averages of column one and column two of "file.dat". It can be easily modified if other columns are to be averaged.
The arguments of "seq" indicate the starting value, step size, and the end value of the x-range. "awk" outputs (x, f(x)) pairs and pipes them to "graph", which is part of the "plotutils" package.
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
Use the find command to match certain files and summarise their total size in KBytes. Show Sample Output
Change ~/tmp to the destination directory, such as your mounted media. Change -n20 to whatever number of files to copy. It should quit when media is full. I use this to put my most recently downloaded podcasts onto my phone.
ip address show | grep eth0 | sed '1d' | awk '{print $2}'
does the same, but shows network-prefix.
exported files will get a .r23 extension (where 23 is the revision number)
This will extract all of the urls from a firefox session (including urls in a tab's history). The sessionstore.js file is in ~/.mozilla/firefox/{firefox profile}
Inspired by http://www.commandlinefu.com/commands/view/2573/remove-all-files-previously-extracted-from-a-tar.gz-file. .... yet for zip files
Handy when you need to create a list of files to be updated when subversion is not available on the remote host. You can take this tar file, and upload and extract it where you need it. Replace M and N with the revisions specific to yours. Make sure you do this from an updated (svn up) working directory.
a variation of avi4now's command - thanks by the way!
converts any number on the 'stdin' to SI notation. My version limits to 3 digits of precious (working with 10% resistors). Show Sample Output
This command changes all filename and directories within a directory tree to unaccented ones. I had to do this to 'sanitize' some samba-exported trees. The reason it works might seem a little difficult to see at first - it first reverses-sort by pathname length, then it renames only the basename of the path. This way it'll always go in the right order to rename everything. Some notes: 1. You'll have to have the 'unaccent' command. On Ubuntu, just aptitude install unaccent. 2. In this case, the encoding of the tree was UTF-8 - but you might be using another one, just adjust the command to your encoding. 3. The program might spit a few harmless errors saying the files are the same - not to fear.
Shell timeout variables (TMOUT) can be very liberal about what is classified as 'activity', like having an editor open. This command string will terminate the login shell for an user with more than a day's idle time.
After executing this, click on a window you want to track X Window events in. Explaination: "xev will track events in the window with the following -id, which we get by greping window information obtained by xwininfo" Show Sample Output
inputfile.txt is a space-separated textfile, 1st column contains the items (id) I want to put into my SQL statement.
39 = charactercode for single tick '
1 = first column
If inputfile.txt is a CSV-file separated by "," use FS= to define your own field-separator:
awk 'BEGIN {FS=","; }{printf "select * from table where id = %c%s%c;\n",39,$1,39; }' inputfile.txt
Show Sample Output
Just one character longer than the sed version ('FNR==5' versus -n 5p). On my system, without using "exit" or "q", the awk version is over four times faster on a ~900K file using the following timing comparison:
testfile="testfile"; for cmd in "awk 'FNR==20'" "sed -n '20p'"; do echo; echo $cmd; eval "$cmd $testfile"; for i in {1..3}; do time for j in {1..100}; do eval "$cmd $testfile" >/dev/null; done; done; done
Adding "exit" or "q" made the difference between awk and sed negligible and produced a four-fold improvement over the awk timing without the "exit".
For long files, an exit can speed things up:
awk 'FNR==5{print;exit}' <file>
Sometimes, you don't really care about all the other information that ifconfig spits at you (however useful it may otherwise be). You just want an IP. This strips out all the crap and gives you exactly what you want. 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: