store unix command error message into file - unix

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

Related

How do I find the word 'error ' in which folder it is in Unix?

I am trying to find a word ''Error'' in the log file. But I do not know in which folder it is. Will ls-lr | Grep ''Error'' work?
You can execute the below to find the files with the word Error
grep -R Error <directory path>

Unix file mv error

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.

How to extract a .tar.gz file on UNIX

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

problems with sudo mv file /non_existing_folder - file disappeared

I was trying to move a RubyOnRails.txt file into a /RUBY directory, so for some reason I typed:
mv RubyOnRails.txt /Ruby"
And I got this error: mv: cannot move ‘Untitled Document’ to ‘/Ruby’: Permission denied
Obviously, I typed: sudo mv RubyOnRails.txt /Ruby
And then, I understood my error, the folder wasn't /Ruby, was /RUBY.
Now the file is gone, and I can't find it anywhere.
There is some way to find it or recover it?
The file isn't gone, it's just renamed to Ruby and it's in root directory of your system /
You can still move it where you want like that sudo mv /Ruby your_destination

When extracting a tar archive, I get the error "No such file or directory found"

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.

Resources