I often find myself putting a clear; in front of a command that I expect to produce lot of output.

That I regularly miss is the possibility to see the executed commandline at top. Is there some magic I can do about this?


If I put clear;some_program with params I would like to have a cleared terminal showing something like:

Fri 12 Apr 2024 12:32:00 PM CEST 
> clear;some_program with params
// program output //

the first part is easy by just defining an alias alias clear="clear;date" Is there a solution for the printing the whole command line? (did not matter if the clear is part of it or not or if there is some line wrap or not)

2 Answers 2


You can try enabling debugging mode through set command. Here is a demonstration to do the same.

clear; date; set -x; echo "Hello"; set +x

The first clear and date command are part of your solution. After that, set -x will print the command which are being executed as a part of the debugging. Replace echo "Hello" with your desired command or script. Finally, set +x will disable the debugging mode.

Note: If you are using some customization with zsh, you are going to get a lot of unnecessary output during debugging mode. For example, I use Oh My Zsh, and I got all oh my zsh commands in debugging mode.

If you do not have any customization, the solution should work fine for you. In case you have some sort of customization, you can run the above solution in zsh -f. It will load zsh without any configs (.zshrc .zshenv and others). If you script or command is not dependent on these files, you can have this fix.

  • but this does not fit my use case of using the newly created alieas with arbitrary programs, did it? because the program has to be embedded into the command. also the debugging mode does not seem to be appropriate Commented Apr 12 at 12:16
  • Then you can try creating a simple script which requires one argument. Pass your command there, the script should, run clear, then date, and then echo your command which was passed as argument, and finally, run your command as a part of that script. Add your script to path to run it from anywhere. stackoverflow.com/questions/20054538/add-a-bash-script-to-path Commented Apr 12 at 13:59

I was able to achive it with the history variable of zsh. the variable $history[$HISTCMD] contains the last executed command line that in this case is always the commandline executed just now.

So defining an alias like this: alias clear="clear;date;echo \> \"\$history[\$HISTCMD]\"" leads to the requested output.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .