ابدأ بالتواصل مع الأشخاص وتبادل معارفك المهنية

أنشئ حسابًا أو سجّل الدخول للانضمام إلى مجتمعك المهني.

متابعة

How to save the output of the script in different directory in Bash?

user-image
تم إضافة السؤال من قبل Mudassir Mubin Baig , Network Engineer , Saima Packaging Pvt. Ltd.
تاريخ النشر: 2016/03/07
Carlos Perez
من قبل Carlos Perez , RAN Engineer , Grupo Poas

both outputs; on screen and to file.log: 

' command '2>&1 | tee -a file.log

ASHISH VERMA
من قبل ASHISH VERMA , Software Engineer , Ragon Systems

 $HOME/bin/shell_script.sh >/home/usr/test.log 2>&1

Khaja Ehteshamuddin  Ahmed
من قبل Khaja Ehteshamuddin Ahmed , IT Analyst , Tata Consultancy Services

We can run the script using and redirect the output to a file rather than to the screen.

Ex: ./script.sh > /home/dir1/file1 We are executing the script and saving the output to a file called file1

benyahia oussama
من قبل benyahia oussama , Network and Security Administrator , ELIT

DIR="NewDirectory" mkdir -p $DIR echo "Testing">>"$DIR/file.txt"

Anil Mathew Kadakethu
من قبل Anil Mathew Kadakethu , Technical Support Manager , M H Alshaya

yourcommand 1>> path/log_file 2>&1this redirect stdout and sterr to log_file

 

NIVETHA SENTHILKUMAR
من قبل NIVETHA SENTHILKUMAR , Software Engineer , infosys

The oup\\tput can be save in a new directory using redirecting symbol >>

مستخدم محذوف‎
من قبل مستخدم محذوف‎

First capture the output of the script using a backtick and then pipe it into an echo command which writes into a specified file in a specified directory.

مستخدم محذوف‎
من قبل مستخدم محذوف‎

$ ./yourscript.sh > output.txt$ /path/to/your/script.sh > output.txt

مستخدم محذوف‎
من قبل مستخدم محذوف‎

do something like this ./script.sh > /tmp/output.log 2>&1

المزيد من الأسئلة المماثلة