I asked 'change filename without using mv command and rename function' few days ago, and #nos answered me. So I try to use 'link' function.(It seems to create a hard link.)
But, it is not available with a directory.
Is there any way to change a directory name without using 'rename' function and 'mv' command?
I can use my copy function and delete function, but it is too hard and wasteful to just change a directory name.
I just want to know whether there is any way to change a directory name without using 'rename' function and 'mv' command.
I'm so sorry about my poor English skill... ;(...
Try this answer!
mv /home/user/oldname /home/user/newname
If you just want to rename the folder(not moving file to different folder) use below command.
mv oldFolderName newFolderName
Related
Lots of questions like this one but none of them have helped and i've already killed a day on this single command.
Basically I need to understand how I can mv a folder into a subfolder in the same directory from a bash script.
To isolate this problem as much as possible i made the following movetest.sh:
sudo mv /home/zoctavous/vault/repos/work/recup_dir1000/ /trash/
All the folders specified exist and there are no folders that are currently named this. All I get in response is
mv: cannot stat '/home/zoctavous/vault/repos/work/recup_dir1000/': No such file or directory
please help :(
I figured out my issue... I was deleting part of the filename farther up in the script that it was a part of.
/home/zoctavous/vault/repos/work/recup_dir.1000/ is the actual directory name.
the variable for the directory was being stored as shown above
/home/zoctavous/vault/repos/work/recup_dir1000/
How to move all files (except directories) to subdirectories by extension name in the specified DIR directory?
If I'm understanding your question correctly, globbing should help you. If you're going to be using linux for a while, I'd recommend reading up on it, as it makes using linux and bash much easier.
To directly answer your question, something like this should work:
mv *.<extension> <target directory>
I am a bit curious about CygWin command source and renaming with mv.
When I run in source file cmd mv and would rename some file in my computer, it renames files well, but unhappily it puts at the end of name also the cryptic character.
f.e.: 1A6CSAB000A1_51D9.pdfand in this case, my computer isn´t able to open the file.
But when I run it without cmd source (and source file), just with
mv A.phd.1 B.phd.1
in CygWin, it works well and rename files without cryptic character.
Any idea how to deal with this issue?
Thanks in advance and sorry, if there is similar question, I didn´t find it.
Gabi
I used command zip in linux (RedHat), this is my command:
zip -r /home/username/folder/compress/zip.zip /home/username/folder/compressed/*
Then, i open file zip.zip, i see architecture as path folder compress.
I want to in folder zip only consist list file *.txt
Because i used this command in script crontab hence i can't use command cd to path folder before run command zip
Please help me
I skimmed the zip man page and this is what I have found. There is not an option archive files relative to a different directory. The closest I have found is zip -j which removes the entire path and stores the files directly in the zip rather than sub directories. I do not know what happens in the case of file name conflicts such as if /home/username/folder/compressed/a.txt and /home/username/folder/compressed/subdir/a.txt both exist. If this is not a problem for you, you can use this option, but I am concerned because you did specify the -r option indicating that you expect zip to traverse sub folders.
I also thought of the possibility that your script could somehow call zip with a different working directory, but I took a look at this unix stack exchange page and it looks like their options use cd.
I have to admit I do not understand why you cannot use cd and I am very curious about it. You said something about using crontab, but I have never heard of anything wrong with changing directories in a crontab script.
I used option -j in command zip
zip -jr /home/username/folder/compress/zip.zip /home/username/folder/compressed/*
and i was yet settled this problem, thanks
This is a basic question but I am struggling to find a decent solution. This is hindering my script from automation.
I have the following path.
/home/hassan/Dyna/ProjectSimulation
in project simulation I have 3 folders
friction time force
like
/home/hassan/Dyna/ProjectSimulation/friction
Now I have a file friction1.txt in this friction folder and I want to copy it to ProjectSimulation.
is it possible to avoid complete path and just one step down?
Also if I have to copy this friction1.txt to folder force, is there anyway to avoid the complete path.
I mean I have a subroutine but this is path dependent , whenever I run it , I have to run in the same folder and then copy my results so I can run only one instance of my simulation.
Experts please guide me.
PS: This is part of a 600 lines shell.
This comes across as so basic that I must have misunderstood something in your question.
If you want to refer to a parent directory, .. is the way to do that. So, if you want to copy friction1.txt to two places you just do
cp friction1.txt ..
cp friction1.txt ../force
All you need to take care of is making sure that CWD is
/home/hassan/Dyna/ProjectSimulation/friction
so that the references point at the right place.
You can temprarily change the current directory to ProjectSimulation, copy the file (cp friction/friction1.txt .), then change the path back to the original (so the rest of the script works as before)
Alternatively, you can use dirname to get he name of the parent directory and use that.
Change to the root dir of your known directory structure. Then do the copy operations with relative paths. Then change back to your dir where you came from.
Your friends are:
cd
cd -
or better:
pushd
popd
(see man bash)
I.e.
pushd /home/hassan/Dyna/ProjectSimulation
cp friction/friction1.txt .
cp friction/friction1.txt force
popd