Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ls - ltr error because nothing in folder

Tags:

bash

ls

I have a script and in the script I am running the below command.

ls -1tr ${ARCH1_DIR}/* | grep ${LOG_PREFIX} > $copied_binlog_set

if the folder is empty I get an error.

ls: cannot access /n01/mysqlarch1/*: No such file or directory

The script at this point stops processing. Is there a way so the script can carry on processing if the folder is empty.

like image 922
user2841861 Avatar asked Dec 01 '25 16:12

user2841861


1 Answers

You can try:

ls -1tr ${ARCH1_DIR}/* 2>/dev/null | grep ${LOG_PREFIX} > $copied_binlog_set

When you write 2> file, it redirect stderr to file, but you can use the null device and throws the input it gets. You can think about it as the black hole of your system.

like image 200
Maroun Avatar answered Dec 04 '25 09:12

Maroun



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!