It's called taking guard. Players use a bail whereas some others use their bat or foot to make a mark on the crease. It is done to know the line of the stumps, and every batsman takes a guard of the middle and/or off stump so that they can assume the correct stance.