Cannot stat , No such file or directory linux - linux

Ive looked over some other questions similar to this but none of the solutions worked for me. I've got two directories Teacher and Employee. I've got a file in the Teacher directory called Emp7.tar.gz and i want to move it into the Employee directory. I'm using a shell script to move it but i keep getting the same error. The code im using to move it is
#:/bin.bash
mv Emp7.tar.gz Employee/
I know its probably simple but im just getting used to linux so any help is appreciated.

Welcome to StackOverflow! If your working directory is Teacher, then your command should be:
mv Emp7.tar.gz ../Employee/
If your working directory is one above Teacher, then your command should be:
mv Teacher/Emp7.tar.gz Employee/
If your working directory is Employee, then your command should be:
mv ../Teacher/Emp7.tar.gz .

mv Emp7.tar.gz ../Employee
You need to specify the relative path to the Employee directory.
As you're in the Teacher directory, you need to get up once

Related

cannot stat folder when moving from a bash script

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/

Go to bottom most directory?

I'm working with a directory with a lot of nested folders like /path/to/project/users/me/tutorial
I found a neat way to navigate up the folders here:
https://superuser.com/questions/449687/using-cd-to-go-up-multiple-directory-levels
But I'm wondering how to go down them. This seems significantly more difficult, but a couple things about the directory structure help. Each directory only has another directory in it, or maybe a directory and a README.
The directory I'm looking for looks more like a traditional project and might have random directories and files in it (more than any of the other higher directories certainly).
Right now I'm working on a solution using uh.. recursive bash functions cd'ing into the only directory underneath until there are either 0 or 2+ directories to loop through. This doesn't work yet..
Am I overcomplicating this? I feel like there could be some sweet solution using find. Ideally I want to be able to type something like:
down path
where path is a top-level folder. And that will take me down to the bottom folder tutorial.
There is an environment variable named CDPATH. This variable is used by cd in the same manner that executables use PATH when searching for pathname.
For example, if you have the following directories:
/path/to/project/users/me
/path/to/project/users/me/tutorial
/path/to/project/users/him
/path/to/project/users/him/test
/path/to/project/users/her
/path/to/project/users/her/uat
/path/to/project/users/her/dev
/path/to/application
/path/to/application/conf
/path/to/application/bin
/path/to/application/share
export CDPATH=/path/to/project/users/me:/path/to/project/users/him:/path/to/project/users/her:/path/to/application
A simple command such as cd tutorial will search the above paths for tutorial.
Let's pretend /path/to/application has directories underneath namely, conf, bin, share. A simple cd conf will send you to /path/to/application/conf as long as none of the paths before it have conf directory. This behavior is similar to executables in PATH. The first occurrence always gets chosen
My attempt - this actually works now! I'm still afraid it could easily go infinite with symbolic links or some such.
Also, I have to run this like
. down
from within the first empty folder.
#!/bin/bash
function GoDownOnce {
Dirs=$(find ./ -maxdepth 1 -mindepth 1 -type d)
NumDirs=$(echo $Dirs | wc -w)
echo $Dirs
echo $NumDirs
if [ "$NumDirs" = "1" ]; then
cd $Dirs
GoDownOnce
fi
}
GoDownOnce
A friend also suggested this sweet one liner:
cd $(find . -type d -name tutorial)
Admittedly this isn't quite what I asked, but it gets the job done pretty well.

What exactly is this terminal command doing?

cp EFI/boot/loader.efi to EFI/boot/bootx64.efi
I understand that this is the copy command, but what exactly happens to files individually when this command is run on them. Do we get duplicate files or do we get only one file? I am trying to recreate the action on Windows, as I do not have sudo access on the linux I am working on.
I got this command from a question on this forum. Please do not ask any more questions as to clarify this question. Thanks for all your answers!
This copies looder.efi to bootx64.efi. If the bootx64.efi file does not already exist, the cp command creates it. If it does exist, the cp command replaces its contents with the contents of the looder.efi file.

Change working directory while looping over folders

Currently I am trying to run MRI software (TBSS) on imaging files(scan.nii.gz) on the Linux command line.
The scans are all stored in separate folders for different participants and the file names are identical,so:
/home/scans/participant1/scan.nii.gz
/home/scans/participant2/scan.nii.gz
/home/scans/participant3/scan.nii.gz
What this software does is it creates the result of the analysis in the current working directory.Since the scans have the same image name, they get overwritten al the time.
I would like to loop through all the participant folders, make it my working directory and then execute the tbss command, which is simply tbss_1_preproc scan.nii.gz. In this way, the file will be stored in the current working directory,which is the participant directory.
Is there any sensible way of doing this in Linux ?
Thanks so much !
Try it in BASH. The code below is untested, but it should give you a clue
#! /bin/bash
find . -name scan.nii.gz | while read line
do
cd $(dirname "${line}")
tbss_1_preproc $(basename "${line}")
done
Put it in a file and make it executable. Copy it to your scans folder and execute it.

Linux - Giving all users access to a folder (and all folders and files below)

I know this seems like its a question I could just google, but I've tried and to be honest I'm still stuck.
The question I'm trying to solve asks...
Your current directory is sample_dir. Add the permission (using
symbolic) for gen_ed so that all users can access the file cars2:
The path is stenton/gen_ed/cars2 from the working directory.
So naturally, I assumed it was:
chmod -R ugo+r stenton/gen_ed, however that fails. I've tried a ton of iterations on the same line of thinking, but they've all failed.
Can someone please end this torment!
chmod go+x stenton/gen_ed
THIS should do the job!
What bit has to be set for a directory to be accessible (traversable) by all users?
For a file to be accessible, a user must be able to traverse all the directories from the root to that file. Can they?
Since it's an assignment, I won't give you the answer.
For anyone who is still searching for the correct answer for this question, it is:
chmod a+x stenton/gen_ed

Resources