I am trying to read from a file in unix that contains filenames and move the files from one directory to another. But it's giving me an error:
"mv: cannot stat `REGPC_20170224113009_1111_S.dat': No such file or
directory"
Can someone please help?
Tried below script:
#!/bin/sh
while read file;
do
mv "$file" /opt/mounts/tes/summit/archive/
done < /opt/mounts/tes/summit/inbound/rpm_file_list.txt
As statedm cannot stat `REGPC_20170224113009_1111_S.dat ; where you are trying to run the script the file, REGPC_20170224113009_1111_S.dat does not exist. Check manually if the path is correct.
Related
I have a file (reviews_dataset.tar.gz) that contains many files which contains data. I am required to extract the files in this archive and then perform some basic commands on the file. So far I have created a directory named (CW) and found a command tar zxvf fileNameHere.tgz but when I run this it of course cannot find my file as I have not "downloaded it" into my directory yet? How do I get this file into my directory so that I can then extract it? Sorry if this is poorly worded I am extremely new to this.
You must either run the command from the directory your file exists in, or provide a relative or absolute path to the file. Let's do the latter:
cd /home/jsmith
mkdir cw
cd cw
tar zxvf /home/jsmith/Downloads/fileNameHere.tgz
You should use the command with the options preceded by dash like this:
tar -zxvf filename.tar.gz
If you want to specify the directory to save all the files use -C:
tar -zxf filename.tar.gz -C /root/Desktop/folder
When I attempt to extract a huge tar archive, I get the following error:
"filename: No such file or directory found"
Any suggestions on what could be going wrong?
This may happen if the disk is full. If you extract using:
tar -xvf <filename.tar>
you may see the following message before any No such file or directory found:
mkdir failed: Disk quota exceeded
why dont you try to test your tar file first!
file yourfile.tar
(it should say its a tar file if it's not broken)
Then...
tar -tvf yourfile.tar
It should give a listing of the contents of your tar file without actually writing it to disk. Just to check the integrity of it.
Also, if your file is larger tan 2GB it is posible that your tar binary wont work, try gtar instead!
with that info, you can go further...
regards,
Daniel.
I want to store error of unix command into file.
Ex.
cd /test
/test: No such file or directory.
I want to store error "/test: No such file or directory." into file
Can you please help?
How about
cd /test 2> myFile.txt
I want to run a program for a file that exists in different subdirectories and then redirect the output to an output file. I want the output to be saved to the directory that the program has run.
So I would like to do something like this:
for x in */*.txt; do command $x > output.fsa; done
My questions are:
Is it correct the above loop? should I change directory in order to save the output on the directory that the command was executed or linux takes care of it?
any ideas on how to give the name of the directory in the output file?
Is it correct the above loop?
Yes
should I change directory in order to save the output on the directory that the command was executed or linux takes care of it?
You do not need to change the directory it is enough to redirect the output to a file in the correct directory:
for x in */*.txt; do command $x > `dirname $x`/output.fsa; done
The loop is correct, you will iterate over all txt files in subdirs of the current pwd (where this script or command is being executed). You don't have to change directory to save the output in that subdir. Linux don't take care of it :)
You can delete everything after first / using variable expansion ${x%%/*}
Try
for x in */*.txt; do
command "$x" > "${x%%/*}"/output.fsa
done
Remember, if you have more txt files in that subdir, you will execute command "$x" more times and rewrite the output.fsa.
You can use append (>>) in that case
Try
for x in */*.txt; do
echo "Executing command \"$x\"" >> "${x%%/*}"/output.fsa
command "$x" >> "${x%%/*}"/output.fsa
done
I'm writing a script that will print the file names of every file in a subdirectory of my home directory. My code is:
foreach file (`~/.garbage`)
echo "$file"
end
When I try to run my script, I get the following error:
home/.garbage: Permission denied.
I've tried setting permissions to 755 for the .garbage directory and my script, but I can't get over this error. Is there something I'm doing incorrectly? It's a tcsh script.
Why not just use ls ~/.garbage
or if you want each file on a separate line, ls -1 ~/.garbage
backtic will try to execute whatever is inside them. You are getting this error since you are giving a directory name within backtic.
You can use ls ~/.garbage in backtics as mentioned by Mark or use ~/.garbage/* in quotes and rely on the shell to expand the glob for you. If you want to get only the filename from a full path; use the basename command or some sed/awk magic