Suppress verbose tar output and the "Cannot stat: No such file or directory" messages

I am trying to "debug" my backup script ever since I started using tar instead of creating zip files.

I need to suppress the "Cannot stat: No such file or directory" messages to make it easier.

cd $DOCS
touch  /home/andy/Documents/$( date '+%m-%d-%Y' )
tar -cvf Ubuntu_Documents.tar *.txt *.doc *.rtf *.html *.png *.pdf *.odt *.ods *.odg *.csv *.xls *.jpg 

Templates.odt
tar: *.ods: Cannot stat: No such file or directory
tar: *.odg: Cannot stat: No such file or directory
tar: *.csv: Cannot stat: No such file or directory
tar: *.xls: Cannot stat: No such file or directory
Modified_food_plan.jpg
tar: Exiting with failure status due to previous errors

Did you look at the tar man page and understand what the -v and related options do?

1 Like

I am researching it.

When I do a search in a terminal for text, I used "- v" or "-v", it finds nothing.

Is there a special format that I need?

-v is verbose.

In bash you can try

shopt -s nullglob

to silence the null matches.
Still you will get an error from tar if there were not a single match.

2 Likes

Gee, I am surprises tar has no option for that.

I will put that on hold while I look for how to suppress those long file listings when I create an archive. :slight_smile:

Did you try without the -v option just to test??

isnt this that option. ```
tar -cvf Ubuntu_Do
cuments.tar *.txt *.doc *.rtf *.html *.png

( I had hernia surgery at lunch, so I am a little loopy.)

Just get rid of the v .....

tar -cf

the v is verbose mode, which you do not want.

Screen Shot 2022-12-02 at 10.49.40 AM

Yes, I agree you are loopy :slight_smile: The verbose mode flag is on every tar man page I can think of :slight_smile:

Not sure why you cannot find this mode. It's on every man page I can think of.....

If you do not want verbose tar listing, then you must not use verbose mode; just as the docs say.

This is the first step, to understand the basics of how to use the tar command.

Mod Note:

So before jumping to shell options, standard redirections, and other ways to suppress output, users need to at least understand the basic options in the commands they are working with and demonstrate they have at least, tried to use and experiment with these command-line options.

Also, we should not be assuming the shell a member is using. Ask first, don't guess.

Thanks.

I removed the v as you recommended.

I read the link you provided.

I think I have provided answers to your questions and read the suggested material you provided.

-,--verbose*** verbosely list files processed

cd $DOCS
touch  /home/andy/Documents/$( date '+%m-%d-%Y' )
tar -cf Ubuntu_Documents.tar *.txt *.doc *.rtf *.html *.png *.pdf *.odt *.ods *.odg *.csv *.xls *.jpg


tar: *.rtf: Cannot stat: No such file or directory
tar: *.png: Cannot stat: No such file or directory
tar: *.ods: Cannot stat: No such file or directory
tar: *.odg: Cannot stat: No such file or directory
tar: *.csv: Cannot stat: No such file or directory
tar: *.xls: Cannot stat: No such file or directory
tar: Exiting with failure status due to previous errors


------------------
(program exited with code: 2)

Yes, you can see that none of the successful files names are listed now.

But as @MadeInGermany mentioned you must now deal with the shell errors.

Why not try redirecting standard error to /dev/null ?

What shell are you using exactly?

1 Like

You might review your decision to put on hold the answer from @MadeInGermany , because it addresses your remaining problem.

I will go back and re-read @MadeInGermany post.

By shell, do you mean what terminal?
If so, I am using the Ubuntu-Mate terminal.

I am trying to find the @MadeInGermany post.

I tried this search but it did not return that post.

MadeInGermany and shell and errors and cyclist

I added >> /dev/null to all my tar commands.

The screen display is much less cluttered. :slight_smile:

I appreciate your help.

1 Like

> or 1> redirects stdout.
>> or 1>> redirects stdout after an append attempt.
But error messages go to stderr... you must redirect stderr.

See also:

https://www.cyberciti.biz/faq/how-to-redirect-standard-error-in-bash/

ok. I did this. Do I do a rm output.txt to get rid of output.txt?

SCRIPTS="/home/andy/bin/"

cd $SCRIPTS

tar -cvf UM_20_04_Ubuntu_Scripts.tar *.sh *.rb *.c *.py *.txt  &> output.txt
/usr/bin/rsync --progress -r -u UM_20_04_Ubuntu_Scripts.tar $Backup_Directory
/usr/bin/rsync --progress -r -u UM_20_04_Ubuntu_Scripts.tar $Local_Backup_Dir

Use the /dev/null (device file).
And do not delete that!!

&> is both stdout and stderr.
stderr only would be 2>; especially if you have the -v option it does not make sense to supress the verbose output.

Ok.

Thanks luckily I did that with small test file and not the original script.

My original script still has the

>> /dev/null

There is a slider on the right of the posts, which shows (approximately) which post is on view, and a time-bar of the postings. The post by @MadeInGermany which I refer to is 4/19 (fourth of 19).

The terminal is just the display mechanism in the command line window. The shell is the interpreter for the commands you type into the terminal. The process tree command below shows I have a Mate terminal process, with one bash running the pipeline that makes the output, another bash in a different terminal that is idle, and three other stubs (which I don't understand).

$ pstree -p $PPID | cat
mate-terminal(15283)-+-bash(15290)-+-cat(15433)
                     |             `-pstree(15432)
                     |-bash(15342)
                     |-{mate-terminal}(15286)
                     |-{mate-terminal}(15288)
                     `-{mate-terminal}(15289)

By "which shell", we mean one of bash, ksh, dash, csh, tcsh, and a few others.

Normally, echo $0 will show the shell you are currently have running in your terminal.

Most shells will tell you their version number, with a -v or --version option. Note this tells you the version of the shell you ask, which is not necessarily the shell you are running.

Unless you specifically run a different shell, your terminal is running the shell specified for your user in the /etc/passwd file.

If you run a script that has a shebang like #! /bin/bash, the script gets run by that shell, but that does not alter the shell running in the terminal.

$ echo $0
bash
$ bash --version
GNU bash, version 4.4.20(1)-release (x86_64-pc-linux-gnu)
(( Some licensing information ))
$ ksh --version
  version         sh (AT&T Research) 93u+ 2012-08-01
$ #.. My sh is a link to dash, and I do not have csh or tcsh ..#
$ grep paul /etc/passwd
paul:x:1000:1000:Paul Stillman,,,:/home/paul:/bin/bash
$ ksh
$ echo $0
ksh
$ pstree -p $$
ksh(15362)───pstree(15383)
$ #.. I ended that ksh with Ctrl-D, so I am back in my login bash shell ..#
$ echo $0
bash
$ pstree -p $$
bash(15322)───pstree(15384)
$
2 Likes

Hi @Paul_Pedant

I think your information is good but it seems "quite over the head" of the OP, who struggles with command switches and basic unix admin tasks.

It's important when replying to OPs to keep in mind their demonstrated skill levels and interests.

The OP has not shown any interest or skills in moving to using pstree and other utilities to work this simple task.

Let's wait for them to reply.

Anything else @cyclist ? Are you good now?