Tag Info

New answers tagged

1

You can use prename (rename) perl script comes with perl package in Debian/Ubuntu. It is actually a fork of the original rename script. To solve your issue you can do: rename -n 's/^([^[:digit:]]+)([^.]+)/$2\.$1/' *.doc -n is for dry-run, if you are satisfied with the changes remove -n. Test : $ rename -n 's/^([^[:digit:]]+)([^.]+)/$2\.$1/' *.doc ...


2

With bash: for f in XYZ*/*; do mv -v "$f" "${f%/*}/${f:0:5}${f##*/}"; done The for loop runs trough all XYZ* directories. Then the mv command renames the files. Where: $f is the original filename ${f%/*} is the directory name ${f:0:5} is the prefix ${f##*/} is the original filename


0

You can run this command which just shows you what it would do: ls -d XYZ*/* | sed -n s'|\(XYZ[0-9][0-9]\)\([^/]*\)/\(\2_.*\)|mv & \1\2/\1\3|p' | cat and if you like the commands to run, replace cat by sh.


2

With zsh: autoload zmv # best in ~/.zshrc zmv '(XYZ??)(*)/(*)' '$1$2/$1$3'


2

Use this: c=132 for f in *; do mv -v "$f" "enum-$(printf '%0*d' 5 $c)" c=$(($c+1)) done The c=<your_starting_number>; I assumed 132 as in your question. Then the for loop runs trough all the files in the current directory. For every file the mv command is called. the printf utility prints the new filename with leading zeros. And finally the ...


3

If your rename is the Perl one: rename 's/[\/\\?*:><|"]//g' *.extension


0

To rename all files with .foo.bar to .bar in the current directory and its subdirectories: rename 's/\.foo\.bar/\.bar/' * */* Here, rename is the rename utility from the perl package. On some systems, it may be called prename. (There is, unfortunately, also a rename executable that some systems have installed from the util-linux package. It is ...


1

You can use parameter expansion mechanism shopt -s globstar for file in **/*foo.bar; do prefix="${file%.foo*}" suffix="${file##*.foo}" mv -v -- "$file" "$prefix$suffix" done The ${file%.foo*} removes matching suffix (leaving only prefix), and ${file#*.foo} removes prefix (leaving suffix). The double star glob (**) is needed to traverse all ...


1

By using \0-delimited strings, this can handle spaces and \n in file names. cd "${PROJECT_DIR%/*}" outdir="output"; mkdir -p "$outdir" find "$PROJECT_DIR" -type f -name '*.log' -printf "%p\0${outdir}/%P\0" | awk 'BEGIN{FS="/";RS=ORS="\0"} NR%2||NF==2 {print; next} {gsub("/","#"); sub("#","/#"); print}' | xargs -0 -n2 cp -T mkdir -p ...


1

#!/bin/bash newdir=/absolute/path/output olddir=/absolute/path/project find $olddir -name '*log' | while read line ; do if [ "$olddir" == "$( basename "$line" )" ] ; then #just move the file if there are no subdirectories mv "$line" "$newdir" else #1) replace old project dir with nothing #2) replace all slashes with hashes #3) set ...


0

(cd "$PROJECT_DIR" && find . -name "*.log") | tar -cf - -T - | (cd $OUTPUT_DIR && tar -xf -) cd to project directory find all of the log files tar's list of log files to stdout cd to output directory untar stdin


3

Here's one simple way, that addresses your original question completely. Could be done as a one-liner, but this syntax keeps it readable. #!/bin/bash for F in "$@" do echo mv "$F" "${F%.pdf}[$(pdfinfo "$F" | awk '/^Pages/{print $NF}')].pdf" done $ ls *pdf aosa-bash.pdf article.pdf bash.pdf bashref.pdf rose94.pdf $ find . -name \*.pdf -exec ./pdf.sh ...


1

So, here are two scripts, which you can put in a folder with the pdf-files needing to be renamed. The first one is for adding page numbers and the second is for deleting them. Both scripts are interactive Type abort Enter to exit the script, type n Enter to enter interactive file-by-file mode and if you want a script to proceed with all pdfs without ...


0

Assuming you: wanted "1 + Ordinal date" at Position 2. "_"-padded station names. lowercasing of the channel name Then this should perform the wanted transform. $ ls 2007-07-22-2300-11S.NAN___024_ABI___HH_E_SAC $ for i in *; do od="$(expr $(date +%j -d "${i:0:10}") + 1 )"; chn="${i:39:1}"; sta="$(echo ${i:30:6} | tr -d '_')"; mv "$i" ...


1

For mass renaming, prename is your friend. In this case: prename 's/^(\d*)-(\d*-\d*)-(\d*)-.*___\d*_(\w*)___\w*_(\w*)_\w*/$1.$2.$3.$4.$5/' * (ignoring the Julian date until the respective questions have been clarified).


2

Use this: find -name "* *" -print0 | sort -rz | \ while read -d $'\0' f; do mv -v "$f" "$(dirname "$f")/$(basename "${f// /_}")"; done find will search for files and folders with a space in the name. This will be printed (-print0) with nullbytes as delimiters to cope with special filenames too. The sort -rz reverses the file order, so that the deepest ...


0

find $1 -depth -name "* *" -type d -execdir rename 's/ /_/g' "{}" \;


0

separate between filename basename (i.e. last name in the path) and dirname: find $1 -depth -name "* *" -print0 | \ while read -d $'\0' f ; do a="$(dirname "$f")" b="$(basename "$f")" #optional check if the basename changes -> reduces errors in mv command #only needed when using -wholename instead of -name in find, so skippable if [ ...


10

Use this with bash: find $1 -name "* *.xml" -type f -print0 | \ while read -d $'\0' f; do mv -v "$f" "${f// /_}"; done find will search for files with a space in the name. The filenames will be printed with a nullbyte (-print0) as delimiter to also cope with special filenames. Then the read builtin reads the filenames delimited by the nullbyte and ...


8

Using rename find . -type f -name "* *.xml" -exec rename "s/\s/_/g" {} \; or with $1 find "$1" -type f -name "* *.xml" -exec rename "s/\s/_/g" {} \; Using mv find . -type f -name "* *.xml" -exec bash -c 'mv "$0" "${0// /_}"' {} \; or with $1 find "$1" -type f -name "* *.xml" -exec bash -c 'mv "$0" "${0// /_}"' {} \;


1

Assuming none of your files have spaces: for i in *k120*; do mv -- "$i" "$i.dat" done


0

Works for me, so you will need to provide more information about the problem: chris@localhost$ finger 2> file.txt chris@localhost$ sftp remotehost Connected to remotehost. sftp> ls -l file.txt Can't ls: "/home/chris/file.txt" not found sftp> ls -l file.tmp Can't ls: "/home/chris/file.tmp" not found # So the file doesn't exist on the remote in ...


5

If you've a snapshot of the filesystem, or a backup, then yes. If you haven't, then no.



Top 50 recent answers are included