-1

I would like to know how to change the name of a txt file inside a directory.

I know that I can mv test123 test456, but that only changes the name in the current directory. What if I want to change the name of a txt file inside /home/folder1/?

anonymous2
  • 4,298

1 Answers1

2

Run the following:

mv /home/folder1/test123 /home/folder1/test456
anonymous2
  • 4,298
  • it just gives me No such file or directory error... – TraumCro Jun 21 '16 at 14:00
  • What is the name of your file, and what folder is it in specifically? – anonymous2 Jun 21 '16 at 14:02
  • Right now i made it work by doing this

    #!/bin/bash ls *.txt > Scripttextfil1.txt mkdir modul2 cp Scripttextfil1.txt modul2 mv modul2/Scripttextfil1.txt nyttextfil.txt cp nyttextfil.txt modul2 rm nyttextfil.txt

    but this is not "clean scripting" i need to just change the file name without having to copy more or remove more documents.. i hope u understand

    – TraumCro Jun 21 '16 at 14:23
  • What i want is to change the name of the file inside modul2 from scripttextfil1.txt to nyttextfil.txt – TraumCro Jun 21 '16 at 14:24
  • Okay, I think I'm starting to catch you now. :) So run mv modul2/scripttextfil1.txt modul2/nyttextfil.txt. Make sure you get spelling and capitalization right. – anonymous2 Jun 21 '16 at 14:25
  • No problem. My pleasure. Basically, you have to put the folder name both in front of the file you are moving and in front of the file you are renaming to. – anonymous2 Jun 21 '16 at 14:28
  • May i ask one more thing! how do i work with pipes and grep to make ls show all files ending in txt from my home dir – TraumCro Jun 21 '16 at 14:28
  • I use the find command: sudo find ~/ -name *.txt – anonymous2 Jun 21 '16 at 14:30
  • Or if you just want the ones straight in your home directory, you can use ls *.txt. – anonymous2 Jun 21 '16 at 14:31