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.
If you have a new feature suggestion or find a bug, please get in touch via http://commandlinefu.uservoice.com/
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.
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:
SImply type "cd" and press enter
This example is taken from Cygwin running on Win7Ent-64. Device names will vary by platform.
Both commands resulted in identical files per the output of md5sum, and ran in the same time down to the second (2m45s), less than 100ms apart. I timed the commands with 'time', which added before 'dd' or 'readom' gives execution times after the command completes. See 'man time' for more info...it can be found on any Unix or Linux newer than 1973. Yeah, that means everywhere.
readom is supposed to guarantee good reads, and does support flags for bypassing bad blocks where dd will either fail or hang.
readom's verbosity gave more interesting output than dd.
On Cygwin, my attempt with 'readom' from the first answer actually ended up reading my hard drive. Both attempts got to 5GB before I killed them, seeing as that is past any CD or standard DVD.
'bs=1M' says "read 1MB into RAM from source, then write that 1MB to output. I also tested 10MB, which shaved the time down to 2m42s.
'if=/dev/scd0' selects Cygwin's representation of the first CD-ROM drive.
'of=./filename.iso' simply means "create filename.iso in the current directory."
'-v' says "be a little noisy (verbose)." The man page implies more verbosity with more 'v's, e.g. -vvv.
dev='D:' in Cygwin explicitly specifies the D-drive. I tried other entries, like '/dev/scd0' and '2,0', but both read from my hard drive instead of the CD-ROM. I imagine my LUN-foo (2,0) was off for my system, but on Cygwin 'D:' sort of "cut to the chase" and did the job.
f='./filename.iso' specifies the output file.
speed=2 simply sets the speed at which the CD is read. I also tried 4, which ran the exact same 2m45s.
retries=8 simply means try reading a block up to 8 times before giving up. This is useful for damaged media (scratches, glue lines, etc.), allowing you to automatically "get everything that can be copied" so you at least have most of the data.
Use dots to cd down directories instead of having to remember all of the pesky back slashes!
Better yet, works on even and odd number of dots! Now, just estimate how far down you want to traverse.
if you cd into a directory then cd into another directory somewhere else then you run the cd - command you will go to the previous directory you was in!! To go back to the other directory just run it again. So if you are working in 2 different directories then this is the perfect command for you.
Only requirement is bash shell. No functions needed.
The comp.unix.shell posting by St?phane Chazelas also lists the following offsets:
type 32768 (1 byte)
id 32769 (5 bytes)
version 32774 (1 byte)
system_id 32776 (32 bytes)
volume_id 32808 (32 bytes)
volume_space_size 32848 (8 bytes)
escape_sequences 32856 (32 bytes)
volume_set_size 32888 (4 bytes)
volume_sequence_number 32892 (4 bytes)
logical_block_size 32896 (4 bytes)
path_table_size 32900 (8 bytes)
type_l_path_table 32908 (4 bytes)
opt_type_l_path_table 32912 (4 bytes)
type_m_path_table 32916 (4 bytes)
opt_type_m_path_table 32920 (4 bytes)
root_directory_record 32924 (34 bytes)
volume_set_id 32958 (128 bytes)
publisher_id 33086 (128 bytes)
preparer_id 33214 (128 bytes)
application_id 33342 (128 bytes)
copyright_file_id 33470 (37 bytes)
abstract_file_id 33507 (37 bytes)
bibliographic_file_id 33544 (37 bytes)
creation_date 33581 (17 bytes)
modification_date 33598 (17 bytes)
expiration_date 33615 (17 bytes)
effective_date 33632 (17 bytes)
file_structure_version 33649 (1 byte)
application_data 33651 (512 bytes)
Since none of the systems I work on have readlink, this works cross-platform (everywhere has perl, right?).
Note: This will resolve links.
I did not like two things in the submitted commands and fixed it here:
1) If I do cd - afterwards, I want to go back to the directory I've been before
2) If I call up without argument, I expect to go up one level
It is sad, that I need eval (at least in bash), but I think it's safe here.
eval is required, because in bash brace expansion happens before variable substitution, see http://rosettacode.org/wiki/Repeat_a_string#Using_printf
I realise that this is just a reiteration of another entry (regardless of whether I came up with all this all by myself), but I would like present my additional alias' in context as a method of managing your directories. Rather convenient.
An easy method to generate ISOs from CD/DVD media.
as alternative to cd $OLDPWD
Use shopt -s cdspell to correct the typos in the cd command
manage directory stack
switch to previous directory or toggle
Creates a directory and then cds into it directly
`up 3` will climb the directory tree by three steps. `up asdf` will do nothing, and returns exit code 1 as an error should.
I wrote this a long time ago, wondering why this wasn't floating around somewhere out there (at least not where I could find).. this seems much more simple than multiple aliases and can cd out of directories easier.
Change n directories up, without parameters change one up
This is like `cd -` but doesn't echo the new directory name, which is preferable (to me) for an alias, e.g.
alias cdo="cd $OLDPWD"
work for execute file
Also resolves symlinks, showing the full path of the link target
Sometimes you need the full path to your script, regardless of how it was executed (which starting directory) in order to maintain other relative paths in the script.
If you attempt to just use something simple like:
you will only get the relative path depending on where you first executed the script from.
You can get the relative path to the script (from your starting point) by using dirname, but you actually have to change directories and print the working directory to get the absolute full path.