commandlinefu.com is the place to record those command-line gems that you return to again and again.
Delete that bloated snippets file you've been using and share your personal repository with the world. 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.
You can sign-in using OpenID credentials, or register a traditional username and password.
First-time OpenID users will be automatically assigned a username which can be changed after signing in.
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:
It extracts X number of lines from file1 and dumps them to file2.Using grep with the empty string '' extracts the complete lines (i.e. no filtering takes place) and the -m flag indicates how many lines to extract out from the given file. Then using the redirect > operator we send the extracted lines to a new file.
This command will grep the entire directory looking for any files containing the list of files. This is useful for cleaning out your project of old static files that are no longer in use. Also ignores .svn directories for accurate counts. Replace 'static/images/' with the directory containing the files you want to search for.
This command shows if there are any locked AFS volumes.
The output is a list of AFS volume IDs (or nothing if there are none locked).
Find out which RPMs were installed on a particular date.
These would (naturally) include update RPMs.
This example shows searching for "Thu 05 Mar" (with grep).
Alternatively, pipe it to less so you can search inside less (with less's neat text highlighting of the search term):
rpm -qa --queryformat '%{installtime} \"%{vendor}\" %{name}-%{version}-%{release} %{installtime:date}\n' | less # (this example) search term: Thu 05 Mar
This command converts filenames with embedded spaces in the current directory replacing spaces with the underscore ("_") character.
This command will kill all processes using a directory. It's quick and dirty. One may also use a -9 with kill in case regular kill doesn't work. This is useful if one needs to umount a directory.
This adds all new files to SVN recursively. It doesn't work for files that have spaces in their name, but why would you create a file with a space in its name in the first place?
populate the auth.hosts file with a list of IP addresses that are authorized to be in use and when you run this command it will return the addresses that are pingable and not in the authorized list.
Can be combined with the "Command line Twitter" command to tweet unauthorized access.
This will let you know what filesets or fixes (if any) are missing in order to be considered "at" a given technology level in AIX.
Removes all unversioned files and folders from an svn repository. Also:
svn status --no-ignore | grep ^I | awk '{print $2}' | xargs rm -rf
will remove those files which svn status ignores. Handy to add to a script which is in your path so you can run it from any repository (a la 'svn_clean.sh').
the good:
Server: Apache/2.2.8 (Ubuntu) PHP/5.2.4-2ubuntu5.4 with Suhosin-Patch
the bad:
Server: Microsoft-IIS/6.0
and the ugly:
Server: Apache/2.2.10 (Win32) mod_ssl/2.2.10 OpenSSL/0.9.8i PHP/5.2.6
This is the result of a several week venture without X. I found myself totally happy without X (and by extension without flash) and was able to do just about anything but watch YouTube videos... so this a the solution I came up with for that. I am sure this can be done better but this does indeed work... and tends to work far better than YouTube's ghetto proprietary flash player ;-)
Replace $i with any YouTube ID you want and this will scrape the site for the _real_ URL to the full quality .FLV file on Youtube's server and will then will hand that over to mplayer (or vlc or whatever you want) to be streamed.
In some browsers you can replace $i with just a % or put this in a shell script so all YouTube IDs can be handed directly off to your media player of choice for true streaming without the need for Flash or a downloader like clive. (I do however fully recommend clive if you wish to archive videos instead of streaming them)
If any interest is shown I would be more than happy to provide similar commands for other sites. Most streaming flash players use similar logic to YouTube.
Edit: 05/03/2011 -
Updated line to work with current YouTube. It could be a lot prettier but I will probably follow up with another update when I figure out how to get rid of that pesky Grep. Sed should take that syntax... but it doesn't.
Original (no longer working) command:
mplayer -fs $(echo "http://youtube.com/get_video.php?$(curl -s $youtube_url | sed -n "/watch_fullscreen/s;.*\(video_id.\+\)&title.*;\1;p")")
Suppose you made a backup of your hard disk with dd:
dd if=/dev/sda of=/mnt/disk/backup.img
This command enables you to mount a partition from inside this image, so you can access your files directly.
Substitute PARTITION=1 with the number of the partition you want to mount (returned from sfdisk -d yourfile.img).
The large context number (-C 1000) is a bit of a hack, but in most of my use cases, it makes sure I'll see the whole log output.
grep 'HOME.*' data.txt | awk '{print $2}' | awk '{FS="/"}{print $NF}'
OR
awk '/HOME/ {print $2}' data.txt | awk -F'/' '{print $NF}'
In this example, we are having a text file that is having several entries like:
---
c1 c2 c3 c4
this is some data
HOME /dir1/dir2/.../dirN/somefile1.xml
HOME /dir1/dir2/somefile2.xml
some more data
---
for lines starting with HOME, we are extracting the second field that is a 'file path with file name', and from that we need to get the filename only and ignore the slash delimited path.
The output would be:
somefile1.xml
somefile2.xml
(In case you give a -ive - pls give the reasons as well and enlighten the souls :-) )
Explanation:
* The date command evaluated to today's date with blank padded on the left if single digit
* The grep command search and highlight today's date
* The --before-context and --after-context flags displays up to 6 lines before and after the line containing today's date; thus completes the calendar.
I have tested this command on Mac OS X Leopard and Xubuntu 8.10
recursively traverse the directory structure from . down, look for string "oldstring" in all files, and replace it with "newstring", wherever found
also:
grep -rl oldstring . |xargs perl -pi~ -e 's/oldstring/newstring'
This command kills all processes with 'SomeCommand' in the process name. There are other more elegant ways to extract the process names from ps but they are hard to remember and not portable across platforms. Use this command with caution as you could accidentally kill other matching processes!
xargs is particularly handy in this case because it makes it easy to feed the process IDs to kill and it also ensures that you don't try to feed too many PIDs to kill at once and overflow the command-line buffer.
Note that if you are attempting to kill many thousands of runaway processes at once you should use 'kill -9'. Otherwise the system will try to bring each process into memory before killing it and you could run out of memory. Typically when you want to kill many processes at once it is because you are already in a low memory situation so if you don't 'kill -9' you will make things worse