Using command line to change the name of your files in HiPerGator. - meyermicrobiolab/Meyer_Lab_Resources GitHub Wiki

Changing a file name:

  • In order to successfully run cutadapt in the HiPerGator (hpg), you need to make sure you have no capital "R" in your file name. This does NOT apply for the R1/R2 in the file name.

  • You will need to change a specific chunk of the file name in order to do this, but renaming a file one by one is extremely tedious and time-consuming.

  • To change all of the file names in a working directory, use this line of code in the terminal: for file in *[file type] ; do mv $file ${file//[former file name]/[new file name]} ; done

  • File type refers to the file element you want to rename. This could be a .pdf or .txt. For amplicons and other genomics, this is usually a .fastq.gz file element.

  • former file name is the chunk of the file name you want to change. The new file name is what you will be replacing the former file name with.

  • An example:

for file in *.fastq.gz ; do mv $file ${file//STRI/stri} ; done. This line of codes changes all of the "STRI" in my directory to "stri".

Changing a file element:

  • You can also change the file type, or file element, in your working directory. Let's say you want to change a .pdf to .txt.

  • To do this, run: find . -depth -name "[current file type]" -exec sh -c 'f="{}"; mv -- "$f" "${f%[current file type]}[new file type]"' \;

  • Therefore, to change a .pdf to a .txt, run: find . -depth -name ".pdf" -exec sh -c 'f="{}"; mv -- "$f" "${f%.pdf}.txt"' \;