Tag Info

New answers tagged

0

In general case use perl rename as following: rename -n 's/^(.*-).*(NBC.*$)/$1safe$2/' * or for your specific pattern use: rename -n 's/#U00a9/safe/' * If you check the result of renames, remove the -n option to perform actual renaming.


0

The more easy way is use bash substitution in this way: for i in $(find . -name '*IMG*');do mv -v $i ${i//IMG/RG}; done ‘./IMG001.img’ -> ‘./RG001.img’


0

You can make it pure BASH: netikras@netikras-netbook /tmp $ ls -l /tmp/*.*season.*episode.*avi -rw-r--r-- 1 netikras netikras 0 Grd 16 10:29 /tmp/my.program.name.season.05.episode.07.-.title.avi -rw-r--r-- 1 netikras netikras 0 Grd 16 10:29 /tmp/my.program.name.season.05.episode.32.-.title.avi -rw-r--r-- 1 netikras netikras 0 Grd 16 10:29 ...


3

TL;DR I hope this is not confusing @.@ rename -n 's/^((\w+\.+){3})(.).*\.(.*)\.(.).*\.(.*)\.\-(\..*)$/$1$3$4$5$6$7/' * \w+ matches one or more word characters, i.e. [a-zA-Z0-9_]+ [1] \.+ matches one or more dot(.) character [2] Note that \. matches the . character. We need to use \. to represent . as . has special meaning in regex. The \ is known as ...


0

Try doing this with perl's rename : rename -n 's/ (.*?s)eason\.(\d{2})\.episode\.(\d{2})\.-\.(.*\.avi) /$1$2e$3.$4/x ' my.program.name* Once you are satisfied that this does what you want, remove the -n to actually perform the renaming.


1

The following uses data.csv as a link to the requested file to keep status between iterations. # check to see if an argument is given if [ "$#" -ne 1 ]; then echo "Illegal number of parameters" exit fi # check if ran before if so move that to processed/ directory if [ -h "data.csv" ]; then prev=`readlink data.csv` echo ...


1

If the file names have no newlines, you can find the first file to process in a bash script by using: first=$(ls --sort=version *.csv | head -1) ln -s "$first" data.csv however before you rename that file you have to make sure and old existing one is out of the way: #! /bin/bash if [ -e data.csv ] ; then mv $(readlink data.csv) backup_directory rm ...


1

You can use the -l option of the cp command, which creates hard links of files on the same filesystem instead of full-data copies. The following command copies the folder source/folder to a parent folder (destination) which already contains a directory with the name folder. cp -rl source/folder destination rm -r source/folder You may also want to use the ...


0

You can make simple script in home folder(or any folder other than the folder which contains the files you are intending to move). The script will be like this: #!/bin/bash for var in ./* do if [ -f "$var" ] then mv "$var" /home/user/"$var".backup1 fi done run this script inside the folder from which you are intending to move files i.e. by cd <the ...


1

The simplest route, IMHO, is to use a variable: a=file.csv; mv "$a" ~user/"$a"_backup You can avail of tab completion with variables, both while setting them and while using them.


0

Another solution. A little crude, but this is going to work if all the original files are going to have the extension .csv and if you want to move all the .csv files from the current directory. for i in *.csv; do mv $i /home/user; rename .csv .csv_backup1 /home/user/*.csv; done Just change the 'user' for each users when needed.


1

In bash, you could try the following: Type mv file1. Press Ctrl-w enough times to delete file1. Press Ctrl-y to paste file1 back. Type /home/user/. Press Ctrl-y to paste file1. Type the rest: _backup


2

You could use a bash or ksh function added in your shell rc file : mymv(){ echo mv "$1" "$2/${1##*/}_$3"; } mymv file.csv /home/user backup1 remove the echo when tests are done


3

Needing only one command is a hard thing to achieve with unix philosophy in mind. On the other hand: you can rule major parts of your world using one-liners. First fix the configuration files in sites-available with the script from the question, then use the following code to create new symlinks in sites-enabled. cd /etc/apache2/sites-enabled find . ...


0

Personally I love using perl-rename for such tasks. For instance, I'd use perl-rename 's:_: :g' file_name_here to change all underscores to spaces, resulting in file name here. You can think of it as a sed rename thing :)


2

Try: rename -n 'y/+/ /' * y is used for translating characters from one set to another. Consider the example from man rename: To translate uppercase names to lower, you'd use rename 'y/A-Z/a-z/' * The -n is used for testing out the expression. Once you're satisfied with the results, run rename without it to perform the actual renaming. I ...


1

You could also use mv to rename files. Copy and paste this into terminal or turn it into a script: for f in *; do # check if its a file if [[ -f "$f" ]]; then new_name=$(echo "$f" | sed 's/+/ /g') # replace this echo with mv echo "$f" "$new_name" fi done Replace the second echo with mv if you are satisfied with the ...


4

Here is the rename command: rename -n 'our $i=2;s/^(\d+)-(\d+)/sprintf("$1-%04d", $i*$2)/e' *.png Result: 1-001.png renamed as 1-0002.png 1-002.png renamed as 1-0004.png 1-003.png renamed as 1-0006.png 1-004.png renamed as 1-0008.png 1-005.png renamed as 1-0010.png ... 2-001.png renamed as 2-0002.png 2-002.png renamed as 2-0004.png 2-003.png renamed as ...


0

Working under the assumption that you want to multiply each page number by 2, #!/bin/sh tmpext=tmpext # temporary extension to avoid clobbering existing files # double the page number and change .png to tmpext for page in ./*-[[:digit:]][[:digit:]][[:digit:]].png; do vol=${page%-*} num=${page#$vol-} num=${num%.png} zeroes=${num%%[!0]*} ...


0

Here is a script that worked for me. I prefer mv over rsync, so I use Jewel and Jonathan Mayer's solutions. #!/bin/bash # usage source1 .. sourceN dest length=$(($#-1)) sources=${@:1:$length} DEST=$(readlink -f ${!#}) for SRC in $sources; do pushd $SRC; find . -type d -exec mkdir -p ${DEST}/{} \; find . -type f -exec mv {} ${DEST}/{} \; ...


0

You are not using regular expressions correctly. tes* means te with any number of ss following it, so test-file-1 will be renamed to file 1t-file-1: $ rename -n 's/tes*/file 1/' * test-file-1 renamed as file 1t-file-1 Similarly, ^* will match the empty string appearing at the start, so in effect it's like ^, but with a an inifinite loop: $ rename -n ...


2

To squash multiple hyphens (one hyphen followed by one or more hyphens) into a single one for all files in the current directory use: rename 's/--+/-/g' -- * The -- is important if files start with a hyphen, otherwise they would be interpreted as command line arguments. The * expands to the list of files in the current directory.



Top 50 recent answers are included