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:
"&&" runs sed if and only if the backup completed and /bin/cp exited cleanly. Works for multiple files; just specify multiple filenames (or glob). Use -v switch for cp to play it safe.
cp options:
-p will preserve the file mode, ownership, and timestamps
-r will copy files recursively
also, if you want to keep symlinks in addition to the above: use the -a/--archive option
I used this to copy all PDFs recursively to a selected dir
It will create a backup of the filename. The advantage is that if you list the folder the backups will be sorted by date. The command works on any unix in bash.
You could start this one with
for f in *; do
BUT using the find with "-type f" ensures you only get files not any dirs you might have
It'll also create backups of the files it's overwriting
Of course, this assumes that you don't have any files with duplicated filenames in your target structure
To check if the table-of-content in a LaTeX document is up-to-date, copy it to a backup before running LaTeX and compare the new .toc to the backup. If they are identical, it is updated. If not, you need to run LaTeX again.
less symbols, tab completion.
including # export SIMPLE_BACKUP_SUFFIX="_`date +%F`" in your .bashrc provides you to easily timestamp your files
search the newest *.jpg in the directory an make a copy to newest.jpg. Just change the extension to search other files. This is usefull eg. if your webcam saves all pictures in a folder and you like the put the last one on your homepage. This works even in a directory with 10000 pictures.
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.
Find all corrupted jpeg in the current directory, find a file with the same name in a source directory hierarchy and copy it over the corrupted jpeg file.
Convenient to run on a large bunch of jpeg files copied from an unsure medium.
Needs the jpeginfo tool, found in the jpeginfo package (on debian at least).
Add this to .bashrc, then you can quickly create backups from files on current directory, but it only backups files on current directory.
useful when changing config files, coding something or just trying something stupid.
The --parents option will cause cp or mkdir to automatically create the parent directory structure.
mkdir --parents /one/two/three/dir
will create /one, /one/two, and /one/two/three as needed before creating dir. cp will copy files with their full directory structure into the target directory with this option.
Thanks to Peter Leung at:
http://linuxcommando.blogspot.com/2007/11/use-of-parents-flag-in-mkdir-and-c.html
which has good examples of usage.
./* is for copying files starting with -
.[!.]* is for copying hidden files and avoiding copying files from the parent directory.
..?* is for copying files starting with .. (avoids the directory ..)
/path/to/dir the path to the directory where the files should be copied
Can also be used as a script. Input argument is /path/to/dir
in tcsh, replace .[!.]* with .[^.]*
-t, --target-directory=DIRECTORY (copy all SOURCE arguments into DIRECTORY).
"." is current dir, maxdepth is the level, -print0 | xargs -0 fix spaces in names, -i interactive , ./ is the current dir {} actual name , and {,.bak} is the atual name + bak
Allows you to preserve your files when using cp, mv, ln, install or patch. When the target file exists, it will generate a file named XXX.~N~ (N is an auto-incremental number) instead of deleting the target file.
Copy the file with the given .extension at the source file's location. Eliminates the typing of long paths again and again.
This is a simple case of recursing through all directories, adding the '.bak' extension to every file. Of course, the 'cp $file $file.bak' could be any code you need to apply to your recursion, including tests, other functions, creating variables, doing math, etc. Simple and clean recursion.
The expansion {,} in bash will repeat the given string once for each item seperated by commas. The given command will result in the following being run:
cp /really/long/path/and/file/name /really/long/path/and/file/name-`date -I`
These can be embedded as needed, ex: rm file{1,2,3{1,2,3}} would delete the files file1, file2, file31, file32, file32, and no other files.