<ul>
<?php
$categories = get_categories();
foreach($categories as $category)
{
?>
<li><a href="https://wordpress.stackexchange.com/questions/165159/<?php echo get_category_link($category->cat_id);?>">$category->name</a></li>
<?php
}
?>
</ul>
Just simply change the content inside the foreach loop to output how ever your desire. If you are doing this in a number of places drop it into a function and echo the function from your functions file.
Drop this into your functions.php
<?php
function outputcategories()
{
?>
<ul>
<?php
$categories = get_categories();
foreach($categories as $category)
{
?>
<li><a href="https://wordpress.stackexchange.com/questions/165159/<?php echo get_category_link($category->id);?>">$category->name</a></li>
<?php
}
?>
</ul>
<?php
}
then to use it run the below
<?php echo outputcategories(); ?>