Recursively rename .JPG to .jpg using standard find and mv. It's generally better to use a standard tool if doing so is not much more difficult.
You could do the following, however, brace expansion with {} is not defined in POSIX, and therefore not guaranteed to work in all shells. But, if it does, it's more convenient (although it's certainly not less typing):
cp -r {*,.??*} /dest
Sometimes there are times when I need to cp(1), mv(1) or rm(1) files recursively, but don't want to traverse the previous directory by following ../../../../ etc out of the current directory. This command prevents that. The secret sauce is ".??*". The file globbing ensures that it must start with a dot, and be followed by at least two characters. So, three characters must exist in the filename, which eliminates "." and "..".
A powerfull way to rename file using sed groups. & stand for the matched expression. \1 referes to the first group between parenthesis. \2 to the second. Show Sample Output
Sometimes in a hurry you may move or copy a file using an already existent file name. If you aliased the cp and mv command with the -i option you are prompted for a confirmation before overwriting but if your aliases aren't there you will loose the target file! The -b option will force the mv command to check if the destination file already exists and if it is already there a backup copy with an ending ~ is created.
FILENAME=nohup.out mv -iv $FILENAME{,.$(stat -c %Y $FILENAME)} does it help ? Show Sample Output
Note that the -i will not help in a script. Proper error checking is required. Show Sample Output
Prior to working on/modifying a file, use the 'install -m' command which can both copy files, create directories, and set their permissions at the same time. Useful when you are working in the public_html folder and need to keep the cp'd file hidden. Show Sample Output
if you want to move with command mv large list of files than you would get following error /bin/mv: Argument list too long alternavite with exec: find /source/directory -mindepth 1 -maxdepth 1 -name '*' -exec mv {} /target/directory \; Show Sample Output
Useful if non-ascii characters in filenames have been improperly encoded. Replace "PROBLEM" with the incorrect characters (e.g. 'é'), and "FIX" with the correct ones (e.g. '?').
rename file name with fixed length nomeric format pattern Show Sample Output
Give files a random name (don't ask why :-) The function will rename files but maintain their extensions. BUG: If a file doesn't have an extension it will end up with a dot at the end of the name. The parameter '8' for pwgen controls the length of filenames - eight random characters. Show Sample Output
replace all "?" characters in filename to underscore Show Sample Output
Renames duplicates from MusicBrainz Picard, so you get the latest copy and not a bunch of duplicates. Show Sample Output
easier way to recursively change files to lowercase using rename instead
Avoid clobbering files by either overwriting due to name collisions or by assuming the command worked and deleting the target directory.
Rename all mp4 files with crc32 information. Show Sample Output
Handles spaces in file names and directories. Optionally change directories as well by pipe to tr from dirname.
icp and imv, interactive versions of cp and mv, will prompt the user for the new filename. These tools are from rename-utils package.
Find all books on my systems and move them into folder. The -0 switches are to handle spaces etc. in the filenames. Why would you need this? Locate uses an index, so it's super quick, and xargs is more elegant than a for loop.
rename all dirs with "?" char in name, leave spaces and () in place Show Sample Output
I had trouble with accent I could do a simple mv by hand but it is not efficient. I found this online http://www.unix.com/shell-programming-and-scripting/158635-remove-spanish-accent-file-name.html but I could not specify the accented letter direcly because it is not in the same encoding as my cli so I changed the char for their octal value. to add accent I use this table http://linux.about.com/library/cmd/blcmdl7_iso_8859-1.htm and add the values to the tr part. the other "duplicates" where not working for me. comment to help me better this script. :) Show Sample Output
Works with any file name: space, ', " and even \n is OK. The code in {= =} is a perl expression.
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: